Kill AWS EC2 instances based on TAG (without success)

15 views
Skip to first unread message

Ricardson

unread,
Oct 16, 2017, 10:49:33 AM10/16/17
to Ansible Project
Hi All,

 I`m struggling to get this working without success.. Here my playbook.

First a search my machines by tag and later try to terminate them.


---

   - name: EC2 Facts
     ec2_instance_facts:
      region: us-east-1
      filters:
        "tag:Type": "staging"
      aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
      aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
     register: ec2

   - name: Kill EC2 Instance
     ec2:
     instance_ids: "{{ ec2.instance_id }}"
     state: "{{ state }}"
     region: "{{ lookup('env', 'AWS_REGION') }}"
     aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
     aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"



Running
ansible-playbook ec2_id_kill.yml --extra-vars "state=absent"

Error:
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "image parameter is required for new instance"}



Looks like I cannot able to parse the facts.




Reply all
Reply to author
Forward
0 new messages