Ok looks like a change in behaviour in Ansible v2:
Following playbook in v2 results in this which I think is failing as its
trying to run on the remote host:
TASK [debug msg={{ hostvars[inventory_hostname]['ec2_id'] }}]
******************
ok: [10.237.3.62] => {
"changed": false,
"msg": "i-f2fc90ca"
}
TASK [Terminate instances]
*****************************************************
fatal: [10.237.3.62]: FAILED! => {"changed": false, "failed": true, "msg":
"boto required for this module"}
Downgrade to Ansible v1.9.4 and it terminates successfully:
TASK: [debug msg={{ hostvars[inventory_hostname]['ec2_id'] }}]
****************
ok: [10.237.3.62] => {
"msg": "i-f2fc90ca"
}
msg:
i-f2fc90ca
TASK: [Terminate instances]
***************************************************
changed: [10.237.3.62 -> 127.0.0.1]
PLAY RECAP
********************************************************************
10.237.3.62 : ok=4 changed=1 unreachable=0 failed=0
Play looks like:
---
- name: Termination Script
hosts: ec2
gather_facts: False
connection: local
vars:
- region: 'cn-north-1'
tasks:
- name: Gather EC2 facts
local_action: ec2_facts
- debug: var=hostvars[inventory_hostname]
- debug: "msg={{ hostvars[inventory_hostname]['ec2_id'] }}"
- name: Terminate instances
local_action: ec2
profile='china'
state='absent'
instance_ids='{{ ec2_id }}'
region='{{ region }}'
wait=True
On Thursday, October 22, 2015 at 10:32:09 AM UTC+10, K Cheng wrote:
>
> Hi All,
>
> I'm trying to create a terminate AWS EC2 play using the dynamic inventory
> script but I keep getting fatal: [remote_host_ip]: FAILED! => {"changed":
> false, "failed": true, "msg": "boto required for this module"}.
>
> I created the instance using another play and that works perfectly.
>
> My terminate play looks like this:
>
> ---
> - name: Find instances
> hosts: tag_Environment_goji
> gather_facts: False
> tasks:
>
> - name: Create group
> group_by: key=mark_terminate
>
> - hosts: mark_terminate
> connection: local
> gather_facts: false
> tasks:
>
> - name: Terminate instance(s)
> ec2:
> profile: china
> region: cn-north-1
> instance_ids: "{{ ec2_id }}"
> state: absent
>
>
>
> I'm running Ansible 2.0.0-beta.
> I run the playbook using this from my local laptop:
>
> ansible-playbook -i china_aws_inventory/ec2.py
> roles/terminate_environment.yml -e "env=goji" --limit tag_Environment_goji
> -vvvv
> Using /Users/Etherdaemon/personal/coderepos/ansible/ansible.cfg as config
> file
> 2 plays in roles/terminate_environment.yml
> Loaded callback default of type stdout, v2.0
>
> PLAY [Find instances]
> **********************************************************
>
> TASK [Create group]
> ************************************************************
> changed: [10.237.3.62] => {"add_group": "mark_terminate", "changed": true}
>
> PLAY
> ***************************************************************************
>
> TASK [Terminate instance(s)]
> ***************************************************
> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
> 10.237.3.62 EXEC (umask 22 && mkdir -p
> "$HOME/.ansible/tmp/ansible-tmp-1445473215.44-14684358660357" && echo
> "$HOME/.ansible/tmp/ansible-tmp-1445473215.44-14684358660357")
> 10.237.3.62 PUT /var/folders/vh/rdc7pnkj2kz6vs9vhb844c480000gn/T/tmpCoE5zB
> TO
> /Users/Etherdaemon/.ansible/tmp/ansible-tmp-1445473215.44-14684358660357/ec2
> 10.237.3.62 EXEC LANG=C LC_MESSAGES=C LC_CTYPE=C /usr/bin/python
> /Users/Etherdaemon/.ansible/tmp/ansible-tmp-1445473215.44-14684358660357/ec2;
> rm -rf
> "/Users/Etherdaemon/.ansible/tmp/ansible-tmp-1445473215.44-14684358660357/"
> > /dev/null 2>&1
> fatal: [10.237.3.62]: FAILED! => {"changed": false, "failed": true, "msg":
> "boto required for this module"}
>
> PLAY RECAP
> *********************************************************************
> 10.237.3.62 : ok=1 changed=1 unreachable=0 failed=1
>
>
>
> The part I'm confused about is that I thought connection: local ran the
> terminate command from my local laptop - not from the remote host I want to
> terminate? The above output look like it's trying to run it from the
> remote??
>
> If I change hosts to localhost in the playbook then I get skipping: no
> hosts matched when trying to find the instances.
>
> If I run the inventory first using python china_aws_inventory/ec2.py
> --refresh-cache it finds all the instances, but running the play still says
> skipping due to no hosts found.
>
> I'm running on:
> - MAC OSX 10.10.5
> - Ansible v2.0.0-0.3.beta1
> - boto: 2.38.0
>
> Launch scripts using the same ec2 module and boto profile works fine.
>
> Any help greatly appreciated.
>
> Karen
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d1b66434-a306-4c21-b8a1-d9b61fc01bd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.