From 7a9ef6a0532db69a9fe9e48981090427485ddad8 Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Thu, 9 Jan 2025 13:21:20 -0500 Subject: [PATCH] Update haproxy role and make it more generic Signed-off-by: Eric D. Helms --- playbooks/haproxy.yml | 4 ++ roles/haproxy/defaults/main.yml | 1 + roles/haproxy/tasks/main.yml | 17 ++--- roles/haproxy/templates/haproxy.cfg.j2 | 93 ++++---------------------- 4 files changed, 24 insertions(+), 91 deletions(-) create mode 100644 playbooks/haproxy.yml create mode 100644 roles/haproxy/defaults/main.yml diff --git a/playbooks/haproxy.yml b/playbooks/haproxy.yml new file mode 100644 index 000000000..e1fa7d609 --- /dev/null +++ b/playbooks/haproxy.yml @@ -0,0 +1,4 @@ +- hosts: all + become: true + roles: + - haproxy diff --git a/roles/haproxy/defaults/main.yml b/roles/haproxy/defaults/main.yml new file mode 100644 index 000000000..6abe8cc88 --- /dev/null +++ b/roles/haproxy/defaults/main.yml @@ -0,0 +1 @@ +haproxy_targets: [] diff --git a/roles/haproxy/tasks/main.yml b/roles/haproxy/tasks/main.yml index 2222236a0..1d287dcf4 100644 --- a/roles/haproxy/tasks/main.yml +++ b/roles/haproxy/tasks/main.yml @@ -1,28 +1,25 @@ --- -- name: discover foreman proxies - setup: - delegate_to: "{{ item }}" - delegate_facts: yes - with_items: - - "{{ foreman_proxies }}" - name: install haproxy - package: + ansible.builtin.package: name: haproxy state: present + - name: set haproxy_connect_any - seboolean: + ansible.posix.seboolean: name: haproxy_connect_any state: yes persistent: yes + - name: configure haproxy - template: + ansible.builtin.template: dest: /etc/haproxy/haproxy.cfg src: haproxy.cfg.j2 validate: haproxy -c -f %s notify: - restart haproxy + - name: enable haproxy - service: + ansible.builtin.service: name: haproxy state: started enabled: yes diff --git a/roles/haproxy/templates/haproxy.cfg.j2 b/roles/haproxy/templates/haproxy.cfg.j2 index 68dc93880..2cd72770b 100644 --- a/roles/haproxy/templates/haproxy.cfg.j2 +++ b/roles/haproxy/templates/haproxy.cfg.j2 @@ -61,8 +61,8 @@ frontend https backend f-proxy-https option tcp-check balance source -{% for host in foreman_proxies %} - server f-proxy-https-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:443 check +{% for host in haproxy_targets %} + server f-proxy-https-{{loop.index}} {{ host }}:443 check {% endfor %} #http @@ -75,25 +75,10 @@ frontend http backend f-proxy-http option tcp-check balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-http-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:80 check +{% for host in haproxy_targets %} + server f-proxy-http-{{loop.index}} {{ host }}:80 check {% endfor %} -#amqp -frontend amqp - bind *:5647 - mode tcp - option tcplog - default_backend f-proxy-amqp - -backend f-proxy-amqp - option tcp-check - balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-amqp-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:5647 check -{% endfor %} - - #anaconda frontend anaconda bind *:8000 @@ -104,74 +89,20 @@ frontend anaconda backend f-proxy-anaconda option tcp-check balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-anaconda-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:8000 check -{% endfor %} - -#puppet -frontend puppet - bind *:8140 - mode tcp - option tcplog - default_backend f-proxy-puppet - -backend f-proxy-puppet - option tcp-check - balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-puppet-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:8140 check +{% for host in haproxy_targets %} + server f-proxy-anaconda-{{loop.index}} {{ host }}:8000 check {% endfor %} -#puppet-ca -frontend puppet-ca - bind *:8141 - mode tcp - option tcplog - default_backend f-proxy-puppet-ca - -backend f-proxy-puppet-ca - option tcp-check - balance roundrobin - server f-proxy-puppet-ca-1 {{ hostvars[foreman_proxies[0]].ansible_default_ipv4.address }}:8140 check - -#rhsm -frontend rhsm - bind *:8443 - mode tcp - option tcplog - default_backend f-proxy-rhsm - -backend f-proxy-rhsm - option tcp-check - balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-rhsm-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:8443 check -{% endfor %} - -#scap -frontend scap +#smart-proxy +frontend smart-proxy bind *:9090 mode tcp option tcplog - default_backend f-proxy-scap - -backend f-proxy-scap - option tcp-check - balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-scap-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:9090 check -{% endfor %} - -#docker -frontend docker - bind *:5000 - mode tcp - option tcplog - default_backend f-proxy-docker + default_backend f-proxy-smart-proxy -backend f-proxy-docker +backend f-proxy-smart-proxy option tcp-check balance roundrobin -{% for host in foreman_proxies %} - server f-proxy-docker-{{loop.index}} {{ hostvars[host].ansible_default_ipv4.address }}:5000 check +{% for host in haproxy_targets %} + server f-proxy-smart-proxy-{{loop.index}} {{ host }}:9090 check {% endfor %}