If gather_facts is false and node is unreachable, how are you going to 
retrieve hostvars[item]['ec2_id'] ? Is it statically declared in your 
inventory file? 

On Thursday, September 27, 2018 at 10:29:17 AM UTC-5, John Peters wrote:
>
> Any clue as to how to accomplish this?
>
> My Ansible Tower inventory has a list of hosts in it, all in 'stopped' 
> state.
>
> I'd like to use that inventory, assign it to a playbook, that will loop 
> through each machine in the inventory, from the *localhost*, and issue a 
> command to start the instance to AWS.
>
> I've tried several different ways to do this, but to no avail.
>
> It seems that because I'm specifying an inventory to the job, and that 
> inventory only has stopped instances in it, there's no way to execute a 
> task on the localhost, loop through that inventory, and start them, one by 
> one?
>
> Here is some code that contains all the different lines I've tried...
>
> ---
> - name: Start EC2 Instances
>   hosts: localhost # also tried 'all' here
>   connection: local
>   gather_facts: false
>   tasks:
>     - name: inventory_hostname var
>       debug:
>         msg: "{{ hostvars[inventory_hostname] }}"
>       with_inventory_hostnames: all
>       delegate_to: localhost
>
>     - name: hostvars item
>       debug:
>         msg: "{{ hostvars[item] }}"
>       with_inventory_hostnames: all
>       delegate_to: localhost
>
>    - name: Start EC2 Instances Task
>      ec2_instance: running
>       local_action:
>         module: ec2
>           instance_ids={{hostvars[inventory_hostname]['ec2_id']}}
>           region="{{ region | default('us-east-1') }}"
>           state=running
>      when: hostvars[item]['ec2_id'] is defined
>      with_inventory_hostnames: all
>      delegate_to: localhost
>
>
>

-- 
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/8d87e5e9-d0f7-4a06-b974-fcf7fd56f5e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to