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] *******************************************************************

GATHERING FACTS ***************************************************************
ok: [host1.example.com]
ok: [host3.example.com]
ok: [host2.example.com]

TASK: [perform dist-upgrade] ************************************************** ok: [host3.example.com] => {"changed": false, "msg": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n", "stderr": "", "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n"} ok: [host2.example.com] => {"changed": false, "msg": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n", "stderr": "", "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n"} ok: [host1.example.com] => {"changed": false, "msg": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n", "stderr": "", "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n"}

TASK: [check if reboot is required] ******************************************* failed: [host3.example.com] => {"changed": true, "cmd": ["ls", "/var/run/reboot-required"], "delta": "0:00:00.010204", "end": "2014-05-19 07:36:20.335245", "rc": 2, "start": "2014-05-19 07:36:20.325041"} stderr: ls: cannot access /var/run/reboot-required: No such file or directory
...ignoring
failed: [host2.example.com] => {"changed": true, "cmd": ["ls", "/var/run/reboot-required"], "delta": "0:00:00.010280", "end": "2014-05-19 07:36:20.552200", "rc": 2, "start": "2014-05-19 07:36:20.541920"} stderr: ls: cannot access /var/run/reboot-required: No such file or directory
...ignoring
changed: [host1.example.com] => {"changed": true, "cmd": ["ls", "/var/run/reboot-required"], "delta": "0:00:00.008175", "end": "2014-05-19 07:36:20.607526", "rc": 0, "start": "2014-05-19 07:36:20.599351", "stderr": "", "stdout": "/var/run/reboot-required"}

TASK: [add to reboot_hosts] ***************************************************
skipping: [host2.example.com]

PLAY [reboot_hosts] ***********************************************************
skipping: no hosts matched

PLAY RECAP ******************************************************************** host1.example.com : ok=3 changed=1 unreachable=0 failed=0 host2.example.com : ok=3 changed=1 unreachable=0 failed=0
host3.example.com      : ok=3    changed=1    unreachable=0 failed=0

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/53799D04.4050106%40toscom.at.
For more options, visit https://groups.google.com/d/optout.

Reply via email to