You can use the returned data from cloudformation to call add_host
<http://docs.ansible.com/ansible/add_host_module.html>, then start a new
play that targets that host, or set up an EC2 dynamic inventory script that
will pick up the host(s) you're creating and conditionally call meta:
inventory_refresh when you know an instance got created (then do the same
thing: start another play that touches the right host(s)). I personally
prefer the add_host approach as it's more definitive that you're touching
exactly the right host, but potato, potahto...
-Matt
On Thursday, August 25, 2016 at 7:59:50 PM UTC-7, Michael Ludvig wrote:
>
> Hi there
>
> I've got a play that creates an AWS EC2 instance through a CloudFormation
> template. After it's created I would like to configure it - I can use the
> AWS tools to do that but I prefer to use Ansible to be consistent with our
> other deployments.
>
> What I have now is:
>
> ---
> - name: Create Amazon Linux Instance
> hosts: localhost
> connection: local
> gather_facts: no
> vars_files:
> - config.yml
>
> tasks:
> - name: Create CloudFormation Stack
> cloudformation:
> stack_name: "{{ stack_name }}"
> state: present
> template: basic-ec2-stack.json
> template_parameters:
> KeyName: "{{ key_name }}"
> VpcId: "{{ vpc_id }}"
> SubnetId: "{{ subnet_id }}"
> ...
> register: stack
>
> # The new instance name is in stack.stack_outputs.DnsName ...
> - debug: var=stack.stack_outputs.DnsName
>
>
> Now what? How can I run the rest of the playbook against the newly created
> host?
> For example I would like to create user 'blah' but not on the localhost
> (against which the cloudformation module is running) but obviously on the
> EC2 instence. How do I do that?
>
> Thanks!
>
> Michael
>
>
>
--
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/9f020130-988a-474c-90a1-49c4bf10b951%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.