Note
This plugin is part of the community.postgresql collection (version 1.1.1).
To install it use: ansible-galaxy collection install community.postgresql
.
To use it in a playbook, specify: community.postgresql.postgresql_user
.
no
to make the module ignore failures when trying to remove a user. In this case, the module reports if changes happened as usual and separately reports whether the user has been removed or not.The below requirements are needed on the host that executes this module.
Parameter | Choices/Defaults | Comments |
---|---|---|
ca_cert string | Specifies the name of a file containing SSL certificate authority (CA) certificate(s). If the file exists, verifies that the server's certificate is signed by one of these authorities. aliases: ssl_rootcert | |
comment string added in 0.2.0 of community.postgresql | Adds a comment on the user (equivalent to the COMMENT ON ROLE statement). | |
conn_limit integer | Specifies the user (role) connection limit. | |
db string | Name of database to connect to and where user's permissions are granted. aliases: login_db | |
encrypted boolean |
| Whether the password is stored hashed in the database. You can specify an unhashed password, and PostgreSQL ensures the stored password is hashed when encrypted=yes is set. If you specify a hashed password, the module uses it as-is, regardless of the setting of encrypted. Note: Postgresql 10 and newer does not support unhashed passwords. Previous to Ansible 2.6, this was no by default. |
expires string | The date at which the user's password is to expire. If set to 'infinity' , user's password never expires.Note that this value must be a valid SQL date and time type. | |
fail_on_user boolean |
| If yes , fails when the user (role) cannot be removed. Otherwise just log and continue.aliases: fail_on_role |
groups list / elements=string | The list of groups (roles) that you want to grant to the user. | |
login_host string | Host running the database. | |
login_password string | The password used to authenticate with. | |
login_unix_socket string | Path to a Unix domain socket for local connections. | |
login_user string | Default: "postgres" | The username used to authenticate with. |
name string / required | Name of the user (role) to add or remove. aliases: user | |
no_password_changes boolean |
| If yes , does not inspect the database for password changes. If the user already exists, skips all password related checks. Useful when pg_authid is not accessible (such as in AWS RDS). Otherwise, makes password changes as necessary. |
password string | Set the user's password, before 1.4 this was required. Password can be passed unhashed or hashed (MD5-hashed). An unhashed password is automatically hashed when saved into the database if encrypted is set, otherwise it is saved in plain text format. When passing an MD5-hashed password, you must generate it with the format 'str["md5"] + md5[ password + username ]' , resulting in a total of 35 characters. An easy way to do this is echo "md5`echo -n 'verysecretpasswordJOE' | md5sum | awk '{print $1}'`" .Note that if the provided password string is already in MD5-hashed format, then it is used as-is, regardless of encrypted option. | |
port integer | Default: 5432 | Database port to connect to. aliases: login_port |
priv string | Slash-separated PostgreSQL privileges string: priv1/priv2 , where you can define the user's privileges for the database ( allowed options - 'CREATE', 'CONNECT', 'TEMPORARY', 'TEMP', 'ALL'. For example CONNECT ) or for table ( allowed options - 'SELECT', 'INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER', 'ALL'. For example table:SELECT ). Mixed example of this string: CONNECT/CREATE/table1:SELECT/table2:INSERT . | |
role_attr_flags string |
| PostgreSQL user attributes string in the format: CREATEDB,CREATEROLE,SUPERUSER. Note that '[NO]CREATEUSER' is deprecated. To create a simple role for using it like a group, use NOLOGIN flag. |
session_role string | 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. | |
ssl_mode string |
| Determines how an SSL session is negotiated with the server. See https://www.postgresql.org/docs/current/static/libpq-ssl.html for more information on the modes. Default of prefer matches libpq default. |
state string |
| The user (role) state. |
trust_input boolean added in 0.2.0 of community.postgresql |
| If no , checks whether values of options name, password, privs, expires, role_attr_flags, groups, comment, session_role are potentially dangerous.It makes sense to use no only when SQL injections through the options are possible. |
Note
NOLOGIN
role_attr_flags to change this behaviour.PUBLIC
as the user (role), then the privilege changes apply to all users (roles). You may not specify password or role_attr_flags when the PUBLIC
user is specified.PGOPTIONS: "-c password_encryption=scram-sha-256"
(see the provided example).pg_authid
is not accessible, thus, the module cannot compare the current and desired password
. In this case, the module assumes that the passwords are different and changes it reporting that the state has been changed. To skip all password related checks for existing users, use no_password_changes=yes.check_mode
.postgres
account on the host.See also
The official documentation on the community.postgresql.postgresql_privs module.
The official documentation on the community.postgresql.postgresql_membership module.
The official documentation on the community.postgresql.postgresql_owner module.
Complete reference of the PostgreSQL database roles documentation.
Complete reference of the PostgreSQL SASL Authentication.
- name: Connect to acme database, create django user, and grant access to database and products table community.postgresql.postgresql_user: db: acme name: django password: ceec4eif7ya priv: "CONNECT/products:ALL" expires: "Jan 31 2020" - name: Add a comment on django user community.postgresql.postgresql_user: db: acme name: django comment: This is a test user # Connect to default database, create rails user, set its password (MD5-hashed), # and grant privilege to create other databases and demote rails from super user status if user exists - name: Create rails user, set MD5-hashed password, grant privs community.postgresql.postgresql_user: name: rails password: md59543f1d82624df2b31672ec0f7050460 role_attr_flags: CREATEDB,NOSUPERUSER - name: Connect to acme database and remove test user privileges from there community.postgresql.postgresql_user: db: acme name: test priv: "ALL/products:ALL" state: absent fail_on_user: no - name: Connect to test database, remove test user from cluster community.postgresql.postgresql_user: db: test name: test priv: ALL state: absent - name: Connect to acme database and set user's password with no expire date community.postgresql.postgresql_user: db: acme name: django password: mysupersecretword priv: "CONNECT/products:ALL" expires: infinity # Example privileges string format # INSERT,UPDATE/table:SELECT/anothertable:ALL - name: Connect to test database and remove an existing user's password community.postgresql.postgresql_user: db: test user: test password: "" - name: Create user test and grant group user_ro and user_rw to it community.postgresql.postgresql_user: name: test groups: - user_ro - user_rw # Create user with a cleartext password if it does not exist or update its password. # The password will be encrypted with SCRAM algorithm (available since PostgreSQL 10) - name: Create appclient user with SCRAM-hashed password community.postgresql.postgresql_user: name: appclient password: "secret123" environment: PGOPTIONS: "-c password_encryption=scram-sha-256"
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description |
---|---|---|
queries list / elements=string | always | List of executed queries. Sample: ['CREATE USER "alice"', 'GRANT CONNECT ON DATABASE "acme" TO "alice"'] |
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/community/postgresql/postgresql_user_module.html