That was almost right, it worked now using this:
- name: verify if a reboot is required after upgrade
stat: path=/var/run/reboot-required
register: reboot_required
- name: reboot system
shell: sleep 2 && shutdown -r now
async: 1
poll: 0
ignore_errors: true
when: reboot_required.stat.exists
- name: wait for server to come back
local_action: wait_for host={{ inventory_hostname }} state=started
delay=5 timeout=30
when: reboot_required.stat.exists
Thank you! I was trying to do it using removes, register and async_status,
that was surely simpler. :)
Regards,
Francisco
On Fri, May 27, 2016 at 4:39 PM, Kai Stian Olstad <
[email protected]> wrote:
> On 27. mai 2016 21:28, Francisco Lopes wrote:
>
>> I see. I guess a found a good default for my case, which would be:
>>
>> - name: reboot system if required
>> shell: removes=/var/run/reboot-required sleep 2 && shutdown -r now
>> async: 1
>> poll: 0
>> ignore_errors: true
>>
>> - name: wait for server to come back
>> local_action: wait_for host={{ inventory_hostname }} state=started
>> delay=5 timeout=30
>>
>> So right now it correctly waits for the server to come back.
>>
>> Is it possible to add a condition on the wait task in order to skip it if
>> a
>> reboot was not required?
>>
>
> Not tested but this should work
>
> - stat: /var/run/reboot-required
> register: result_reboot
>
> - name: reboot system if required
> shell: sleep 2 && shutdown -r now
> async: 1
> poll: 0
> ignore_errors: true
> when: result_reboot.stat.exists == True
>
> - name: wait for server to come back
> local_action: wait_for host={{ inventory_hostname }} state=started
> delay=5 timeout=30
> when: result_reboot.stat.exists == True
>
> --
> Kai Stian Olstad
>
> --
> 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/3658b971-0c8e-a0f5-8aa7-2edbcc2aeab7%40olstad.com
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAKK1GdKP-8DgnSkimRZRYifvQLkpyCirz17j5EV7Mv5PvtEoQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.