Skip to content

Commit e052274

Browse files
committed
Update haproxy role and make it more generic
Signed-off-by: Eric D. Helms <ericdhelms@gmail.com>
1 parent e7a0f21 commit e052274

File tree

4 files changed

+24
-91
lines changed

4 files changed

+24
-91
lines changed

playbooks/haproxy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- hosts: all
2+
become: true
3+
roles:
4+
- haproxy

roles/haproxy/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
haproxy_targets: []

roles/haproxy/tasks/main.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
---
2-
- name: discover foreman proxies
3-
setup:
4-
delegate_to: "{{ item }}"
5-
delegate_facts: yes
6-
with_items:
7-
- "{{ foreman_proxies }}"
82
- name: install haproxy
9-
package:
3+
ansible.builtin.package:
104
name: haproxy
115
state: present
6+
127
- name: set haproxy_connect_any
13-
seboolean:
8+
ansible.builtin.seboolean:
149
name: haproxy_connect_any
1510
state: yes
1611
persistent: yes
12+
1713
- name: configure haproxy
18-
template:
14+
ansible.builtin.template:
1915
dest: /etc/haproxy/haproxy.cfg
2016
src: haproxy.cfg.j2
2117
validate: haproxy -c -f %s
2218
notify:
2319
- restart haproxy
20+
2421
- name: enable haproxy
25-
service:
22+
ansible.builtin.service:
2623
name: haproxy
2724
state: started
2825
enabled: yes

roles/haproxy/templates/haproxy.cfg.j2

Lines changed: 12 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ frontend https
6161
backend f-proxy-https
6262
option tcp-check
6363
balance source
64-
{% for host in foreman_proxies %}
65-
server f-proxy-https-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:443 check
64+
{% for host in haproxy_targets %}
65+
server f-proxy-https-{{loop.index}} {{ host }}:443 check
6666
{% endfor %}
6767

6868
#http
@@ -75,25 +75,10 @@ frontend http
7575
backend f-proxy-http
7676
option tcp-check
7777
balance roundrobin
78-
{% for host in foreman_proxies %}
79-
server f-proxy-http-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:80 check
78+
{% for host in haproxy_targets %}
79+
server f-proxy-http-{{loop.index}} {{ host }}:80 check
8080
{% endfor %}
8181

82-
#amqp
83-
frontend amqp
84-
bind *:5647
85-
mode tcp
86-
option tcplog
87-
default_backend f-proxy-amqp
88-
89-
backend f-proxy-amqp
90-
option tcp-check
91-
balance roundrobin
92-
{% for host in foreman_proxies %}
93-
server f-proxy-amqp-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:5647 check
94-
{% endfor %}
95-
96-
9782
#anaconda
9883
frontend anaconda
9984
bind *:8000
@@ -104,74 +89,20 @@ frontend anaconda
10489
backend f-proxy-anaconda
10590
option tcp-check
10691
balance roundrobin
107-
{% for host in foreman_proxies %}
108-
server f-proxy-anaconda-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:8000 check
109-
{% endfor %}
110-
111-
#puppet
112-
frontend puppet
113-
bind *:8140
114-
mode tcp
115-
option tcplog
116-
default_backend f-proxy-puppet
117-
118-
backend f-proxy-puppet
119-
option tcp-check
120-
balance roundrobin
121-
{% for host in foreman_proxies %}
122-
server f-proxy-puppet-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:8140 check
92+
{% for host in haproxy_targets %}
93+
server f-proxy-anaconda-{{loop.index}} {{ host }}:8000 check
12394
{% endfor %}
12495

125-
#puppet-ca
126-
frontend puppet-ca
127-
bind *:8141
128-
mode tcp
129-
option tcplog
130-
default_backend f-proxy-puppet-ca
131-
132-
backend f-proxy-puppet-ca
133-
option tcp-check
134-
balance roundrobin
135-
server f-proxy-puppet-ca-1 {{ hostvars[foreman_proxies[0]].ansible_default_ipv4.address }}:8140 check
136-
137-
#rhsm
138-
frontend rhsm
139-
bind *:8443
140-
mode tcp
141-
option tcplog
142-
default_backend f-proxy-rhsm
143-
144-
backend f-proxy-rhsm
145-
option tcp-check
146-
balance roundrobin
147-
{% for host in foreman_proxies %}
148-
server f-proxy-rhsm-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:8443 check
149-
{% endfor %}
150-
151-
#scap
152-
frontend scap
96+
#smart-proxy
97+
frontend smart-proxy
15398
bind *:9090
15499
mode tcp
155100
option tcplog
156-
default_backend f-proxy-scap
157-
158-
backend f-proxy-scap
159-
option tcp-check
160-
balance roundrobin
161-
{% for host in foreman_proxies %}
162-
server f-proxy-scap-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:9090 check
163-
{% endfor %}
164-
165-
#docker
166-
frontend docker
167-
bind *:5000
168-
mode tcp
169-
option tcplog
170-
default_backend f-proxy-docker
101+
default_backend f-proxy-smart-proxy
171102

172-
backend f-proxy-docker
103+
backend f-proxy-smart-proxy
173104
option tcp-check
174105
balance roundrobin
175-
{% for host in foreman_proxies %}
176-
server f-proxy-docker-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:5000 check
106+
{% for host in haproxy_targets %}
107+
server f-proxy-smart-proxy-{{loop.index}} {{ host }}:9090 check
177108
{% endfor %}

0 commit comments

Comments
 (0)