Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
- name: Launch haproxy EC2 instances
hosts: localhost
connection: local
gather_facts: True
vars:
component_name: "{{ component_name }}"
stack_name: "{{ stack_name }}"
vars_files:
- vars/vars.yml
roles:
- iam_role
- secgroup
- ec2
- name: Set facts - allows build info to pass to hosts
hosts: localhost
connection: local
tasks:
- set_fact:
node0: "{{ ec2_ids.0 }}"
node1: "{{ ec2_ids.1 }}"
node0_ip: "{{ ec2_IPS.0 }}"
node1_ip: "{{ ec2_IPS.1 }}"
- name: Section - Routing
hosts: localhost
connection: local
vars_files:
- vars/vars.yml
tasks:
- name: Get Route table facts
ec2_vpc_route_table_facts:
region: "{{ region }}"
filters:
tag-key: Name
vpc-id: "{{ vpc_id }}"
register: vpc_rt_facts
- name: Store route tables for future use
set_fact:
route_table_ids="{{ vpc_rt_facts|json_query('route_tables[*].id') }}"
- name: Create Route for VIP
shell: |
/usr/bin/aws ec2 describe-route-tables --route-table-id {{ item }} | grep {{ virtual_ip }}
if [ $? -eq 0 ]; then
/usr/bin/aws ec2 delete-route --route-table-id {{ item }} --destination-cidr-block {{ virtual_ip }}/32
/usr/bin/aws ec2 create-route --route-table-id {{ item }} --destination-cidr-block {{ virtual_ip }}/32 --instance-id {{ node0 }}
else
/usr/bin/aws ec2 create-route --route-table-id {{ item }} --destination-cidr-block {{ virtual_ip }}/32 --instance-id {{ node0 }}
fi
with_items: "{{ route_table_ids }}"
- name: Configure nodes
hosts: ec2_hosts
user: ec2-user
become: yes
become_method: sudo
gather_facts: true
vars_files:
- vars/vars.yml
vars:
component_name: "{{ hostvars['localhost']['component_name'] }}"
virtual_ip: "{{ hostvars['localhost']['virtual_ip'] }}"
node0: "{{ hostvars['localhost']['node0'] }}"
node1: "{{ hostvars['localhost']['node1'] }}"
node0_ip: "{{ hostvars['localhost']['node0_ip'] }}"
node1_ip: "{{ hostvars['localhost']['node1_ip'] }}"
rt_table_id: "{{ hostvars['localhost']['route_table_ids']}}"
roles:
- haproxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.