Hi,

I rant into the same issue today.  That is that the ec2.py plugin only 
shows details of running instances.  To get around it I used the Boto 
provided list_instances command.  Here's my playbook.



---
- name: Start Front instance and associate EIP
  hosts: local
  connection: local
  gather_facts: False

  vars:
    - ec2_secret_key: XXXXXXX
    - ec2_access_key: XXXXXXX

  tasks:
    - name: Get instance id
      local_action:
        module: shell /python/ansible/bin/list_instances -r ap-southeast-2 
-H ID,T:Name -t | grep Front | awk '{print $1}'
      register: instance_id

    - name: Display instance id
      debug: msg="Instance id = {{ instance_id.stdout }}"

    - name: Start instance
      local_action:
        module: ec2
        ec2_secret_key: "{{ ec2_secret_key }}"
        ec2_access_key: "{{ ec2_access_key }}"
        region: ap-southeast-2
        state: running
        instance_ids: "{{ instance_id.stdout }}"
        wait: yes

    - name: Associate EIP to instance      
      local_action:
        module: ec2_eip
        ec2_secret_key: "{{ ec2_secret_key }}"
        ec2_access_key: "{{ ec2_access_key }}"
        region: ap-southeast-2
        instance_id: "{{ instance_id.stdout }}"
        ip: X.X.X.X

Hope it helps.

Des


On Tuesday, 11 March 2014 08:21:32 UTC+11, [email protected] wrote:
>
>   Sorry, 
> "Unfortunately, shutdown didn't work..." 
>   should read 
> "Unfortunately, starting 'stopped' instances didn't work...".
>
>
>
>
> On Monday, March 10, 2014 2:19:54 PM UTC-7, [email protected] wrote:
>>
>>   Ah, thank you very much, this indeed allowed me to shut down all 
>> instances in an environment (code pasted below if anyone ever needs to 
>> google this).  Unfortunately, shutdown didn't work because ec2.py doesn't 
>> seem to list stopped instances (even after --refresh-cache).
>>
>>   Thank you both.
>>
>>
>> -------------------------------- sample below
>> ---
>> - hosts: localhost
>>   gather_facts: false
>>   connection: local
>>   tasks:
>>     - name: Stop the instances for pod '{{pod}}'
>>       local_action:
>>         module: ec2
>>         instance_ids: "{{hostvars[item]['ec2_id']}}"
>>         state: stopped
>>         region: 'us-west-1'
>>         wait: false
>>       with_items:  "groups.tag_env_{{pod}}"
>> --------------------------------- sample end
>>
>>
>> On Monday, March 10, 2014 10:46:15 AM UTC-7, Michael DeHaan wrote:
>>>
>>>
>>>
>>> On Mon, Mar 10, 2014 at 1:22 PM, <[email protected]> wrote:
>>>
>>>>   Just trying to understand: what is your proposed solution for, say 
>>>> 'starting all EC2 VMs that match tag_env_prod in zone US-WEST-1'?
>>>>
>>>
>>> You can iterate over hosts and check states like so:
>>>
>>> -  hosts: localhost
>>>    tasks:
>>>
>>>        - shell: blah
>>>          when: hostvars[item][ec2_state] == blah and item in 
>>> hostvars[item]['ec2_region'] == blah
>>>          with_items:  groups.tag_env_prod
>>>
>>>
>>> The region should also be available as a group:
>>>
>>> when: item in groups.foo
>>>
>>> etc
>>>
>>>
>>>

-- 
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/3932ce74-c905-4d38-859c-f197df0a1585%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to