-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
143 lines (127 loc) · 3.52 KB
/
playbook.yml
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
- name: Deploy servers
hosts: localhost
gather_facts: no
vars_files:
- environments/{{ env }}/group_vars/rax.yml
tasks:
- name: Ensure database servers
rax:
wait: yes
name: "{{ database.name }}"
auto_increment: yes
image: "{{ database.image }}"
flavor: "{{ database.flavor }}"
region: "{{ database.region|default('IAD') }}"
group: "{{ database.group|default('database') }}"
key_name: "{{ database.key_name }}"
count: "{{ database.count|default(1) }}"
exact_count: yes
register: database_servers
- name: Register new database hosts
add_host:
hostname: "{{ item.name }}"
ansible_host: "{{ item.rax_accessipv4 }}"
ansible_ssh_host: "{{ item.rax_accessipv4 }}"
groups: "{{ database.group|default('database') }}"
with_items: "{{ database_servers.success }}"
when: database_servers.action == 'create'
- name: Configure access
hosts: "{{ env }}"
remote_user: root
gather_facts: no
vars_files:
- environments/{{ env }}/group_vars/rax.yml
tasks:
# TODO: Fetch host keys
- name: Ensure SSH keys
authorized_key:
user: root
key: https://github.com/{{ item }}.keys
with_items:
- dirn
- jonafato
- name: Secure servers
hosts: "{{ env }}"
remote_user: root
roles:
- role: hardening.os-hardening
os_ignore_users:
- postgres
- role: hardening.ssh-hardening
ssh_allow_root_with_key: true
tasks:
- name: Deny everything by default
ufw:
state: reloaded
policy: deny
- name: Allow SSH
ufw:
rule: allow
port: 22
proto: tcp
- name: Configure database servers
hosts: "{{ database.group|default('database') }}"
remote_user: root
vars_files:
- environments/{{ env }}/group_vars/db.yml
- environments/{{ env }}/group_vars/rax.yml
roles:
- role: ANXS.postgresql
postgresql_version: 9.5
postgresql_default_auth_method: md5
postgresql_listen_addresses: '*'
postgresql_pg_hba_default:
- type: local
database: all
user: "{{ postgresql_admin_user }}"
address: ''
method: peer
- type: local
database: all
user: all
address: ''
method: peer
- type: host
database: all
user: all
address: 127.0.0.1/32
method: "{{ postgresql_default_auth_method }}"
- type: host
database: all
user: all
address: ::1/128
method: "{{ postgresql_default_auth_method }}"
- type: host
database: all
user: all
address: 0.0.0.0/0
method: "{{ postgresql_default_auth_method }}"
- type: host
database: all
user: all
address: ::0/0
method: "{{ postgresql_default_auth_method }}"
postgresql_databases:
- name: "{{ db_name }}"
hstore: yes
postgresql_database_extensions:
- db: "{{ db_name }}"
extensions:
- hstore
postgresql_users:
- name: "{{ db_user }}"
pass: "{{ db_pass }}"
encrypted: no
postgresql_user_privileges:
- name: "{{ db_user }}"
db: "{{ db_name }}"
priv: ALL
role_attr_flags: NOSUPERUSER,NOCREATEDB
tasks:
# TODO: Only allow in-network traffic
- name: Allow Postgres
ufw:
rule: allow
port: 5432
proto: tcp