Skip to content

Instantly share code, notes, and snippets.

@tumainimosha
Last active August 9, 2018 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tumainimosha/c94f716dac856186475d5156b1efb8e9 to your computer and use it in GitHub Desktop.
Save tumainimosha/c94f716dac856186475d5156b1efb8e9 to your computer and use it in GitHub Desktop.
##
# Example Ansible playbook that uses the PostgreSQL module.
#
# This installs PostgreSQL on an Ubuntu system, creates a database called
# "app" and a user called "app" with password "secret"
# with access to the "app" database.
#
---
- hosts: appBackend
become: yes
gather_facts: no
tasks:
- name: ensure apt cache is up to date
apt: update_cache=yes
- name: ensure packages are installed
apt: name={{item}}
with_items:
- postgresql
- libpq-dev
- python-psycopg2
- hosts: appBackend
become: yes
become_user: postgres
gather_facts: no
vars:
dbname: app
dbuser: app_usr
dbpassword: secret
tasks:
- name: ensure database is created
postgresql_db: name={{dbname}}
- name: ensure user has access to database
postgresql_user: db={{dbname}} name={{dbuser}} password={{dbpassword}} priv=ALL
- name: ensure user does not have unnecessary privilege
postgresql_user: name={{dbuser}} role_attr_flags=NOSUPERUSER,NOCREATEDB
- name: ensure no other user can access the database
postgresql_privs: db={{dbname}} role=PUBLIC type=database priv=ALL state=absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment