---- hosts: appserversforce_handlers: Trueroles:- { role: nginx, when: "ansible_os_family == 'RedHat'"}
- name: Run a command that failsshell: /bin/false- name: Install nginxyum:name: nginxstate: installedregister: nginx_installednotify:- restart nginx
- name: restart nginxservice:name: nginxstate: restartedregister: nginx_restarted- debug: var=nginx_restarted
[ansible@localhost roles]$ ansible-playbook nginx.ymlPLAY [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.retryPLAY RECAP ******************************************************************************10.10.0.3 : ok=1 changed=0 unreachable=0 failed=110.10.0.4 : ok=1 changed=0 unreachable=0 failed=1
[ansible@localhost roles]$ ansible-playbook nginx.yml
PLAY [localhost] ***************************************************************TASK [Gathering Facts] *********************************************************ok: [localhost]TASK [nginx : Install nginx] ***************************************************fatal: [localhost]: FAILED! => {"changed": true, "failed": true, "msg": "Repository epel is listed more than once in the configuration\nRepository epel-source is listed more than once in the configuration\nYou need to be root to perform this command.\n", "rc": 1, "results": ["Loaded plugins: fastestmirror, langpacks\n"]}
to retry, use: --limit @/etc/ansible/playbooks/roles/nginx.retryPLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
tasks/main.yml- name: Install nginxyum:name: nginxstate: installedregister: nginx_installednotify:- restart nginx- name: Run a command that failsshell: /bin/false
[ansible@localhost roles]$ ansible-playbook nginx.ymlPLAY [localhost] ***************************************************************TASK [Gathering Facts] *********************************************************ok: [localhost]TASK [nginx : Install nginx] ***************************************************
changed: [localhost]TASK [nginx : Run a command that fails] *************************************** *fatal: [localhost]: FAILED! => {"changed": true, "cmd": "/bin/false", "delta": "0:00:00.003499", "end": "2017-09-21 15:19:14.897224", "failed": true, "rc": 1, "start": "2017-09-21 15:19:14.893725", "stderr": "", "stderr_lines": [], "stdo ut": "", "stdout_lines": []}RUNNING HANDLER [nginx : restart nginx] *************************************** *changed: [localhost]
to retry, use: --limit @/etc/ansible/playbooks/roles/nginx.retryPLAY RECAP ******************************************************************** *
localhost : ok=3 changed=2 unreachable=0 failed=1