Perhaps I'm not completely following the question:
" I am able to capture the elastic IP via register but how do I call it
from the role?"
Basically any variable already registered can be used like "{{ foo }}" in
subsequent roles/tasks/whatever -- so maybe you could help me understand
where the point of confusion is?
Want to help, just a bit unclear on it. Thanks!
On Wed, Dec 10, 2014 at 3:18 PM, <[email protected]> wrote:
>
> Quick correction on this. I pasted the wrong data where it says "name:
> allocate a new elastic IP without associating it to anything" The play
> actually looks like this:
>
> - name: Associate a new Elastic IP to instance
> ec2_eip: region=us-east-1 in_vpc=yes "instance_id={{ item }}"
> with_items: ec2.instance_ids
> register: eiptest
>
> On Wednesday, December 10, 2014 2:11:41 PM UTC-6, [email protected] wrote:
>>
>> I am launching one-off ec2 instance for development purposes and in the
>> main playbook I am launching an EC2 instance then assigning an elastic IP.
>> Once all of that is done I am configuring the server via a role. I am able
>> to capture the elastic IP via register but how do I call it from the role?
>> Or more specifically how can I call it in a configuration template from
>> within the role that is applied?
>>
>> Here's an example:
>>
>> launch-server.yml:
>>
>> - name: Launch ec2 instance
>> hosts: localhost
>> gather_facts: False
>> vars:
>> key_name: ssh-key
>> instance_type: t2.medium
>> group_id: sg-f834234
>> image: ami-b234234
>> region: us-east-1
>> vpc_subnet_id: subnet-65wer234
>> tasks:
>>
>> - name: Launch instance
>> local_action: ec2 key_name={{ key_name }} group_id={{ group_id }}
>> instance_type={{ instance_type }} image={{ image }} wait=true region={{
>> region }} vpc_subnet_id={{ vpc_subnet_id }} instance_tags='{"Name":"ec2-
>> instance"}'
>> register: ec2
>>
>> - name: allocate a new elastic IP without associating it to anything
>> action: ec2_eip region=us-east-1
>> register: eiptest
>>
>> - name: output the IP
>> debug: msg="Allocated IP is {{ eiptest.public_ip }}" <--- this
>> prints the elastic IP to the screen.
>>
>> - name: Add new instance to host group
>> local_action: add_host hostname={{ item.private_ip }}
>> groupname=launched
>> with_items: ec2.instances
>>
>> - name: Wait for SSH to come up
>> local_action: wait_for host={{ item.private_ip }} port=22 delay=60
>> timeout=320 state=started
>> with_items: ec2.instances
>>
>> - name: Configure instance
>> hosts: launched
>> sudo: True
>> gather_facts: True
>> roles:
>> - myrole
>>
>> In the template from within the role it doesn't know about
>> eiptest.public_ip so it fails and reading the docs it seems that var will
>> be destroyed at the end of the play that calls the role. If I run ansible
>> hostname -m setup I don't see any entries for the elastic IP assigned to
>> the instance.
>>
>> I've tried a number of things and read through the docs but not having
>> much luck. I would like to keep the roles separate from the plays that
>> launch the instances if at all possible.
>>
>> Thanks!
>>
> --
> 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/6613e7b0-3be9-40f1-9eb9-4fbe685297ea%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6613e7b0-3be9-40f1-9eb9-4fbe685297ea%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CA%2BnsWgxH_VcJYzw47Q6c%2BwD_5if7JnbKa1oqTLe6v%2B1EcYxDbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.