cluster_rabbitmq.yml 1.49 KB
Newer Older
1

2
# ansible-playbook -i ec2.py cluster_rabbitmq.yml --limit tag_Name_stage-edx-commoncluster -e@/path/to/vars/env-deployment.yml -T 30 --list-hosts
3 4

- hosts: all
5
  become: True
6 7 8 9 10 11 12 13 14 15 16 17 18 19
  serial: 1
  vars:
    # By default take instances in and out of the elb(s) they
    # are attached to
    # To skip elb operations use "-e elb_pre_post=fase"
    elb_pre_post: true
    # Number of instances to operate on at a time
    serial_count: 1
  serial: "{{ serial_count }}"
  pre_tasks:
    - action: ec2_facts
    - debug: var="{{ ansible_ec2_instance_id }}"
      when: elb_pre_post
    - name: Instance De-register
20
      local_action: ec2_elb
21 22 23 24 25
      args:
        instance_id: "{{ ansible_ec2_instance_id }}"
        region: us-east-1
        state: absent
        wait_timeout: 60
26
      become: False
27 28 29 30 31
      when: elb_pre_post
  tasks:
    - debug: msg="{{ ansible_ec2_local_ipv4 }}"
      with_items: list.results
    - command: rabbitmqctl stop_app
32 33
    - command: rabbitmqctl join_cluster rabbit@ip-{{ hostvars.keys()[0]|replace('.', '-') }}
      when: hostvars.keys()[0] != ansible_ec2_local_ipv4
34 35 36 37 38
    - command: rabbitmqctl start_app
  post_tasks:
    - debug: var="{{ ansible_ec2_instance_id }}"
      when: elb_pre_post
    - name: Register instance in the elb
39
      local_action: ec2_elb
40 41 42 43 44 45 46
      args:
        instance_id: "{{ ansible_ec2_instance_id }}"
        ec2_elbs: "{{ item }}"
        region: us-east-1
        state: present
        wait_timeout: 60
      with_items: ec2_elbs
47
      become: False
48
      when: elb_pre_post