community.postgresql.postgresql_publication (3.4.0) — module

Add, update, or remove PostgreSQL publication

Authors: Loic Blot (@nerzhul) <loic.blot@unix-experience.fr>, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>

Install collection

Install with ansible-galaxy collection install community.postgresql:==3.4.0


Add to requirements.yml

  collections:
    - name: community.postgresql
      version: 3.4.0

Description

Add, update, or remove PostgreSQL publication.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create publication "acme" publishing only prices and vehicles tables
  community.postgresql.postgresql_publication:
    name: acme
    tables:
    - prices
    - vehicles
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove publication "acme" if exists in database "test"
  community.postgresql.postgresql_publication:
    db: test
    name: acme
    state: absent

Inputs

    
db:
    aliases:
    - login_db
    description:
    - Name of the database to connect to and where the publication state will be changed.
    type: str

name:
    description:
    - Name of the publication to add, update, or remove.
    required: true
    type: str

port:
    aliases:
    - login_port
    default: 5432
    description:
    - Database port to connect to.
    type: int

owner:
    description:
    - Publication owner.
    - If I(owner) is not defined, the owner will be set as I(login_user) or I(session_role).
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - The publication state.
    type: str

tables:
    description:
    - List of tables to add to the publication.
    - If no value is set all tables are targeted.
    - If the publication already exists for specific tables and I(tables) is not passed,
      nothing will be changed.
    - If you need to add all tables to the publication with the same name, drop existent
      and create new without passing I(tables).
    elements: str
    type: list

ca_cert:
    aliases:
    - ssl_rootcert
    description:
    - Specifies the name of a file containing SSL certificate authority (CA) certificate(s).
    - If the file exists, the server's certificate will be verified to be signed by one
      of these authorities.
    type: str

cascade:
    default: false
    description:
    - Drop publication dependencies. Has effect with I(state=absent) only.
    type: bool

comment:
    description:
    - Sets a comment on the publication.
    - To reset the comment, pass an empty string.
    type: str
    version_added: 3.3.0
    version_added_collection: community.postgresql

ssl_key:
    description:
    - Specifies the location for the secret key used for the client certificate.
    type: path
    version_added: 2.4.0
    version_added_collection: community.postgresql

ssl_cert:
    description:
    - Specifies the file name of the client SSL certificate.
    type: path
    version_added: 2.4.0
    version_added_collection: community.postgresql

ssl_mode:
    choices:
    - allow
    - disable
    - prefer
    - require
    - verify-ca
    - verify-full
    default: prefer
    description:
    - Determines whether or with what priority a secure SSL TCP/IP connection will be
      negotiated with the server.
    - See U(https://www.postgresql.org/docs/current/static/libpq-ssl.html) for more information
      on the modes.
    - Default of C(prefer) matches libpq default.
    type: str

login_host:
    aliases:
    - host
    default: ''
    description:
    - Host running the database.
    - If you have connection issues when using C(localhost), try to use C(127.0.0.1) instead.
    type: str

login_user:
    aliases:
    - login
    default: postgres
    description:
    - The username this module should use to establish its PostgreSQL session.
    type: str

parameters:
    description:
    - Dictionary with optional publication parameters.
    - Available parameters depend on PostgreSQL version.
    type: dict

trust_input:
    default: true
    description:
    - If C(false), check whether values of parameters I(name), I(tables), I(owner), I(session_role),
      I(params) are potentially dangerous.
    - It makes sense to use C(false) only when SQL injections via the parameters are possible.
    type: bool
    version_added: 0.2.0
    version_added_collection: community.postgresql

session_role:
    description:
    - Switch to session_role after connecting. The specified session_role must be a role
      that the current login_user is a member of.
    - Permissions checking for SQL commands is carried out as though the session_role
      were the one that had logged in originally.
    type: str
    version_added: 0.2.0
    version_added_collection: community.postgresql

connect_params:
    default: {}
    description:
    - Any additional parameters to be passed to libpg.
    - These parameters take precedence.
    type: dict
    version_added: 2.3.0
    version_added_collection: community.postgresql

login_password:
    default: ''
    description:
    - The password this module should use to establish its PostgreSQL session.
    type: str

login_unix_socket:
    aliases:
    - unix_socket
    default: ''
    description:
    - Path to a Unix domain socket for local connections.
    type: str

Outputs

alltables:
  description:
  - Flag indicates that all tables are published.
  returned: if publication exists
  sample: false
  type: bool
exists:
  description:
  - Flag indicates the publication exists or not at the end of runtime.
  returned: success
  sample: true
  type: bool
owner:
  description: Owner of the publication at the end of runtime.
  returned: if publication exists
  sample: alice
  type: str
parameters:
  description: Publication parameters at the end of runtime.
  returned: if publication exists
  sample:
    publish:
      delete: false
      insert: false
      update: true
  type: dict
queries:
  description: List of executed queries.
  returned: success
  sample:
  - DROP PUBLICATION "acme" CASCADE
  type: str
tables:
  description:
  - List of tables in the publication at the end of runtime.
  - If all tables are published, returns empty list.
  returned: if publication exists
  sample:
  - '"public"."prices"'
  - '"public"."vehicles"'
  type: list

See also