-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaybook.yml
More file actions
105 lines (83 loc) · 3.14 KB
/
Copy pathplaybook.yml
File metadata and controls
105 lines (83 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
- hosts: all
become: true
tasks:
- name: Install git
apt: name=git state=latest
- name: Add Oracle java repository
apt_repository: repo='ppa:webupd8team/java'
- name: Update apt
apt: update_cache=yes
- name: Accept license terms
debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'
- name: Install Java
apt: name={{item}} state=latest
with_items:
- oracle-java8-installer
- ca-certificates
- oracle-java8-set-default
- name: Download leiningen
get_url: url=https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
dest=/usr/local/bin/lein
mode=0755
- name: Add PostgreSQL repository
apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main'
- name: Add PostgreSQL repository key
apt_key: url=https://www.postgresql.org/media/keys/ACCC4CF8.asc
- name: Update apt
apt: update_cache=yes
- name: Install PostgreSQL and postgis
apt: name={{item}} state=latest
with_items:
- postgresql-9.6
- postgresql-9.6-postgis-2.3
- name: Start PostgreSQL and enable at boot
service: name=postgresql
enabled=yes
state=started
use=service
- name: set admin postgres user password
user: name=postgres password=sefjKaLm7zybE #secret
- name: Ensure postgresql is listening on all localhost
lineinfile: dest=/etc/postgresql/9.6/main/postgresql.conf
regexp='^#?listen_addresses\s*='
line="listen_addresses = '*'"
state=present
backrefs=yes
notify: restart postgresql
- lineinfile: dest=/etc/postgresql/9.6/main/pg_hba.conf
regexp='local\s+all\s+all\s+peer'
line='local all all md5'
insertbefore=BOF
backrefs=yes
notify: restart postgresql
- lineinfile: dest=/etc/postgresql/9.6/main/pg_hba.conf
line='host all all 192.168.32.10/24 md5'
- name: python database adapter
apt: name={{item}}
with_items:
- libpq-dev
- python-psycopg2
handlers:
- name: restart postgresql
service: name=postgresql state=restarted use=service
# Example taken from https://github.com/ansible/ansible-examples/blob/master/language_features/postgresql.yml
- hosts: all
become: yes
become_user: postgres
gather_facts: no
vars:
dbname: sample
dbuser: dev
dbpassword: secretpwd
tasks:
- name: ensure db is created
postgresql_db: name={{dbname}}
- name: ensure user has access to db
postgresql_user: db={{dbname}} name={{dbuser}} password={{dbpassword}} priv=ALL
- name: ensure user doesnt 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
- name: enable postgis for the {{dbname}} database
postgresql_ext: name=postgis db={{dbname}}