任务完成后未调用处理程序

gau*_*har 1 ansible ansible-2.x ansible-handlers

我正在尝试使用 Ansible 自动执行一些任务。在我的剧本中,我有一个复制任务,然后更改文件的权限。我需要在执行此任务后重新启动该服务。我包括了通知并且还声明了我的处理程序,但奇怪的是这个处理程序永远不会被调用。

摘自我的剧本

- 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
Run Code Online (Sandbox Code Playgroud)

这是我的处理程序文件内容。

---

- name: restart aem
  service: name=cq5 state=restarted
  become: yes
Run Code Online (Sandbox Code Playgroud)

运行剧本后的o/p

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!"}
Run Code Online (Sandbox Code Playgroud)

但是当我运行这个剧本时,不会调用该服务的重新启动。为什么会这样呢?

我们不能在文件模块中使用notify吗?任何帮助将不胜感激。

Kon*_*rov 5

您可以附上notify到任何模块。

\n\n

但 Ansible 仅当任务处于更改状态 \xe2\x80\x93 时才会通知处理程序,这是为了防止在后续 playbook 运行时执行不必要的处理程序(例如服务重新启动)。

\n\n

您的日志摘录显示"changed": false有问题的任务,因此不会触发处理程序执行。

\n\n

另请记住,处理程序在角色/剧本的最后执行,除非它们显式地用meta刷新,因此在您的场景中,处理程序将在任务之后 执行Pause the execution for cq5 to come up

\n