I would tag the instances in your CF template, then reference those tagged 
hosts by the inventory groups that are created with the ec2.py dynamic 
inventory script.  If you do this in two separate ansible-playbook runs, 
you won't need to do anything special, the inventory will reflect the newly 
tagged instances. If you are doing this within the same play or playbook, 
you'll need to update the inventory in memory, you can do that  (in Ansible 
2.0) with:

- meta: refresh_inventory


On Monday, December 7, 2015 at 11:15:02 AM UTC-5, Juris wrote:
>
> Hi,
>
> I am having hard time figuring out idiomatic way of doing AWS 
> infrastructure deployment and application e.g. EC2 instance provisioning in 
> one go in same playbook. The problem being accessing EC2 host in the next 
> play after AWS infrastructure creation. The example playbook is as follows:
>
> ---
> - name: Deploy cloud infrastructure
>   hosts: localhost
>   connection: local
>   gather_facts: False
>   vars:
>     aws_region: "us-east-1"
>     ssh_key_name: "MyAwsKey"
>     stack_name: "test-stack"
>
>   tasks:
>     - name: Create a sample stack
>       cloudformation:
>         stack_name: "{{ stack_name }}"
>         state: "present"
>         region: "us-east-1"
>         disable_rollback: true
>         template: "files/simple.template"
>         template_parameters:
>           KeyName: "{{ ssh_key_name }}"
>       register: cf
>
>     - name: Output EC2 IP
>       debug: var=cf.stack_outputs.PublicIP
>
> # Try to install something to EC2
> - name: Provision application
>   hosts: "{{ hostvars.localhost.cf.stack_outputs.PublicIP }}"
>   remote_user: "ubuntu"
>   sudo: yes
>
>   tasks:
>     - name: Just a test command
>       command: uptime
>       register: out
>     - debug: var=out.stdout
>
> And output:
>
> ok: [localhost] => {
>     "var": {
>         "cf.stack_outputs.PublicIP": "XXX.XXX.XXX.XXX"
>     }
> }
>
> PLAY [Provision application] 
> **************************************************
> skipping: no hosts matched
>
>
> My naive assumption was that consecutive play "Provision application" 
> would reference EC2 instance with hosts directive via registered variable 
> e.g. hostvars.localhost.cf.stack_outputs.PublicIP which apparently does 
> not work like I imagined.
>
> So, the question is - what is the right way to approach this problem? I 
> bet I am missing something. I would prefer just one playbook that does both 
> cloud infrastructure deployment and server/application provisioning.
>
> Thanks!
> Juris
>
>

-- 
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/a0b68fee-3173-4d37-85a4-a67f88e11a3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to