Skip to content

Commit

Permalink
Making haproxy compactable with ansible v2.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasswaroop committed May 28, 2020
1 parent 4c2ecbd commit fcdf349
Showing 1 changed file with 61 additions and 30 deletions.
91 changes: 61 additions & 30 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,86 @@
---
- name: 'Installs haproxy'
apt: pkg=haproxy state=installed
- name: Installs haproxy
apt:
pkg:
- haproxy
state: latest

- name: 'Enable it'
copy: src='haproxy-default' dest='/etc/default/haproxy'
- name: Enable it
copy:
src: haproxy-default
dest: /etc/default/haproxy

- name: 'Create directory for the frontend'
file: path='/etc/haproxy/frontends.d' state=directory
- name: Create directory for the frontend
file:
path: /etc/haproxy/frontends.d
state: directory

- name: 'Empty the folder if not already empty'
command: rm -f /etc/haproxy/backends.d/*.cfg
- name: Empty the folder if not already empty
file:
path: /etc/haproxy/frontends.d/*.cfg
state: absent

- name: 'Build up the frontends'
template: src=frontend.cfg dest=/etc/haproxy/frontends.d/{{ item.name }}.cfg
- name: Build up the frontends
template:
src: frontend.cfg
dest: /etc/haproxy/frontends.d/{{ item.name }}.cfg
with_items: " {{ haproxy_frontends }} "
when: haproxy_frontends is defined

- name: 'Create directory for the backends'
file: path='/etc/haproxy/backends.d' state=directory
- name: Create directory for the backends
file:
path: /etc/haproxy/backends.d
state: directory

- name: 'Empty the folder if not already empty'
command: rm -f /etc/haproxy/backends.d/*.cfg
- name: Empty the folder if not already empty
file:
path: /etc/haproxy/backends.d/*.cfg
state: absent

- name: 'Build up the backends'
template: src=backend.cfg dest=/etc/haproxy/backends.d/{{ item.name }}.cfg
- name: Build up the backends
template:
src: backend.cfg
dest: /etc/haproxy/backends.d/{{ item.name }}.cfg
with_items: " {{ haproxy_backends }} "
when: haproxy_backends is defined

- name: 'Create the compiled folder'
file: path='/etc/haproxy/compiled' state=directory
- name: Create the compiled folder
file:
path: /etc/haproxy/compiled
state: directory

- name: 'Empty the folder if not already empty'
command: rm -f /etc/haproxy/compiled/*.cfg
- name: Empty the folder if not already empty
file:
path: /etc/haproxy/compiled/*.cfg
state: absent

- name: 'Build up the global config'
template: src=global.cfg dest=/etc/haproxy/compiled/01-global.cfg
- name: Build up the global config
template:
src: global.cfg
dest: /etc/haproxy/compiled/01-global.cfg
when: haproxy_global is defined
tags: 'test'

- name: 'Build up the default config'
template: src=defaults.cfg dest=/etc/haproxy/compiled/02-defaults.cfg
- name: Build up the default config
template:
src: defaults.cfg
dest: /etc/haproxy/compiled/02-defaults.cfg
when: haproxy_defaults is defined

# Here we have to go through multiple assemble calls,
# we can't assemble multiple folders into the same destination

- name: 'Assemble the backends configuration file'
assemble: src=/etc/haproxy/backends.d dest=/etc/haproxy/compiled/03-backends.cfg
- name: Assemble the backends configuration file
assemble:
src: /etc/haproxy/backends.d
dest: /etc/haproxy/compiled/03-backends.cfg

- name: 'Assemble the frontends configuration file'
assemble: src=/etc/haproxy/frontends.d dest=/etc/haproxy/compiled/04-frontends.cfg
- name: Assemble the frontends configuration file
assemble:
src: /etc/haproxy/frontends.d
dest: /etc/haproxy/compiled/04-frontends.cfg

- name: 'Assemble the final configuration file'
assemble: src=/etc/haproxy/compiled dest=/etc/haproxy/haproxy.cfg backup=yes
- name: Assemble the final configuration file
assemble:
src: /etc/haproxy/compiled
dest: /etc/haproxy/haproxy.cfg backup=yes

0 comments on commit fcdf349

Please sign in to comment.