Ansible 1.3.2 doesn't seem to work with ec2 samples?

Hi,

I’ve just clean installed ansible 1.3.2 from rquillo’s PPA on my Ubuntu 12.04 system.

I created a playbook file (ansible-ec2.yml) with the following contents from the ec2 module documentation:

Launch instances, runs some tasks

and then terminate them

  • name: Create a sandbox instance
    hosts: localhost
    gather_facts: False
    vars:
    keypair: langfords
    instance_type: m1.small
    security_group: sg-1edd3571
    image: ami-c7c0d6b3
    region: eu-west-1
    tasks:
  • name: Launch instance
    local_action: ec2 keypair={{ keypair }} group={{ security_group }} instance_type={{ instance_type }} image={{ image }} wait=true region={{ region }}
    register: ec2
  • name: Add new instance to host group
    local_action: add_host hostname={{ item.public_ip }} groupname=launched
    with_items: ec2.instances
  • name: Wait for SSH to come up
    local_action: wait_for host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
    with_items: ec2.instances

And my /etc/ansible/hosts has a single entry:
localhost ansible_connection=local

I run this and it fails. Similar posts on this list suggest I have out of date modules, but I don’t know where these might be or how they might have got there?
langfords@langfords4$ ansible-playbook ansible-ec2.yaml -vvvv

PLAY [Create a sandbox instance] **********************************************

TASK: [Launch instance] *******************************************************
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1381143657.34-222947650962172 && chmod a+rx $HOME/.ansible/tmp/ansible-1381143657.34-222947650962172 && echo $HOME/.ansible/tmp/ansible-1381143657.34-222947650962172’]
<127.0.0.1> REMOTE_MODULE ec2 keypair=langfords group=sg-1edd3571 instance_type=m1.small image=ami-c7c0d6b3 wait=true region=eu-west-1
<127.0.0.1> PUT /tmp/tmpocPJSL TO /home/langfords/.ansible/tmp/ansible-1381143657.34-222947650962172/ec2
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘/usr/bin/python /home/langfords/.ansible/tmp/ansible-1381143657.34-222947650962172/ec2; rm -rf /home/langfords/.ansible/tmp/ansible-1381143657.34-222947650962172/ >/dev/null 2>&1’]
failed: [localhost] => {“failed”: true, “parsed”: false}
invalid output was: Traceback (most recent call last):
File “/home/langfords/.ansible/tmp/ansible-1381143657.34-222947650962172/ec2”, line 1549, in
main()
File “/home/langfords/.ansible/tmp/ansible-1381143657.34-222947650962172/ec2”, line 612, in main
(instance_dict_array, new_instance_ids, changed) = create_instances(module, ec2)
File “/home/langfords/.ansible/tmp/ansible-1381143657.34-222947650962172/ec2”, line 437, in create_instances
res = ec2.run_instances(**params)
TypeError: run_instances() got an unexpected keyword argument ‘instance_profile_name’

FATAL: all hosts have already failed – aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/langfords/ansible-ec2.yaml.retry

localhost : ok=0 changed=0 unreachable=0 failed=1

How did you install ansible? The modules are (by default) installed in /usr/share/ansible, and it would appear that the cloud/ec2 file is out of date, as it’s erroring out on a new parameter that was added in 1.3.

Hi James,

I added the Ubuntu PPA mentioned on this page: http://www.ansibleworks.com/docs/intro_installation.html

And then just ran: sudo apt-get install ansible

Cheers
Simon

Hi James,

I checked the folder you mentioned and it seems to know about the parameter:

langfords@langfords4:/usr/share/ansible/cloud$ pwd
/usr/share/ansible/cloud
langfords@langfords4:/usr/share/ansible/cloud$ cat ec2 | grep instance_profile_name
instance_profile_name:
instance_profile_name = module.params.get(‘instance_profile_name’)
‘instance_profile_name’: instance_profile_name}
instance_profile_name = dict(),

So, I tried to force the module dir on the command line, and now it appears the issue has gone away, to be replaced by an auth issue:

langfords@langfords4:~/Dropbox/work/clouddeploy$ ansible-playbook -M /usr/share/ansible -i /etc/ansible/hosts ansible-ec2.yaml -vvvv

PLAY [Create a sandbox instance] **********************************************

TASK: [Launch instance] *******************************************************
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1381222473.64-270653428553926 && chmod a+rx $HOME/.ansible/tmp/ansible-1381222473.64-270653428553926 && echo $HOME/.ansible/tmp/ansible-1381222473.64-270653428553926’]
<127.0.0.1> REMOTE_MODULE ec2 keypair=langfords group=sg-1edd3571 instance_type=m1.small image=ami-c7c0d6b3 wait=true region=eu-west-1
<127.0.0.1> PUT /tmp/tmp0BjAph TO /home/langfords/.ansible/tmp/ansible-1381222473.64-270653428553926/ec2
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘/usr/bin/python /home/langfords/.ansible/tmp/ansible-1381222473.64-270653428553926/ec2; rm -rf /home/langfords/.ansible/tmp/ansible-1381222473.64-270653428553926/ >/dev/null 2>&1’]
failed: [localhost] => {“failed”: true}
msg: No handler was ready to authenticate. 1 handlers were checked. [‘QuerySignatureV2AuthHandler’] Check your credentials

FATAL: all hosts have already failed – aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/langfords/ansible-ec2.yaml.retry

localhost : ok=0 changed=0 unreachable=0 failed=1

My /etc/ansible/hosts is still as below:
localhost ansible_connection=local

How have you configured your AWS credentials? Are you exporting them?

Ah, oops… I’d switched terminal windows… right, so back to the original prob.

I’ve run with -M to force the location and it makes no difference:

langfords@langfords4:~/Dropbox/work/clouddeploy$ ./run_ansible ansible-ec2.yaml -M /usr/share/ansible

PLAY [Create a sandbox instance] **********************************************

TASK: [Launch instance] *******************************************************
failed: [localhost] => {“failed”: true, “parsed”: false}
invalid output was: Traceback (most recent call last):
File “/home/langfords/.ansible/tmp/ansible-1381245971.29-257994512790004/ec2”, line 1549, in
main()
File “/home/langfords/.ansible/tmp/ansible-1381245971.29-257994512790004/ec2”, line 612, in main
(instance_dict_array, new_instance_ids, changed) = create_instances(module, ec2)
File “/home/langfords/.ansible/tmp/ansible-1381245971.29-257994512790004/ec2”, line 437, in create_instances
res = ec2.run_instances(**params)
TypeError: run_instances() got an unexpected keyword argument ‘instance_profile_name’

FATAL: all hosts have already failed – aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/langfords/ansible-ec2.yaml.retry

localhost : ok=0 changed=0 unreachable=0 failed=1

langfords@langfords4:~/Dropbox/work/clouddeploy$ cat /usr/share/ansible/cloud/ec2 | grep instance_profile_name
instance_profile_name:
instance_profile_name = module.params.get(‘instance_profile_name’)
‘instance_profile_name’: instance_profile_name}
instance_profile_name = dict(),

I got a hold of the 1.3.2 source and ran a diff between the two ec2 modules and get no diffs…

Is there anywhere else I can look to see what might be going on here? I don’t know python, so it’s hard for me to diagnose.

What version of boto do you have installed? This actually appears to be an issue where that parameter is being sent into the boto function run_instances(), but boto says it’s an invalid parameter name (it was introduced in boto 2.5.0).

Right. I have boto 2.2.2, frustrating that the ansible deb didn’t flag this. Seems to be non-trivial to get an ubuntu PPA for 12.04 which has >=2.5.0. Will find a way to get it on there and try again.

Thanks v much for you help.

Simon

Yup, that worked great. Installed with pip and now it runs. Except…

msg: InvalidGroup.NotFound: The security group ‘sg-1edd3571’ does not exist in default VPC ‘vpc-a86e25c3’

I’ve double checked and that security group is most definitely assigned to that VPC, which is the default VPC, which raises 2 questions:

  • Does ansible support VPC?

  • And because I’m about to stop using my default VPC, does it support a non-default VPC?

Thanks
Simon

The answer to both is yes, you should be able to specify the VPC with vpc_subnet_id. Do VPCs span regions in AWS? I’m a little bit ignorant of that detail myself, so it could be that the VPC you’ve defined isn’t in eu-west-1.

They don’t AFAIK, but it’s defo in eu-west-1. I hadn’t seen the vpc_subnet_id. When I went and checked the doco I realised i was putting a group_id into the group parameter. Sorted that out and it works.

Thanks for you help, I can delve a little further now.