This is a great tip! Seems to be working as expected now,

Thank you

On Wednesday, December 10, 2014 9:43:19 AM UTC-6, Matt Martz wrote:
>
> So roles are evaluated after the top level portions of the play.
>
> I would do something such as using add_host to add deleted servers to an 
> in memory group that you could use for exclusion later.  Such as something 
> like:
>
> - hosts: local
>   gather_facts: False
>   tasks:
>     - name: Create or delete servers
>       rax:
>           [module stuff here that deletes servers]
>           group: webservers
>       register: rax_results
>
>     - name: Add created servers to webservers group
>       add_host:
>           hostname: "{{ item.name }}"
>           ansible_ssh_host: "{{ item.rax_accessipv4 }}"
>           ansible_ssh_pass: "{{ item.rax_adminpass }}"
>           groups: webservers
>       with_items: rax_results.success
>       when: rax_results.action == 'create'
>
>     - name: Add deleted servers to deleted group for later exclusions
>       add_host:
>           hostname: "{{ item.name }}"
>           groups: deleted
>       with_items: rax_results.success
>       when: rax_results.action == 'delete'
>
> - hosts: webservers!deleted
>   [other stuff here]
>
>
>
>
>
>
> On Wed, Dec 10, 2014 at 9:13 AM, phil toohill <[email protected] 
> <javascript:>> wrote:
>
>> ##### Issue Type:
>> Bug Report
>>
>> ##### Ansible Version:
>> 1.8.2
>>
>> ##### Environment:
>> OSX 10.8.5
>>
>> ##### Summary:
>> Fact gathering fails when cloud module deletes server and roles play is 
>> called with a when conditional.
>>
>> ##### Steps To Reproduce:
>>
>> Assuming utilization of a cloud module such as 'rax', you can set the 
>> count to 0 to remove the servers and then call out to roles, as such:
>> ```
>> - name: Build an exact count of cloud servers with incremented names
>>   hosts: local
>>   gather_facts: False
>>   tasks:
>>     - name: Server build requests
>>       local_action:
>>         module: rax
>>         credentials: ~/.raxpub
>>         name: test%03d.example.org
>>         flavor: performance1-1
>>         image: ubuntu-1204-lts-precise-pangolin
>>         state: present
>>         count: 0
>>         exact_count: yes
>>         group: webservers
>>         wait: yes
>>       register: rax
>>
>> - name: Setup nginx
>>   user: root
>>   hosts: webservers
>>   vars:
>>    operation: "{{ wsoperation }}"
>>   roles:
>>     - { role: nginx, when: operation == 'create' }
>> ```
>> ##### Expected Results:
>>
>> It would expected that the when clause should trigger prior/during the 
>> gather facts call thus adhering to the conditional and passing tests.
>>
>> I call this a bug because I assume no operations should happen for a play 
>> unless the conditional is met, this includes fact gathering. 
>>
>> Besides having a separate playbook with duplicated server logic, which 
>> defeats the purpose of this modules benefits, I do not see a proper work 
>> around. 
>>
>> ##### Actual Results:
>> Gather facts is triggered before the when operation is analyzed causing 
>> failure.
>> ```
>> fatal: [webser-backend01] => SSH encountered an unknown error during the 
>> connection
>> ```
>>
>>
>> This was closed as 'not a bug', anyone have suggested work around?
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/c7c00708-ffbb-45b0-ae7c-57ab35b8632a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/c7c00708-ffbb-45b0-ae7c-57ab35b8632a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>  

-- 
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/4e0b3026-3f4b-4c9e-a55a-eb76fa58c566%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to