Ich habe Playbook, die Instanz erstellen und hinzufügen Load Balancer, was ist die Art, wie ich alte Instanz bereits ELB zugewiesen entfernen/stoppen kann, möchte ich sicherstellen, dass wir zuerst die alte Instanz stoppen und dann neue 1s hinzugefügt werden oder umgekehrt Vers. Ich verwende AWS ELB und EC2 InstanzWie stoppe ich alte Instanzen von ELB in Ansible?
0
A
Antwort
1
Ich hoffe, dass Ihnen das helfen kann. Sobald Sie die instance id
haben, dann können Sie tun, was Sie wollen, ich entferne es nur aus dem ELB, aber Sie können das ec2
Modul verwenden, um es zu entfernen.
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Get the facts about the ELB
ec2_elb_facts:
names: rbgeek-dev-web-elb
region: "eu-west-1"
register: elb_facts
- name: Instance(s) ID that are currently register to the ELB
debug:
msg: "{{ elb_facts.elbs.0.instances }}"
- name: Tag the Old instances as zombie
ec2_tag:
resource: "{{ item }}"
region: "eu-west-1"
state: present
tags:
Instance_Status: "zombie"
with_items: "{{ elb_facts.elbs.0.instances }}"
- name: Refresh the ec2.py cache
shell: ./inventory/ec2.py --refresh-cache
changed_when: no
- name: Refresh inventory
meta: refresh_inventory
# must check this step with ec2_remote_facts_module.html ##http://docs.ansible.com/ansible/ec2_remote_facts_module.html
- hosts: tag_Instance_Status_zombie
gather_facts: no
tasks:
- name: Get the facts about the zombie instances
ec2_facts:
- name: remove instance by instance id
ec2:
state: absent
region: "eu-west-1"
instance_ids: "{{ ansible_ec2_instance_id }}"
wait: true
delegate_to: localhost
Was haben Sie bisher versucht? Bitte teilen Sie Ihren Playbook-Code. [ec2_elb] (https://docs.ansible.com/ansible/ec2_elb_module.html) –