Need assist with syntax for EC2 assignment of Elastic IP Address

1,916 views
Skip to first unread message

mark david mcCreary

unread,
Apr 15, 2014, 5:52:20 PM4/15/14
to ansible...@googlegroups.com
I want to finish off an Ansible playbook by assigning a static IP address to it.  I want to do this at the end, because I think it takes a few minutes to take effect.  Not sure if doing it at the beginning would cause Ansible to loose the connection or not.

I launch an instance like this

- name: Launch instance
  local_action: ec2 keypair={{ keypair }}  instance_type={{ instance_type }} 
                image={{ image }} region={{ region }} 
                aws_access_key={{ aws_access_key }} 
                aws_secret_key={{ aws_secret_key }} 
                group={{ security_group }} wait=true   
  register: ec2


I've tried a couple of different ways, both fail.

- name: associate testing.example.com with this instance
  local_action: ec2_eip instance_id={{ item.id }} ip=54.243.243.102 region=us-east-1
  with_items: ec2.instances

 TASK: [missing | associate testing.example.com with this instance] ****** 
 fatal: [54.198.204.2] => One or more undefined variables: 'str object' has no attribute 'id'



- name: associate testing.example.com with this instance
  local_action: ec2_eip instance_id={{ ec2.instance_ids[0] }} ip=54.243.243.102 region=us-east-1

 TASK: [missing | associate testing.example.com with this instance] ****** 
 fatal: [54.197.175.124] => One or more undefined variables: 'ec2' is undefined


Can somebody show me the correct syntax.

Thanks

mark

Michael DeHaan

unread,
Apr 15, 2014, 6:39:45 PM4/15/14
to ansible...@googlegroups.com
First run with the "-v" flag and see what the returns from the ec2 module looks like, which will help with testing how to use the resultant data.



--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/06f1b7e2-2bc3-49be-9649-aaa9769194b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mark david mcCreary

unread,
Apr 16, 2014, 5:42:29 PM4/16/14
to ansible...@googlegroups.com
My playbook looks like this

---

- name: launch ec2 instances 
  hosts: localhost 
  sudo: True

  roles:
    - ec2

- name: provision ec2 instances
  hosts: launched
  remote_user: ubuntu
  sudo: True
  vars:
    - ansible_ssh_private_key_file: /home/allan/test-keypair

  roles:
    - common
    - awscli
    - debconf
    - conffiles



and the ec2 module looks like this


- name: Launch instance
  local_action: ec2 keypair={{ keypair }}  instance_type={{ instance_type }} 
                image={{ image }} region={{ region }} 
                aws_access_key={{ aws_access_key }} 
                aws_secret_key={{ aws_secret_key }} 
                group={{ security_group }} wait=true   
                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

- name: associate test.example.com with this instance
  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", 
                "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"
            }
        ], 
        "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"}

TASK: [ec2 | associate test.example.com with this instance] ********** 
<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> REMOTE_MODULE wait_for host=ec2-23-20-49-142.compute-1.amazonaws.com port=22 delay=60 timeout=320 state=started
<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

TASK: [missing | associate testing.example.com with this instance] ****** 
 fatal: [54.198.204.2] => One or more undefined variables: 'str object' has no attribute 'id'


I'm thinking the ec2 variable must be accessed only from the ec2 role.

Any suggestions on how to attach an Elastic IP address to a newly created instance ?

Thanks

mark

mark david mcCreary

unread,
Apr 16, 2014, 6:11:53 PM4/16/14
to ansible...@googlegroups.com
If I reverse the order, like this

- 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
  
- name: associate test.example.com with this instance
  local_action: ec2_eip instance_id={{ item.id }} ip=54.123.243.14 region=us-east-1
  with_items: ec2.instances



it gets through those ok, but hangs in the middle of the next stanza.

So assigning an Elastic IP address disturbs the environment.

mark

Dan Vaida

unread,
Jun 23, 2014, 5:20:28 AM6/23/14
to ansible...@googlegroups.com
Hi Mark.

This is the typical outcome of AWS' flow. When you assign an EIP to an instance, you can forget about the public dns and public ip entries. they are updated according to the EIP.
As a tip, I am registering the output of the ec2_eip module and use that instead of querying the ec2 module's results. One can also (supposedly) use the ec2_facts module or just output the added EIP to a file with the lineinfile module and read it from there or use the in-memory inventory with add_host.

FYI, here's what ec2_facts gets:
[dvaida@scat ansible-aws]$ ansible -i host all --user=admin --private-key=ansible-ec2.pem -m ec2_facts
The authenticity of host '54.76.235.184 (54.76.235.184)' can't be established.
ECDSA key fingerprint is ec:11:61:76:a0:28:b5:83:10:a7:3c:b5:d8:02:71:bb.
Are you sure you want to continue connecting (yes/no)? yes
54.76.235.184 | success >> {
    "ansible_facts": {
        "ansible_ec2_ami_id": "ami-630fcb14",
        "ansible_ec2_ami_launch_index": "0",
        "ansible_ec2_ami_manifest_path": "(unknown)",
        "ansible_ec2_block_device_mapping_ami": "/dev/sda",
        "ansible_ec2_block_device_mapping_root": "/dev/sda",
        "ansible_ec2_hostname": "ip-10-0-0-8.eu-west-1.compute.internal",
        "ansible_ec2_instance_action": "none",
        "ansible_ec2_instance_id": "i-9edd71dd",
        "ansible_ec2_instance_type": "c3.2xlarge",
        "ansible_ec2_kernel_id": "aki-52a34525",
        "ansible_ec2_local_hostname": "ip-10-0-0-8.eu-west-1.compute.internal",
        "ansible_ec2_local_ipv4": "10.0.0.8",
        "ansible_ec2_mac": "06:31:2e:4a:82:e2",
        "ansible_ec2_metrics_vhostmd": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_device_number": "0",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_interface_id": "eni-4fb93f38",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_ipv4_associations_54.76.235.184": "10.0.0.8",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_local_hostname": "ip-10-0-0-8.eu-west-1.compute.internal",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_local_ipv4s": "10.0.0.8",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_mac": "06:31:2e:4a:82:e2",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_owner_id": "785351690827",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_public_hostname": "ec2-54-76-235-184.eu-west-1.compute.amazonaws.com",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_public_ipv4s": "54.76.235.184",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_security_group_ids": "sg-0b10de6e",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_security_groups": "allinone",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_subnet_id": "subnet-ddca27aa",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_subnet_ipv4_cidr_block": "10.0.0.0/24",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_vpc_id": "vpc-9037d9f5",
        "ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_vpc_ipv4_cidr_block": "10.0.0.0/16",
        "ansible_ec2_placement_availability_zone": "eu-west-1a",
        "ansible_ec2_placement_region": "eu-west-1",
        "ansible_ec2_profile": "default-paravirtual",
        "ansible_ec2_public_hostname": "ec2-54-76-235-184.eu-west-1.compute.amazonaws.com",
        "ansible_ec2_public_ipv4": "54.76.235.184",
        "ansible_ec2_public_key": "ssh-rsa XXX
ansible-ec2\n",
        "ansible_ec2_reservation_id": "r-a5fe14e6",
        "ansible_ec2_security_groups": "allinone",
        "ansible_ec2_services_domain": "amazonaws.com",
        "ansible_ec2_user_data": null
    },
    "changed": false
}
I believe this module should get better documentation.
Hope this helps you!

Arbab Nazar

unread,
Jan 16, 2015, 12:51:50 AM1/16/15
to ansible...@googlegroups.com
Dan is absolutely right, here is an example what he is saying. Thanks

- name:  Associate new EIP to the NAT Instance
   local_action:
     module: ec2_eip
     region: "{{ vpc_region }}"
     instance_id: "{{ item.id }}"
   with_items: ec2.results.instances
   register: eip

 - name:  Add the newly created EC2 instance(s) to the local host group
   local_action: lineinfile
                 dest="./hosts"
                 regexp="{{ eip.results.public_ip }}"
                 insertafter="[nat]"
Reply all
Reply to author
Forward
0 new messages