I believe something like: - name: Reboot if packages were updated command: reboot NOW when: "'Complete!' in yumoutput"
would do the trick. http://docs.ansible.com/ansible/playbooks_conditionals.html#applying-when-to-roles-and-includes http://stackoverflow.com/questions/30533372/run-an-ansible-task-only-when-the-hostname-contains-a-string That is assuming that you don't have the string 'Complete!' turning up anywhere else in the output. On Wednesday, September 14, 2016 at 10:40:42 AM UTC-7, Jörg Kastning wrote: > > Hello, > > I would like to write a playbook to install Red Hat Security Advisory on > my hosts. The idea is to put the published information about the advisories > with their Numbers (e.g. RHSA-2016:1234) in a variable and run the > following playbook on all hosts: > --- > - hosts: all > > tasks: > - name: Group by OS > group_by: key=os_{{ ansible_distribution }} > changed_when: False > > - hosts: os_RedHat > vars: > RHSA: "RHSA-2016:1633, RHSA-2016:1626" > tasks: > - name: Install Red Hat Security Advisory > command: yum update-minimal --advisory {{ RHSA }} > register: yumoutput > > - name: Reboot if packages were updated > command: reboot NOW > when: yumoutput = ??? > > As you could see I would like to reboot a host only in case packages were > updated. As far as I know the last line in the yum output on the host > should be "Complete!". But I have trouble to get only the last line from > the output and use it in the conditional when clause. > > Could someone help me here, please? > > Because english is not my first language I may have difficulties to make > my point. Please bare with me and ask for more details or points I have to > make more clear. > > Kind regards, > Joerg > -- 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/c9de193c-e913-43b7-a5b5-85b5798f5d1d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
