-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerdns_setup.yml
182 lines (158 loc) · 4.73 KB
/
powerdns_setup.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
- name: Install and configure PowerDNS
hosts: "{{ 'app2' if DEPLOY_ENV == 'staging' else 'app' }}"
become: yes
tasks:
- name: Add PowerDNS repository key
ansible.builtin.apt_key:
url: "https://repo.powerdns.com/FD380FBB-pub.asc"
state: present
- name: Add PowerDNS repository
ansible.builtin.apt_repository:
repo: "deb [arch=amd64] http://repo.powerdns.com/ubuntu {{ ansible_distribution_release }}-auth-{{ pdns_auth_version }} main"
state: present
vars:
pdns_auth_version: "48"
- name: Update apt cache
ansible.builtin.apt:
update_cache: yes
- name: Delete content & directory
ansible.builtin.file:
state: absent
path: /etc/resolv.conf
- name: Copy Resolve configuration file
ansible.builtin.copy:
src: resolv.conf
dest: /etc/resolv.conf
owner: root
group: root
mode: '0644'
- name: Disable and stop systemd-resolved
ansible.builtin.systemd:
name: systemd-resolved
state: stopped
enabled: no
- name: Install required packages
ansible.builtin.package:
name:
- pdns-server
- pdns-backend-pipe
- python3
- logrotate
- nginx
state: present
- name: Install Node.js 18.x repository
shell: "curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -"
- name: Install Node.js
apt:
name: nodejs
state: latest
update_cache: yes
- name: Create the destination directory
file:
path: /opt/healthchecker/src
state: directory
become: yes
- name: Sync application files
synchronize:
src: src/
dest: /opt/healthchecker/src
recursive: yes
- name: Template the health route
ansible.builtin.template:
src: src/routes/health.js.j2
dest: /opt/healthchecker/src/routes/health.js
owner: root
group: root
mode: 0777
vars:
subdomain: "{{ 'app2' if DEPLOY_ENV == 'staging' else 'app' }}"
- name: Make sure the start script is executable
file:
path: /opt/healthchecker/src/start.sh
mode: '0755'
- name: Start the application
command: /opt/healthchecker/src/start.sh
args:
chdir: /opt/healthchecker/src
- name: Copy PowerDNS configuration file
ansible.builtin.template:
src: pdns.conf.j2
dest: /etc/powerdns/pdns.conf
owner: root
group: root
mode: '0644'
vars:
subdomain: "{{ 'app2' if DEPLOY_ENV == 'staging' else 'app' }}"
- name: Ensure /opt/pdns/scripts directory exists
ansible.builtin.file:
path: /opt/pdns/scripts
state: directory
owner: root
group: root
mode: 0755
- name: Set variables for STAGING
set_fact:
APP_LIST:
- START: "0"
END: "9"
IPs: ["fdm-lb-2-1.runonflux.io"]
- START: "a"
END: "m"
IPs: ["fdm-lb-2-1.runonflux.io"]
- START: "n"
END: "z"
IPs: ["fdm-lb-2-2.runonflux.io"]
when: DEPLOY_ENV == 'staging'
- name: Set variables for PRODUCTION
set_fact:
APP_LIST:
- START: "0"
END: "9"
IPs: ["fdm-lb-1-1.runonflux.io"]
- START: "a"
END: "g"
IPs: ["fdm-lb-1-1.runonflux.io"]
- START: "h"
END: "n"
IPs: ["fdm-lb-1-2.runonflux.io"]
- START: "o"
END: "u"
IPs: ["fdm-lb-1-3.runonflux.io"]
- START: "v"
END: "z"
IPs: ["fdm-lb-1-4.runonflux.io"]
when: DEPLOY_ENV != 'staging'
- name: Copy multiple files to remote server
ansible.builtin.template:
src: scripts/pdns_pipe_backend.py.j2
dest: /opt/pdns/scripts/pdns_pipe_backend.py
owner: root
group: root
mode: 0777
- name: Copy PowerDNS logrotate configuration
ansible.builtin.copy:
src: pdns_logrotate.conf
dest: /etc/logrotate.d/pdns
owner: root
group: root
mode: '0644'
- name: Set DEPLOY_ENV environment variable
ansible.builtin.lineinfile:
path: /etc/environment
regexp: '^DEPLOY_ENV='
line: "DEPLOY_ENV={{ DEPLOY_ENV }}"
state: present
- name: Restart PowerDNS service
ansible.builtin.systemd:
name: pdns
state: restarted
enabled: yes
- name: Ensure logrotate runs daily
ansible.builtin.cron:
name: "logrotate"
user: "root"
job: "/usr/sbin/logrotate /etc/logrotate.conf"
day: "*"
hour: "0"
minute: "0"