Skip to content

Instantly share code, notes, and snippets.

@Natim
Created September 13, 2013 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Natim/6548009 to your computer and use it in GitHub Desktop.
Save Natim/6548009 to your computer and use it in GitHub Desktop.
I have roles that needs to create each a postgres role and a postgres database. I would like to use the magic of saltstack to do that. Lets say my roles are peopleask and novaauth. How to make it work when both roles are on the same server?
postgresql_db_user: novaauth
postgresql_db_password: novaauth
postgresql_db_name: novaauth
postgresql_db_user: peopleask
postgresql_db_password: peopleask
postgresql_db_name: peopleask
base:
'roles:peopleask':
- match: grain
- peopleask.db
'roles:novaauth':
- match: grain
- novaauth.db
postgresql:
pkg:
- name: postgresql-9.1
- installed
service.running:
- enable: True
postgresql_db_{{ pillar['postgresql_db_name'] }}:
postgres_database.present:
- name: {{ pillar['postgresql_db_name'] }}
- owner: {{ pillar['postgresql_db_user'] }}
- encoding: UTF8
- lc_ctype: en_US.UTF8
- lc_collate: en_US.UTF8
- template: template0
- runas: postgres
- require:
- service: postgresql
- postgres_user: postgresql_user_{{ pillar['postgresql_db_user'] }}
postgresql_user_{{ pillar['postgresql_db_user'] }}:
postgres_user.present:
- name: {{ pillar['postgresql_db_user'] }}
- password: {{ pillar['postgresql_db_password'] }}
- require:
- service: postgresql
postgresql.conf:
file.append:
- name: /etc/postgresql/9.1/main/postgresql.conf
- text: "listen_addresses = '*'"
- require:
- pkg: postgresql
- watch_in:
- service: postgresql
base:
'G@roles:peopleask and G@roles:postgresql':
- match: compound
- postgresql
'G@roles:novaauth and G@roles:postgresql':
- match: compound
- postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment