Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update haproxy role and make it more generic #1892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions playbooks/haproxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- hosts: all
become: true
roles:
- haproxy
1 change: 1 addition & 0 deletions roles/haproxy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
haproxy_targets: []
17 changes: 7 additions & 10 deletions roles/haproxy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
93 changes: 12 additions & 81 deletions roles/haproxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the port also be in the variable? Perhaps even make the var a dict: service -> backends where each backend is just hostname:port

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in go fully generic? I was intending to keep this specific to our load-balancer use case, but remove the fact that it was tightly coupled to how Vagrant works within Forklift to have an inventory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm debating it. On the one hand, it's good but if we go that route perhaps we can use some community collection instead. You could design an intermediate layer too. On the other hand, it may also be overkill.

I'm fine merging this now (provided tests pass) and leave it to a future improvement. Just want to make sure we at least consider it

{% endfor %}

#http
Expand All @@ -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
Expand All @@ -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 %}
Loading