Documentation

postgresql_db - Add or remove PostgreSQL databases from a remote host.

Synopsis

  • Add or remove PostgreSQL databases from a remote host.

Options

parameter required default choices comments
encoding
no
Encoding of the database
lc_collate
no
Collation order (LC_COLLATE) to use in the database. Must match collation order of template database unless template0 is used as template.
lc_ctype
no
Character classification (LC_CTYPE) to use in the database (e.g. lower, upper, ...) Must match LC_CTYPE of template database unless template0 is used as template.
login_host
no
Host running the database
login_password
no
The password used to authenticate with
login_unix_socket
no
Path to a Unix domain socket for local connections
login_user
no postgres
The username used to authenticate with
name
yes
name of the database to add or remove
owner
no
Name of the role to set as owner of the database
port
no 5432
Database port to connect to.
ssl_mode
(added in 2.3)
no prefer
  • disable
  • allow
  • prefer
  • require
  • verify-ca
  • verify-full
Determines whether or with what priority a secure SSL TCP/IP connection will be 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.
ssl_rootcert
(added in 2.3)
no
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.
state
no present
  • present
  • absent
The database state
template
no
Template used to create the database

Examples

# Create a new database with name "acme"
- postgresql_db:
    name: acme

# Create a new database with name "acme" and specific encoding and locale
# settings. If a template different from "template0" is specified, encoding
# and locale settings must match those of the template.
- postgresql_db:
    name: acme
    encoding: UTF-8
    lc_collate: de_DE.UTF-8
    lc_ctype: de_DE.UTF-8
    template: template0

Notes

Note

  • The default authentication assumes that you are either logging in as or sudo’ing to the postgres account on the host.
  • This module uses psycopg2, a Python PostgreSQL database adapter. You must ensure that psycopg2 is installed on the host before using this module. If the remote host is the PostgreSQL server (which is the default case), then PostgreSQL must also be installed on the remote host. For Ubuntu-based systems, install the postgresql, libpq-dev, and python-psycopg2 packages on the remote host before using this module.
  • The ssl_rootcert parameter requires at least Postgres version 8.4 and psycopg2 version 2.4.3.

Status

This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.

Support

This module is community maintained without core committer oversight.

For more information on what this means please read Module Support

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.