rtshome.pgsql

pgsql

This section introduces four new Ansible modules for PostgreSQL:

  • postgresql_table: Ensures a table exists (or doesn't exist) in the database.
  • postgresql_row: Ensures a row exists (or doesn't exist) in a specific table.
  • postgresql_query: Executes a custom query in the database and returns the results.
  • postgresql_command: Runs any command in the database.

For more information, check the project's wiki: Ansible PGSQL Wiki

Requirements

You need to install psycopg2 as mentioned in the Ansible PostgreSQL modules documentation: PostgreSQL Database Modules

Role Variables

No variables are set by the module.

Dependencies

No additional dependencies are listed.

Example Playbook

This example playbook does the following:

  • Creates a table named config in the acme database.
  • Ensures a row is added to the config table.
  • Runs a SELECT query on the config table and saves the results in the variable query.
  • Executes a command to remove all records from the logs table.
    - hosts: servers
      tasks:
        - postgresql_table:
            database: acme
            name: config
            state: present
            columns:
              - {
                name: key,
                type: text,
                null: False
              }
              - {
                name: value,
                type: text,
                null: False
              }
            primary_key:
              - key
        
        - postgresql_row:
            database: acme
            table: config
            row:
              key: env
              value: production

        - postgresql_query:
            database: acme
            query: SELECT * FROM config WHERE env = %(env)s
            parameters:
              env: production 
          register: query

        - postgresql_command:
            database: acme
            command: "TRUNCATE logs"
      roles:
         - rtshome.pgsql

License

This project is licensed under the BSD license.

Author Information

Denis Gasparin denis@gasparin.net Denis's Website

Informazioni sul progetto

Add four modules to interact with PostgreSQL DBMS: postgresql_table, postgresql_row, postgresql_query, postgresql_command.

Installa
ansible-galaxy install rtshome.pgsql
Licenza
bsd-2-clause
Download
76.4k
Proprietario