2012-07-29 18:47:44 +02:00
|
|
|
##
|
|
|
|
# Example Ansible playbook that uses the PostgreSQL module.
|
|
|
|
#
|
|
|
|
# This installs PostgreSQL on an Ubuntu system, creates a database called
|
|
|
|
# "myapp" and a user called "django" with password "mysupersecretpassword"
|
|
|
|
# with access to the "myapp" database.
|
|
|
|
#
|
|
|
|
---
|
|
|
|
- hosts: webservers
|
2012-12-14 11:56:53 +01:00
|
|
|
sudo: yes
|
|
|
|
gather_facts: no
|
2012-07-29 18:47:44 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: ensure apt cache is up to date
|
|
|
|
action: apt update_cache=yes
|
|
|
|
- name: ensure packages are installed
|
2013-05-05 19:41:21 +02:00
|
|
|
action: apt name={{item}}
|
2012-07-29 18:47:44 +02:00
|
|
|
with_items:
|
|
|
|
- postgresql
|
|
|
|
- libpq-dev
|
|
|
|
- python-psycopg2
|
|
|
|
|
|
|
|
- hosts: webservers
|
2012-12-14 11:56:53 +01:00
|
|
|
sudo: yes
|
2012-07-29 18:47:44 +02:00
|
|
|
sudo_user: postgres
|
2012-12-14 11:56:53 +01:00
|
|
|
gather_facts: no
|
2012-07-29 18:47:44 +02:00
|
|
|
|
|
|
|
vars:
|
|
|
|
dbname: myapp
|
|
|
|
dbuser: django
|
|
|
|
dbpassword: mysupersecreetpassword
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: ensure database is created
|
2013-05-05 19:41:21 +02:00
|
|
|
action: postgresql_db db={{dbname}}
|
2012-07-29 18:47:44 +02:00
|
|
|
|
|
|
|
- name: ensure user has access to database
|
2013-05-05 19:41:21 +02:00
|
|
|
action: postgresql_user db={{dbname}} user={{dbuser}} password={{dbpassword}} priv=ALL
|
2012-10-15 23:42:06 +02:00
|
|
|
|
|
|
|
- name: ensure user does not have unnecessary privilege
|
2013-05-05 19:41:21 +02:00
|
|
|
action: postgresql_user user={{dbuser}} role_attr_flags=NOSUPERUSER,NOCREATEDB
|