Then I cannot figure out what am I doing wrong, can you please assist?

main.yml:

---
- hosts: windows_servers
  ignore_errors: true
  gather_facts: false

  tasks:
    - name: inner playbook
      include: update-windows.yml
      until: 'searched_inner.found_update_count > 0' 
      retries: 10
    - debug: var=searched_inner

update-windows.yml:

- name: search wu
  win_updates:
    category_names:
      - CriticalUpdates
      - SecurityUpdates
      - UpdateRollups
    state:
      - searched
    log_path:
      - c:/temp/ansible_wu.txt
  register: searched

- set_fact:
    searched_inner: "{{ searched }}"

and when I execute it, no until loop is actually happening:

[root@ansiblecm more_tires]# ansible-playbook main.yml --limit try

PLAY [windows_servers] 
*********************************************************

TASK [search wu] 
***************************************************************
 [WARNING]: Module invocation had junk after the JSON data:

changed: [try]

TASK [set_fact] 
****************************************************************
ok: [try]

TASK [debug] 
*******************************************************************
ok: [try] => {
    "searched_inner": {
        "changed": true, 
*        "found_update_count": 189, *
        "installed_update_count": 0, 
        "reboot_required": false, 
        "updates": {
            "0025cccd-6122-483a-a646-dd3ea3ff861f": {
                "id": "0025cccd-6122-483a-a646-dd3ea3ff861f", 
                "installed": false, 
                "kb": [
                    "3179574"
                ], 
                "title": "Update for Windows Server 2012 R2 (KB3179574)"
            }, 
...
...
...
PLAY RECAP 
*********************************************************************
try                        : ok=3    changed=1    unreachable=0    failed=0 
  

Playbook run took 0 days, 0 hours, 2 minutes, 4 seconds


Why until is not triggered here by until: 
'searched_inner.found_update_count > 0'


On Friday, January 13, 2017 at 12:26:29 AM UTC+2, Matt Davis wrote:
>
> That post is really old- include looping has worked for a long time...
>
> On Thursday, January 12, 2017 at 1:28:05 AM UTC-8, Danny Rehelis wrote:
>>
>> Hi Matt,
>>
>> Dag's solution was something I really hoped to work but then I found this 
>> post by Brian Coca - 
>> https://groups.google.com/forum/#!topic/ansible-project/xGGe6WADtH0
>>
>> Seems like this is not possible because "Include is not a module, more 
>> like a preprocessing macro."
>>
>> On Thu, Jan 12, 2017 at 4:02 AM, Matt Davis <[email protected] 
>> <javascript:>> wrote:
>>
>>> The solution Dag posted is what I've always done, and it works great for 
>>> me. I've been advocating for block loop support (as a cleaner solution to 
>>> exactly this issue) since before it shipped, but I don't have the bandwidth 
>>> to implement myself right now, and around here it's kinda "put up or shut 
>>> up". ;) If it doesn't work for you, let us know why and maybe we can get it 
>>> figured out.
>>>
>>> I really wouldn't recommend the "run the playbook in a loop" thing- you 
>>> lose a lot of output fidelity and error handling, and it's really just a 
>>> way more expensive way to do what Dag suggested.
>>>
>>> I actually originally wrote win_updates with a wrapper action that would 
>>> handle the reboots automatically, but for various reasons (that I can't 
>>> recall) decided to abandon the wrapper before I shipped it...
>>>
>>> -Matt
>>>
>>>
>>> On Monday, January 2, 2017 at 7:39:48 AM UTC-8, [email protected] 
>>> <javascript:> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm using win_updates module to carry out windows patching and it works 
>>>> pretty good.
>>>> Sometime, updates have dependencies and multiple playbook execution 
>>>> required.
>>>>
>>>> I was thinking, if possible, to loop the playbook until 
>>>> "found_update_count > 0" without the need of running ansible-playbook 
>>>> multiple time after each finish.
>>>>
>>>> My playbook looks like this:
>>>>
>>>> - hosts: win_server_1
>>>>   ignore_errors: true
>>>>   gather_facts: true
>>>>
>>>>   tasks:
>>>>     - name: search wu
>>>>       win_updates:
>>>>         category_names:
>>>>           - UpdateRollups
>>>>           - CriticalUpdates
>>>>           - SecurityUpdates
>>>>         state:
>>>>           - searched
>>>>         log_path:
>>>>           - c:/temp/ansible_wu.txt
>>>>       register: searched
>>>>     
>>>>     - name: install wu
>>>>       win_updates:
>>>>         category_names:
>>>>           - UpdateRollups
>>>>           - CriticalUpdates
>>>>           - SecurityUpdates
>>>>         state:
>>>>           - installed
>>>>         log_path:
>>>>           - c:/temp/ansible_wu.txt
>>>>       register: installed
>>>>       when: searched.found_update_count > 0
>>>>     
>>>>     - name: reboot
>>>>       win_reboot:
>>>>         pre_reboot_delay_sec: 0
>>>>         test_command: whoami
>>>>         reboot_timeout_sec: 300
>>>>       when: installed.reboot_required = 'true'
>>>>       register: reboot
>>>>
>>>>
>>>> I cant figure out how to put this in playbook by myself, seeking for 
>>>> some guidance.
>>>>
>>>> Thanks,
>>>>
>>>> -- 
>>> 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/2ebf7ecd-8da0-4b1d-99ba-f886721a9d2c%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/2ebf7ecd-8da0-4b1d-99ba-f886721a9d2c%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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/90ae5a90-fdcd-4a20-8c59-c562552c332c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to