community.general.postgresql_owner (1.3.14) — module

Change an owner of PostgreSQL database object

Authors: Andrew Klychkov (@Andersson007)

Install collection

Install with ansible-galaxy collection install community.general:==1.3.14


Add to requirements.yml

  collections:
    - name: community.general
      version: 1.3.14

Description

Change an owner of PostgreSQL database object.

Also allows to reassign the ownership of database objects owned by a database role to another role.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Set owner as alice for function myfunc in database bar by ansible ad-hoc command:
# ansible -m postgresql_owner -a "db=bar new_owner=alice obj_name=myfunc obj_type=function"

- name: The same as above by playbook
  community.general.postgresql_owner:
    db: bar
    new_owner: alice
    obj_name: myfunc
    obj_type: function
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set owner as bob for table acme in database bar
  community.general.postgresql_owner:
    db: bar
    new_owner: bob
    obj_name: acme
    obj_type: table
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set owner as alice for view test_view in database bar
  community.general.postgresql_owner:
    db: bar
    new_owner: alice
    obj_name: test_view
    obj_type: view
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set owner as bob for tablespace ssd in database foo
  community.general.postgresql_owner:
    db: foo
    new_owner: bob
    obj_name: ssd
    obj_type: tablespace
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reassign all object in database bar owned by bob to alice
  community.general.postgresql_owner:
    db: bar
    new_owner: alice
    reassign_owned_by: bob
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reassign all object in database bar owned by bob and bill to alice
  community.general.postgresql_owner:
    db: bar
    new_owner: alice
    reassign_owned_by:
    - bob
    - bill

Inputs

    
db:
    aliases:
    - login_db
    description:
    - Name of database to connect to.
    type: str

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

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

obj_name:
    description:
    - Name of a database object to change ownership.
    - Mutually exclusive with I(reassign_owned_by).
    type: str

obj_type:
    aliases:
    - type
    choices:
    - database
    - function
    - matview
    - sequence
    - schema
    - table
    - tablespace
    - view
    description:
    - Type of a database object.
    - Mutually exclusive with I(reassign_owned_by).
    type: str

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

new_owner:
    description:
    - Role (user/group) to set as an I(obj_name) owner.
    required: true
    type: str

login_host:
    description:
    - Host running the database.
    type: str

login_user:
    default: postgres
    description:
    - The username used to authenticate with.
    type: str

trust_input:
    default: true
    description:
    - If C(no), check whether values of parameters I(new_owner), I(obj_name), I(reassign_owned_by),
      I(session_role) are potentially dangerous.
    - It makes sense to use C(no) only when SQL injections via the parameters are possible.
    type: bool
    version_added: 0.2.0
    version_added_collection: community.general

fail_on_role:
    default: true
    description:
    - If C(yes), fail when I(reassign_owned_by) role does not exist. Otherwise just warn
      and continue.
    - Mutually exclusive with I(obj_name) and I(obj_type).
    type: bool

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

login_password:
    description:
    - The password used to authenticate with.
    type: str

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

reassign_owned_by:
    description:
    - The list of role names. The ownership of all the objects within the current database,
      and of all shared objects (databases, tablespaces), owned by this role(s) will be
      reassigned to I(owner).
    - Pay attention - it reassigns all objects owned by this role(s) in the I(db)!
    - If role(s) exists, always returns changed True.
    - Cannot reassign ownership of objects that are required by the database system.
    - Mutually exclusive with C(obj_type).
    elements: str
    type: list

Outputs

queries:
  description: List of executed queries.
  returned: always
  sample:
  - REASSIGN OWNED BY "bob" TO "alice"
  type: str

See also