Skip to content
Snippets Groups Projects
Commit 63539f81 authored by jurgenhaas's avatar jurgenhaas
Browse files

#5 Backup config before configure.yml and then check config before restart

parent d0de40b9
No related branches found
No related tags found
No related merge requests found
--- ---
# file: roles/haproxy/handler/main.yml # file: roles/haproxy/handler/main.yml
- name: "Proxy | Restart HAProxy" - name: "Check HAProxy Config"
command: haproxy -c -f /etc/haproxy/haproxy.cfg
register: haproxy_config_check
changed_when: '"Configuration file is valid" in haproxy_config_check.stdout_lines'
failed_when: '"Configuration file is valid" not in haproxy_config_check.stdout_lines'
notify: "Restart HAProxy"
- name: "Restart HAProxy"
service: name={{item.name}} state={{item.state}} service: name={{item.name}} state={{item.state}}
with_items: with_items:
- name: haproxy - name: haproxy
......
...@@ -8,4 +8,4 @@ ...@@ -8,4 +8,4 @@
regexp='(fullchain)|(privkey)\.pem' regexp='(fullchain)|(privkey)\.pem'
with_items: '{{ proxy_certificates_letsencrypt|default([]) }}' with_items: '{{ proxy_certificates_letsencrypt|default([]) }}'
notify: notify:
- "Proxy | Restart HAProxy" - "Restart HAProxy"
--- ---
# file: roles/haproxy/tasks/configure.yml # file: roles/haproxy/tasks/configure.yml
- name: "Proxy | Install SSL certificates" - name: "Backup current settings"
archive:
path=/etc/haproxy
dest=/var/backups/haproxy-{{ lookup('pipe','date +%Y%m%d-%H%M%S') }}.tgz
- name: "Install SSL certificates"
copy: copy:
src='{{inventory_dir}}/files/ssl/{{item.file}}' src='{{inventory_dir}}/files/ssl/{{item.file}}'
dest='/etc/haproxy/certs' dest='/etc/haproxy/certs'
with_items: '{{ proxy_certificates }}' with_items: '{{ proxy_certificates }}'
when: not item.letsencrypt|default(false) when: not item.letsencrypt|default(false)
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
- name: "Proxy | Create host lists" - name: "Create host lists"
template: template:
src='host_list' src='host_list'
dest='/etc/haproxy/{{item}}.list' dest='/etc/haproxy/{{item}}.list'
...@@ -17,9 +22,9 @@ ...@@ -17,9 +22,9 @@
group='root' group='root'
mode='644' mode='644'
with_items: '{{ groups.webserver }}' with_items: '{{ groups.webserver }}'
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
- name: "Proxy | Create host ssl lists" - name: "Create host ssl lists"
template: template:
src='host_ssl_list' src='host_ssl_list'
dest='/etc/haproxy/{{item}}.ssl.list' dest='/etc/haproxy/{{item}}.ssl.list'
...@@ -27,9 +32,9 @@ ...@@ -27,9 +32,9 @@
group='root' group='root'
mode='644' mode='644'
with_items: '{{ groups.webserver }}' with_items: '{{ groups.webserver }}'
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
- name: "Proxy | Create host path lists" - name: "Create host path lists"
file: file:
dest='/etc/haproxy/{{item}}.path.list' dest='/etc/haproxy/{{item}}.path.list'
owner='root' owner='root'
...@@ -39,25 +44,25 @@ ...@@ -39,25 +44,25 @@
with_items: '{{ groups.webserver }}' with_items: '{{ groups.webserver }}'
changed_when: false changed_when: false
- name: "Proxy | Create use bigpipe host lists" - name: "Create use bigpipe host lists"
template: template:
src='use_bigpipe_list' src='use_bigpipe_list'
dest='/etc/haproxy/use_bigpipe.list' dest='/etc/haproxy/use_bigpipe.list'
owner='root' owner='root'
group='root' group='root'
mode='644' mode='644'
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
- name: "Proxy | Create ignore varnish host lists" - name: "Create ignore varnish host lists"
template: template:
src='ignore_varnish_list' src='ignore_varnish_list'
dest='/etc/haproxy/ignore_varnish.list' dest='/etc/haproxy/ignore_varnish.list'
owner='root' owner='root'
group='root' group='root'
mode='644' mode='644'
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
- name: "Proxy | Create empty crm lists files" - name: "Create empty crm lists files"
file: file:
dest='/etc/haproxy/{{item}}.crm.list' dest='/etc/haproxy/{{item}}.crm.list'
owner='root' owner='root'
...@@ -67,7 +72,7 @@ ...@@ -67,7 +72,7 @@
with_items: '{{ groups.webserver }}' with_items: '{{ groups.webserver }}'
changed_when: false changed_when: false
- name: "Proxy | Update blacklists" - name: "Update blacklists"
template: template:
src='{{ item }}' src='{{ item }}'
dest='/etc/haproxy/{{ item }}' dest='/etc/haproxy/{{ item }}'
...@@ -78,13 +83,13 @@ ...@@ -78,13 +83,13 @@
- 'blacklist.ip' - 'blacklist.ip'
- 'blacklist.referer' - 'blacklist.referer'
- 'blacklist.agent' - 'blacklist.agent'
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
- name: "Proxy | Create config file" - name: "Create config file"
template: template:
src='haproxy_cfg.jinja2' src='haproxy_cfg.jinja2'
dest='/etc/haproxy/haproxy.cfg' dest='/etc/haproxy/haproxy.cfg'
owner='root' owner='root'
group='root' group='root'
mode='644' mode='644'
notify: 'Proxy | Restart HAProxy' notify: "Check HAProxy Config"
--- ---
# file: roles/haproxy/tasks/install.yml # file: roles/haproxy/tasks/install.yml
- name: "Proxy | Add Apt Repositories" - name: "Add Apt Repositories"
apt_repository: apt_repository:
repo='{{ item }}' repo='{{ item }}'
state=present state=present
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
with_items: with_items:
- "ppa:vbernat/haproxy-1.7" - "ppa:vbernat/haproxy-1.7"
- name: "Proxy | Install some packages" - name: "Install some packages"
apt: apt:
pkg='{{ item }}' pkg='{{ item }}'
state=installed state=installed
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
- hatop - hatop
- socat - socat
- name: "Proxy | create directories" - name: "create directories"
file: file:
dest='{{ item }}' dest='{{ item }}'
state=directory state=directory
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
- /etc/haproxy/certs - /etc/haproxy/certs
- /etc/haproxy/update - /etc/haproxy/update
- name: "Proxy | Install hatop shortcut" - name: "Install hatop shortcut"
copy: copy:
src='usr_local_bin_hatop' src='usr_local_bin_hatop'
dest='/usr/local/bin/hatop' dest='/usr/local/bin/hatop'
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
group='root' group='root'
mode='755' mode='755'
- name: "Proxy | Install log rotator" - name: "Install log rotator"
copy: copy:
src='etc_logrotate_d_haproxy' src='etc_logrotate_d_haproxy'
dest='/etc/logrotate.d/haproxy' dest='/etc/logrotate.d/haproxy'
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
group='root' group='root'
mode='644' mode='644'
- name: "Proxy | Install script to read socket" - name: "Install script to read socket"
template: template:
src='hasocket' src='hasocket'
dest='/usr/local/bin/hasocket' dest='/usr/local/bin/hasocket'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment