Skip to content

Instantly share code, notes, and snippets.

@jaybrueder
Created February 23, 2022 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaybrueder/52288526a85a15b0596199922609f0dc to your computer and use it in GitHub Desktop.
Save jaybrueder/52288526a85a15b0596199922609f0dc to your computer and use it in GitHub Desktop.
Ansible HAProxy Playbook
---
- hosts: webservers
become_user: root
become: yes
tasks:
- name: gather facts from web servers
amazon.aws.ec2_metadata_facts:
- hosts: loadbalancers
become_user: root
become: yes
pre_tasks:
- name: update package list
ansible.builtin.apt:
update_cache: yes
roles:
- role: geerlingguy.haproxy
haproxy_version: "{{ '1.4' if '1.4.' in haproxy_version_result.stdout else '1.5' }}"
haproxy_backend_servers:
- name: web1
address: "{{ hostvars['host1']['ansible_ec2_public_ipv4'] }}:80"
- name: web2
address: "{{ hostvars['host2']['ansible_ec2_public_ipv4'] }}:80"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment