instance_profile_name=administrator
register: ec2
- debug: var=ec2
- name: Add new instance to host group
local_action: add_host hostname={{ item.public_ip }} groupname=launched
with_items: ec2.instances
local_action: ec2_eip instance_id={{
item.id }} ip=54.123.243.14 region=us-east-1
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
creates this output
PLAY [launch ec2 instances] ***************************************************
GATHERING FACTS ***************************************************************
<localhost> REMOTE_MODULE setup
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397679399.75-124658801788316 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397679399.75-124658801788316 && echo $HOME/.ansible/tmp/ansible-tmp-1397679399.75-124658801788316']
<localhost> PUT /tmp/tmproj7br TO /home/allan/.ansible/tmp/ansible-tmp-1397679399.75-124658801788316/setup
<localhost> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=txkrcippgjwejawnsvmxfmioikhjbnmo] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-txkrcippgjwejawnsvmxfmioikhjbnmo; /usr/bin/python /home/allan/.ansible/tmp/ansible-tmp-1397679399.75-124658801788316/setup; rm -rf /home/allan/.ansible/tmp/ansible-tmp-1397679399.75-124658801788316/ >/dev/null 2>&1'"'"''
ok: [localhost]
TASK: [ec2 | Launch instance] *************************************************
<127.0.0.1> REMOTE_MODULE ec2 keypair=test-keypair instance_type=m1.small image=ami-2f252646 region=us-east-1 aws_access_key=AKIAJU2B4ETWTLDSFRTA aws_secret_key=afdsnndsk3k3skdnlsdfdsdsf8s83lsdfs9sl20a group=default wait=true instance_profile_name=administrator
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397679401.41-186628483289086 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397679401.41-186628483289086 && echo $HOME/.ansible/tmp/ansible-tmp-1397679401.41-186628483289086']
<127.0.0.1> PUT /tmp/tmpTtwbgP TO /home/allan/.ansible/tmp/ansible-tmp-1397679401.41-186628483289086/ec2
<127.0.0.1> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=afdsjflkjsdlkjaflkjsdlkfjlsdkjflk] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-afdsjflkjsdlkjaflkjsdlkfjlsdkjflk; /usr/bin/python /home/allan/.ansible/tmp/ansible-tmp-1397679401.41-186628483289086/ec2; rm -rf /home/allan/.ansible/tmp/ansible-tmp-1397679401.41-186628483289086/ >/dev/null 2>&1'"'"''
changed: [localhost] => {"changed": true, "instance_ids": ["i-7a475a2b"], "instances": [{"ami_launch_index": "0", "architecture": "x86_64", "dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "ebs_optimized": false, "hypervisor": "xen", "id": "i-7a475a2b", "image_id": "ami-2f252646", "instance_type": "m1.small", "kernel": "aki-919dcaf8", "key_name": "test-keypair", "launch_time": "2014-04-16T20:16:42.000Z", "placement": "us-east-1b", "private_dns_name": "ip-10-151-25-101.ec2.internal", "private_ip": "10.151.25.101", "public_dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "public_ip": "23.20.49.142", "ramdisk": null, "region": "us-east-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "virtualization_type": "paravirtual"}], "item": "", "tagged_instances": []}
TASK: [ec2 | debug var=ec2] ***************************************************
ok: [localhost] => {
"ec2": {
"changed": true,
"instance_ids": [
"i-7a475a2b"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"ebs_optimized": false,
"hypervisor": "xen",
"id": "i-7a475a2b",
"image_id": "ami-2f252646",
"instance_type": "m1.small",
"kernel": "aki-919dcaf8",
"key_name": "test-keypair",
"launch_time": "2014-04-16T20:16:42.000Z",
"placement": "us-east-1b",
"private_dns_name": "ip-10-151-25-101.ec2.internal",
"private_ip": "10.151.25.101",
"public_ip": "23.20.49.142",
"ramdisk": null,
"region": "us-east-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"virtualization_type": "paravirtual"
}
],
"invocation": {
"module_args": "keypair=test-keypair instance_type=m1.small image=ami-2f252646 region=us-east-1 aws_access_key=AKIAJU2B4ETWTLDSFRTA aws_secret_key=afdsnndsk3k3skdnlsdfdsdsf8s83lsdfs9sl20a group=default wait=true instance_profile_name=administrator",
"module_name": "ec2"
},
"item": "",
"tagged_instances": []
},
"item": ""
}
TASK: [ec2 | Add new instance to host group] **********************************
creating host via 'add_host': hostname=23.20.49.142
added host to group via add_host module: launched
ok: [localhost] => (item={u'kernel': u'aki-919dcaf8', u'root_device_type': u'ebs', u'private_dns_name': u'ip-10-151-25-101.ec2.internal', u'public_ip': u'23.20.49.142', u'private_ip': u'10.151.25.101', u'id': u'i-7a475a2b', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'paravirtual', u'architecture': u'x86_64', u'ramdisk': None, u'key_name': u'test-keypair', u'image_id': u'ami-2f252646', u'public_dns_name': u'
ec2-23-20-49-142.compute-1.amazonaws.com', u'state_code': 16, u'placement': u'us-east-1b', u'ami_launch_index': u'0', u'dns_name': u'
ec2-23-20-49-142.compute-1.amazonaws.com', u'region': u'us-east-1', u'launch_time': u'2014-04-16T20:16:42.000Z', u'instance_type': u'm1.small', u'root_device_name': u'/dev/sda1', u'hypervisor': u'xen'}) => {"item": {"ami_launch_index": "0", "architecture": "x86_64", "dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "ebs_optimized": false, "hypervisor": "xen", "id": "i-7a475a2b", "image_id": "ami-2f252646", "instance_type": "m1.small", "kernel": "aki-919dcaf8", "key_name": "test-keypair", "launch_time": "2014-04-16T20:16:42.000Z", "placement": "us-east-1b", "private_dns_name": "ip-10-151-25-101.ec2.internal", "private_ip": "10.151.25.101", "public_dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "public_ip": "23.20.49.142", "ramdisk": null, "region": "us-east-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "virtualization_type": "paravirtual"}, "new_groups": ["launched"], "new_host": "23.20.49.142"}
<127.0.0.1> REMOTE_MODULE ec2_eip instance_id=i-7a475a2b ip=54.123.243.14 region=us-east-1
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397679468.91-9339569617426 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397679468.91-9339569617426 && echo $HOME/.ansible/tmp/ansible-tmp-1397679468.91-9339569617426']
<127.0.0.1> PUT /tmp/tmp_qUFea TO /home/allan/.ansible/tmp/ansible-tmp-1397679468.91-9339569617426/ec2_eip
<127.0.0.1> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=lbyxmaiyzbgobzdfcrdctyrfucjusbxz] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-lbyxmaiyzbgobzdfcrdctyrfucjusbxz; /usr/bin/python /home/allan/.ansible/tmp/ansible-tmp-1397679468.91-9339569617426/ec2_eip; rm -rf /home/allan/.ansible/tmp/ansible-tmp-1397679468.91-9339569617426/ >/dev/null 2>&1'"'"''
changed: [localhost] => (item={u'kernel': u'aki-919dcaf8', u'root_device_type': u'ebs', u'private_dns_name': u'ip-10-151-25-101.ec2.internal', u'public_ip': u'23.20.49.142', u'private_ip': u'10.151.25.101', u'id': u'i-7a475a2b', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'paravirtual', u'architecture': u'x86_64', u'ramdisk': None, u'key_name': u'test-keypair', u'image_id': u'ami-2f252646', u'public_dns_name': u'
ec2-23-20-49-142.compute-1.amazonaws.com', u'state_code': 16, u'placement': u'us-east-1b', u'ami_launch_index': u'0', u'dns_name': u'
ec2-23-20-49-142.compute-1.amazonaws.com', u'region': u'us-east-1', u'launch_time': u'2014-04-16T20:16:42.000Z', u'instance_type': u'm1.small', u'root_device_name': u'/dev/sda1', u'hypervisor': u'xen'}) => {"changed": true, "item": {"ami_launch_index": "0", "architecture": "x86_64", "dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "ebs_optimized": false, "hypervisor": "xen", "id": "i-7a475a2b", "image_id": "ami-2f252646", "instance_type": "m1.small", "kernel": "aki-919dcaf8", "key_name": "test-keypair", "launch_time": "2014-04-16T20:16:42.000Z", "placement": "us-east-1b", "private_dns_name": "ip-10-151-25-101.ec2.internal", "private_ip": "10.151.25.101", "public_dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "public_ip": "23.20.49.142", "ramdisk": null, "region": "us-east-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "virtualization_type": "paravirtual"}, "public_ip": "54.123.243.14"}
TASK: [ec2 | Wait for SSH to come up] *****************************************
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397679470.36-9702616306379 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397679470.36-9702616306379 && echo $HOME/.ansible/tmp/ansible-tmp-1397679470.36-9702616306379']
<127.0.0.1> PUT /tmp/tmpWXZPDN TO /home/allan/.ansible/tmp/ansible-tmp-1397679470.36-9702616306379/wait_for
<127.0.0.1> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=abylrhowihoeqeyaonyrfglectqbfvin] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-abylrhowihoeqeyaonyrfglectqbfvin; /usr/bin/python /home/allan/.ansible/tmp/ansible-tmp-1397679470.36-9702616306379/wait_for; rm -rf /home/allan/.ansible/tmp/ansible-tmp-1397679470.36-9702616306379/ >/dev/null 2>&1'"'"''
ok: [localhost] => (item={u'kernel': u'aki-919dcaf8', u'root_device_type': u'ebs', u'private_dns_name': u'ip-10-151-25-101.ec2.internal', u'public_ip': u'23.20.49.142', u'private_ip': u'10.151.25.101', u'id': u'i-7a475a2b', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'paravirtual', u'architecture': u'x86_64', u'ramdisk': None, u'key_name': u'test-keypair', u'image_id': u'ami-2f252646', u'public_dns_name': u'
ec2-23-20-49-142.compute-1.amazonaws.com', u'state_code': 16, u'placement': u'us-east-1b', u'ami_launch_index': u'0', u'dns_name': u'
ec2-23-20-49-142.compute-1.amazonaws.com', u'region': u'us-east-1', u'launch_time': u'2014-04-16T20:16:42.000Z', u'instance_type': u'm1.small', u'root_device_name': u'/dev/sda1', u'hypervisor': u'xen'}) => {"changed": false, "elapsed": 69, "item": {"ami_launch_index": "0", "architecture": "x86_64", "dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "ebs_optimized": false, "hypervisor": "xen", "id": "i-7a475a2b", "image_id": "ami-2f252646", "instance_type": "m1.small", "kernel": "aki-919dcaf8", "key_name": "test-keypair", "launch_time": "2014-04-16T20:16:42.000Z", "placement": "us-east-1b", "private_dns_name": "ip-10-151-25-101.ec2.internal", "private_ip": "10.151.25.101", "public_dns_name": "
ec2-23-20-49-142.compute-1.amazonaws.com", "public_ip": "23.20.49.142", "ramdisk": null, "region": "us-east-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "virtualization_type": "paravirtual"}, "path": null, "port": 22, "search_regex": null, "state": "started"}
PLAY [provision ec2 instances] ************************************************
GATHERING FACTS ***************************************************************
<23.20.49.142> ESTABLISH CONNECTION FOR USER: ubuntu
<23.20.49.142> REMOTE_MODULE setup
<23.20.49.142> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/allan/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 'IdentityFile=/home/allan/test-keypair', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', u'23.20.49.142', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397679539.75-193322722126767 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397679539.75-193322722126767 && echo $HOME/.ansible/tmp/ansible-tmp-1397679539.75-193322722126767'"]
fatal: [23.20.49.142] => SSH encountered an unknown error. The output was:
OpenSSH_6.6, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/home/allan/.ansible/cp/ansible-ssh-23.20.49.142-22-ubuntu" does not exist
debug2: ssh_connect: needpriv 0
debug1: Connecting to 23.20.49.142 [23.20.49.142] port 22.
debug2: fd 3 setting O_NONBLOCK
debug1: connect to address 23.20.49.142 port 22: Connection timed out
ssh: connect to host 23.20.49.142 port 22: Connection timed out
which makes sense, since I changed the public name right before trying to ssh into it
- 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
If I try
- name: Wait for SSH to come up
local_action: wait_for host={{ item.private_ip_address }} port=22
delay=60 timeout=320 state=started
with_items: ec2.instances
I get
TASK: [ec2 | Wait for SSH to come up] *****************************************
fatal: [localhost] => One or more undefined variables: 'dict object' has no attribute 'private_ip_address'
FATAL: all hosts have already failed -- aborting
I tried moving the ec2_eip statement to the end of the playbook, and it bombs out