I am trying to automate some tasks using Ansible. In my playbooks, I have a copy task and then i change the permissions of the file. I need the service to restart after this task. I am including notify and have also declared my handler, but strangely this handler is never getting invoked.
Excerpt from my playbook
- name: Configure Audit Log Purge Scheduler
copy:
src: "Scheduler-Log-Purge.config"
dest: "{{ crx_dir }}install/com.adobe.cq.audit.purge.Scheduler-LogPurge.config"
become: true
tags: aem
- name: Change Permissions of the Log Purge Scheduler config File
file:
path: "{{ crx_dir }}install/com.adobe.cq.audit.purge.Scheduler-LogPurge.config"
owner: crx
group: crx
become: true
notify: restart aem
tags: aem
- name: Pause the execution for cq5 to come up
pause:
minutes: 5
tags: aem
And here is my handler file contents.
---
- name: restart aem
service: name=cq5 state=restarted
become: yes
The o/p after running the playbook
gparasha-macOS:TLTD gparasha$ ansible-playbook -i hosts tltd.yml --tags aem -v
No config file found; using defaults
PLAY [Run tasks on Author] **************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [35.169.196.183]
PLAY [Run AEM Specific Steps on Author] *************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [35.169.196.183]
TASK [publish : Configure Audit Log Purge Scheduler] ************************************************************************************************************************************
ok: [35.169.196.183] => {"changed": false, "checksum": "3a9d00ea8357fd217a9442b1c408065abf077dfc", "failed": false, "gid": 1005, "group": "crx", "mode": "0644", "owner": "crx", "path": "/mnt/crx/author/crx-quickstart/install/com.adobe.cq.audit.purge.Scheduler-LogPurge.config", "secontext": "user_u:object_r:usr_t:s0", "size": 277, "state": "file", "uid": 1005}
TASK [publish : Change Permissions of the Log Purge Scheduler config File] **************************************************************************************************************
ok: [35.169.196.183] => {"changed": false, "failed": false, "gid": 1005, "group": "crx", "mode": "0644", "owner": "crx", "path": "/mnt/crx/author/crx-quickstart/install/com.adobe.cq.audit.purge.Scheduler-LogPurge.config", "secontext": "user_u:object_r:usr_t:s0", "size": 277, "state": "file", "uid": 1005}
TASK [publish : Pause the execution for cq5 to come up] *********************************************************************************************************************************
Pausing for 300 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
Press 'C' to continue the play or 'A' to abort
fatal: [35.169.196.183]: FAILED! => {"failed": true, "msg": "user requested abort!"}
But when i run this playbook, the restart of this service is not invoked. Why is this so?
Can we not use notify in file modules? Any help will be deeply appreciated.
You can attach notify
to any module.
But Ansible will notify handler only when task is in changed state – this is on purpose to prevent unnecessary handlers execution (e.g. service restarts) on subsequent playbook runs.
Your log excerpts show "changed": false
for the task in question, so handler execution is not triggered.
Also keep in mind that handlers are executed at the very end of the role/playbook unless they are explicitly flushed with meta, so in your scenario handler will be executed after Pause the execution for cq5 to come up
task.