community.postgresql.postgresql_publication 模块 – 添加、更新或删除 PostgreSQL 发布
注意
此模块是 community.postgresql 集合 (版本 3.9.0) 的一部分。
如果您正在使用 ansible
包,则可能已安装此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.postgresql
。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在 playbook 中使用它,请指定:community.postgresql.postgresql_publication
。
概要
添加、更新或删除 PostgreSQL 发布。
要求
在执行此模块的主机上需要以下要求。
psycopg2 >= 2.5.1
参数
参数 |
注释 |
---|---|
指定包含 SSL 证书颁发机构 (CA) 证书的文件名。 如果文件存在,则会验证服务器的证书是否由其中一个机构签名。 |
|
删除发布依赖项。仅当 state=absent 时有效。 选项
|
|
要添加到发布的表及其列的列表。 如果未为表传递任何列,则会将其整体发布。 与 tables 和 tables_in_schema 互斥。 |
|
在发布上设置注释。 要重置注释,请传递空字符串。 |
|
要传递给 libpg 的任何其他参数。 这些参数具有优先级。 默认值: |
|
要连接到的数据库的名称,以及将在其中更改发布状态的数据库。 |
|
运行数据库的主机。 如果您在使用 默认值: |
|
此模块应用于建立其 PostgreSQL 会话的密码。 默认值: |
|
本地连接的 Unix 域套接字的路径。 默认值: |
|
此模块应用于建立其 PostgreSQL 会话的用户名。 默认值: |
|
要添加、更新或删除的发布的名称。 |
|
发布所有者。 如果未定义 owner,则所有者将设置为 login_user 或 session_role。 |
|
包含可选发布参数的字典。 可用的参数取决于 PostgreSQL 版本。 |
|
要连接到的数据库端口。 默认值: |
|
连接后切换到 session_role。指定的 session_role 必须是当前 login_user 属于的角色。 SQL 命令的权限检查将像最初登录的用户是 session_role 一样进行。 |
|
指定客户端 SSL 证书的文件名。 |
|
指定客户端证书使用的密钥的位置。 |
|
确定是否以及以什么优先级与服务器协商安全的 SSL TCP/IP 连接。 有关模式的更多信息,请参见 https://postgresql.ac.cn/docs/current/static/libpq-ssl.html。
选项
|
|
发布状态。 选项
|
|
要添加到发布的表的列表。 如果未设置值,则所有表都是目标。 如果发布已存在于特定表中并且未传递 tables,则不会更改任何内容。 如果您需要将所有同名的表添加到发布物中,请删除现有表并创建新表,无需传递tables参数。 与tables_in_schema和columns参数互斥。 |
|
指定要添加到发布物中的模式列表,以复制这些模式中所有表的更改。 如果要移除所有模式,请显式传递空列表 自PostgreSQL 15版本起支持。 与tables和columns参数互斥。 |
|
如果为 只有当可能通过参数进行SQL注入时,使用 选项
|
属性
属性 |
支持 |
描述 |
---|---|---|
支持:完全支持 |
可以在check_mode下运行,并在不修改目标的情况下返回更改状态预测。 |
备注
注意
PostgreSQL版本必须为10或更高。
默认身份验证假设您以主机上的
postgres
帐户登录或使用sudo。为避免“Peer authentication failed for user postgres”错误,请使用postgres用户作为become_user。
此模块使用
psycopg
,这是一个Python PostgreSQL数据库适配器。在使用此模块之前,必须确保已安装psycopg2 >= 2.5.1
或psycopg3 >= 3.1.8
。如果远程主机是PostgreSQL服务器(这是默认情况),则也必须在远程主机上安装PostgreSQL。
对于基于Ubuntu的系统,在使用此模块之前,请在远程主机上安装
postgresql
、libpq-dev
和python3-psycopg2
软件包。
另请参见
另请参见
- CREATE PUBLICATION 参考
CREATE PUBLICATION命令文档的完整参考。
- ALTER PUBLICATION 参考
ALTER PUBLICATION命令文档的完整参考。
- DROP PUBLICATION 参考
DROP PUBLICATION命令文档的完整参考。
示例
- name: Create a new publication with name "acme" targeting all tables in database "test"
community.postgresql.postgresql_publication:
db: test
name: acme
comment: Made by Ansible
- name: Create publication "acme" publishing only prices and vehicles tables
community.postgresql.postgresql_publication:
name: acme
tables:
- prices
- vehicles
- name: Create publication "acme" publishing only prices table and id and named from vehicles tables
community.postgresql.postgresql_publication:
name: acme
columns:
prices:
vehicles:
- id
- name
- name: Create a new publication "acme" for tables in schema "myschema"
community.postgresql.postgresql_publication:
db: test
name: acme
tables_in_schema: myschema
- name: Remove all schemas from "acme" publication
community.postgresql.postgresql_publication:
db: test
name: acme
tables_in_schema: []
- name: >
Create publication "acme", set user alice as an owner, targeting all tables
Allowable DML operations are INSERT and UPDATE only
community.postgresql.postgresql_publication:
name: acme
owner: alice
parameters:
publish: 'insert,update'
- name: >
Assuming publication "acme" exists and there are targeted
tables "prices" and "vehicles", add table "stores" to the publication
community.postgresql.postgresql_publication:
name: acme
tables:
- prices
- vehicles
- stores
- name: Remove publication "acme" if exists in database "test"
community.postgresql.postgresql_publication:
db: test
name: acme
state: absent
返回值
常见的返回值已在此处记录,以下是此模块独有的字段
键 |
描述 |
---|---|
标志指示所有表都已发布。 返回:如果发布物存在 示例: |
|
标志指示发布物在运行结束时是否存在。 返回:成功 示例: |
|
运行结束时发布物的拥有者。 返回:如果发布物存在 示例: |
|
运行结束时发布物的参数。 返回:如果发布物存在 示例: |
|
已执行查询的列表。 返回:成功 示例: |
|
运行结束时发布物中表的列表。 如果所有表都已发布,则返回空列表。 返回:如果发布物存在 示例: |