Testing out the force handlers parameter in a role and it is not working 
for me.The first tasks fails, so I though the force handlers would force 
the second one to get trigger anyway

nginx.yml

---
- hosts: appservers
  force_handlers: True
  roles:
    - { role: nginx, when: "ansible_os_family == 'RedHat'"}


tasks/main.yml

- name: Run a command that fails
  shell: /bin/false

- name: Install nginx
  yum:
    name: nginx
    state: installed
  register: nginx_installed
  notify:
     - restart nginx


handlers/main.yml

- name: restart nginx
  service:
    name: nginx
    state: restarted
  register: nginx_restarted
- debug: var=nginx_restarted


Output -  


[ansible@localhost roles]$ ansible-playbook nginx.yml

PLAY [appservers] 
***********************************************************************

TASK [Gathering Facts] 
******************************************************************
ok: [10.10.0.3]
ok: [10.10.0.4]

TASK [nginx : Run a command that fails] 
*************************************************
fatal: [10.10.0.3]: FAILED! => {"changed": true, "cmd": "/bin/false", 
"delta": "0:00:00.017543", "end": "2017-09-21 10:09:03.816771", "failed": 
true, "rc": 1, "start": "2017-09-21 10:09:03.799228", "stderr": "", 
"stderr_lines": [], "stdout": "", "stdout_lines": []}
fatal: [10.10.0.4]: FAILED! => {"changed": true, "cmd": "/bin/false", 
"delta": "0:00:00.006919", "end": "2017-09-21 10:08:51.790017", "failed": 
true, "rc": 1, "start": "2017-09-21 10:08:51.783098", "stderr": "", 
"stderr_lines": [], "stdout": "", "stdout_lines": []}
        to retry, use: --limit @/etc/ansible/playbooks/roles/nginx.retry

PLAY RECAP 
******************************************************************************
10.10.0.3                  : ok=1    changed=0    unreachable=0    failed=1
10.10.0.4                  : ok=1    changed=0    unreachable=0    failed=1


 


-- 
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/aaf463bd-a992-406b-8ae7-bb6ffe9ae61f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to