Skip to content

postgresql_row

Denis Gasparin edited this page Oct 1, 2017 · 1 revision

postgresql_table: add or remove a row from PostgreSQL table

Synopsis

  • add or remove a row from PostgreSQL table

Requirements

These are requirements in the host that executes the module:

  • psycopg2

Options

parameter required default choices comments
database no postgres Name of the database to connect to.
login_host no localhost Host running the database.
login_user no The username used to authenticate with.
login_password no The password used to authenticate with.
login_unix_socket no Path to a Unix domain socket for local connections.
port no 5432 Database port to connect to.
schema no public Schema where the table is defined
table yes The table to check for row presence/absence
state no present present, absent The row state
row yes Dictionary with the fields of the row

Examples

# Ensure row with fields key="environment" and value="production" is present in db
- postgresql_row:
    database: my_app_config
    table: app_config
    row:
        key: environment
        value: production
    state:
        present

Return Values

name description returned type
executed_query the body of the last query sent to the backend (including bound arguments) as bytes string success string
executed_command the body of the command executed to insert the missing row including bound arguments success string

Notes

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 C(postgresql), C(libpq-dev), and C(python-psycopg2) packages on the remote host before using this module.

Clone this wiki locally