Denis Gasparin

Hardware and Software Solutions for your Company

Contact me:

Ansible Pgsql Role

rtshome.pgsql is a role available in Ansible Galaxy that provides four new ansible modules for Postgresql:

  • postgresql_table: ensure that a table is present (or absent) in database
  • postgresql_row: ensure that a row is present (or absent) in a table
  • postgresql_query: execute an arbitrary query in database and return results
  • postgresql_command: execute an arbitrary query in database

For additional docs look project’s wiki:


$ ansible-galaxy install rtshome.pgsql


It requires psycopg2 installed as per Ansible’s PostgreSQL modules:

Example Playbook

Sample playbook that:

  • creates the table config in acme database
  • ensures that a row is present in config table
  • performs a SELECT query on config and stores results in query var
  • execute a command removing all records in logs table

Categories: PGDay2017, Planet PostgreSQL, PostgreSQL, Talks