Hi,
I wrote a playbook to update a group of ubuntu servers and reboot them if required.
If I run it against one host using the -l option it works as expected, running against the whole group (3 hosts) it gives some strange behaviour. The "add to reboot_hosts" task is only executed (and skipped) for the second host in the group. The host which requires a reboot is not rebooted. I think I overlooked something.
Best Regards
Christian Rusa
The playbook looks like this:
- hosts: rusa
user: "{{ ssh_user }}"
sudo: yes
tasks:
- name: perform dist-upgrade
apt: upgrade=dist update_cache=yes
- name: check if reboot is required
command: ls /var/run/reboot-required
register: reboot_required
ignore_errors: True
- name: add to reboot_hosts
add_host: name={{ inventory_hostname }} groups=reboot_hosts
when: reboot_required|success
- hosts: reboot_hosts
user: "{{ ssh_user }}"
sudo: yes
gather_facts: no
tasks:
- name: reboot
command: reboot
The output looks like this:
ansible-playbook -v update.yml
PLAY [rusa]