I've found a working solution, it's ugly and probably will cause more 
headache but it works.

My solution looks like this:

---
- hosts: localhost
  ignore_errors: true
#  gather_facts: true

  tasks:
   - shell: ansible-playbook wu.yml
     register: results
     until: "'\"found_update_count\": 0' in results.stdout"
         retries: 5


wu.yml:

---
- hosts: bunch_of_hosts
  ignore_errors: true
  #gather_facts: true

  tasks:
    - block:
        - name: search wu
          win_updates:
            category_names:
              - CriticalUpdates
              - SecurityUpdates
              - UpdateRollups
            state:
              - searched
            log_path:
              - c:/temp/ansible_wu.txt
          register: searched
        - debug: var=searched
       
        - name: install wu
          win_updates:
            category_names:
              - CriticalUpdates
              - SecurityUpdates
              - UpdateRollups
            state:
              - installed
            log_path:
              - c:/temp/ansible_wu.txt
          when: searched.found_update_count > 0
          register: installed
        - debug: var=installed
        
        - name: reboot
          win_reboot:
            pre_reboot_delay_sec: 0
            test_command: whoami
            reboot_timeout_sec: 300
          when: installed.reboot_required
          register: rebooted
        - debug: var=rebooted

This way, it does exactly what I was after.

On Sunday, January 8, 2017 at 11:38:17 PM UTC+2, Danny Rehelis wrote:
>
> I actually tried this and it didn't work.
>
> Later, found this post 
> https://groups.google.com/forum/#!topic/ansible-project/xGGe6WADtH0
>
> On Sun, Jan 8, 2017 at 10:01 PM, Dag Wieers <[email protected]> wrote:
>
>> On Wed, 4 Jan 2017, Danny Rehelis wrote:
>>
>> Anyone? :-(
>>>
>>
>> Never tried it myself, but wouldn't this work ?
>>
>> - include: update-windows.yml
>>   until: <condition>
>>   retries: 10
>>
>> You will have to make sure that the condition is based on facts from the 
>> tasks in your taskbook, which include win_updates and win_reboot.
>>
>> The only other option I see is to add win_reboot capabilities to 
>> win_updates, which would be a shame if that's what is needed.
>>
>> -- 
>> Dag
>>
>> -- 
>> 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/alpine.LRH.2.20.1701082057130.19483%40pikachu.3ti.be
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Danny Rehelis - autogun [AT] gmail.com
>

-- 
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/328db9e5-06fc-4486-9e4b-7e7f8e944774%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to