Skip to content

Commit

Permalink
Merge pull request #71 from Oefenweb/add-support-for-haproxy-map
Browse files Browse the repository at this point in the history
Add support for HAProxy map
  • Loading branch information
tersmitten authored Nov 4, 2017
2 parents acf769f + e9256d4 commit 0864bb9
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 54 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python: "2.7"

env:
- ANSIBLE_VERSION=latest
- ANSIBLE_VERSION=2.4.1.0
- ANSIBLE_VERSION=2.4.0.0
- ANSIBLE_VERSION=2.3.2.0
- ANSIBLE_VERSION=2.3.1.0
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst
* `haproxy_userlists.{n}.users.{n}.insecure_password`: [optional] Plaintext password of this user. **One of `password` or `insecure_password` must be set**
* `haproxy_userlists.{n}.users.{n}.groups`: [optional] List of groups to add the user to

* `haproxy_acl_files`: [default: `[]`]: ACL file declarations
* `haproxy_acl_files.{n}.dest`: [required]: The remote path of the file (e.g. `/etc/haproxy/acl/api.map`)
* `haproxy_acl_files.{n}.content`: [default: `[]`]: The content (lines) of the file (e.g. `['v1.0 be_alpha', 'v1.1 be_bravo']`)

## Dependencies

None
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ haproxy_backend: []

# user-lists section
haproxy_userlists: []

# ACL files
haproxy_acl_files: []
24 changes: 24 additions & 0 deletions tasks/acl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# tasks file for haproxy
---
- name: acl | create directories
file:
path: "{{ item.dest | dirname }}"
state: directory
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
mode: 0750
with_items: "{{ haproxy_acl_files }}"
tags:
- haproxy-acl-create-directories

- name: acl | update files
template:
src: etc/haproxy/acl.j2
dest: "{{ item.dest }}"
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
mode: "{{ item.mode | default('0640') }}"
with_items: "{{ haproxy_acl_files }}"
notify: restart haproxy
tags:
- haproxy-acl-update-files
24 changes: 24 additions & 0 deletions tasks/certificates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# tasks file for haproxy
---
- name: certificates | create directories
file:
path: "{{ item.dest | dirname }}"
state: directory
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
mode: 0750
with_items: "{{ haproxy_ssl_map }}"
tags:
- haproxy-certificates-create-directories

- name: certificates | copy files
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
mode: "{{ item.mode | default('0640') }}"
with_items: "{{ haproxy_ssl_map }}"
notify: restart haproxy
tags:
- haproxy-certificates-copy-files
13 changes: 13 additions & 0 deletions tasks/configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# tasks file for haproxy
---
- name: configuration | update file
template:
src: etc/haproxy/haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
owner: root
group: root
mode: 0640
validate: 'haproxy -f %s -c'
notify: restart haproxy
tags:
- haproxy-configuration-update-file
24 changes: 24 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# tasks file for haproxy
---
- name: install | add repository from PPA and install its signing key
apt_repository:
repo: "{{ haproxy_ppa }}"
update_cache: true
tags:
- haproxy-install-add-repository

- name: install | dependencies
apt:
name: "{{ item.name }}"
state: "{{ item.state }}"
with_items: "{{ haproxy_dependencies }}"
tags:
- haproxy-install-dependencies

- name: install | additional
apt:
name: "{{ item }}"
state: "{{ apt_install_state | default('latest') }}"
with_items: "{{ haproxy_install }}"
tags:
- haproxy-install-additional
60 changes: 6 additions & 54 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,25 @@
- haproxy
- haproxy-check-version-support

- name: add repository from PPA and install its signing key
apt_repository:
repo: "{{ haproxy_ppa }}"
update_cache: true
tags:
- configuration
- haproxy
- haproxy-add-repository

- name: install dependencies
apt:
name: "{{ item.name }}"
state: "{{ item.state }}"
with_items: "{{ haproxy_dependencies }}"
tags:
- configuration
- haproxy
- haproxy-dependencies

- name: install
apt:
name: "{{ item }}"
state: "{{ apt_install_state | default('latest') }}"
with_items: "{{ haproxy_install }}"
- include: install.yml
tags:
- configuration
- haproxy
- haproxy-install

- name: create certificate files directories
file:
path: "{{ item.dest | dirname }}"
state: directory
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
mode: 0750
with_items: "{{ haproxy_ssl_map }}"
- include: certificates.yml
tags:
- configuration
- haproxy
- haproxy-configuration
- haproxy-configuration-ssl
- haproxy-certificates

- name: copy certificate files
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
mode: "{{ item.mode | default('0640') }}"
with_items: "{{ haproxy_ssl_map }}"
notify: restart haproxy
- include: acl.yml
tags:
- configuration
- haproxy
- haproxy-configuration
- haproxy-configuration-ssl
- haproxy-acl

- name: update configuration file
template:
src: etc/haproxy/haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
owner: root
group: root
mode: 0640
validate: 'haproxy -f %s -c'
notify: restart haproxy
- include: configuration.yml
tags:
- configuration
- haproxy
Expand Down
5 changes: 5 additions & 0 deletions templates/etc/haproxy/acl.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# {{ ansible_managed }}

{% for content in item.content | default([]) %}
{{ content }}
{% endfor %}
17 changes: 17 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@
insecure_password: secrete
groups:
- test_grp2

# ACL files
haproxy_acl_files:
- dest: /etc/haproxy/acl/ported-paths.list
content:
- |
^/users/add_player$
^/users/view.*$
- dest: /etc/haproxy/acl/api.map
content:
- |
v1.0 be_alpha
v1.1 be_bravo
v2.5 be_charlie
v2.2 be_alpha
v1.1 be_delta

0 comments on commit 0864bb9

Please sign in to comment.