Redhat

在ansible中使用角色時處理程序不起作用

  • December 18, 2017

這是我的 lamp/tasks/main.yaml 文件(lamp 是角色名稱)

- import_task: httpd.yaml
- import_task: php.yaml
- notify: restart httpd

這是我的燈/處理程序/main.yaml 文件

- name: restart httpd
  service:
   name: httpd
   state: restarted
   enabled: yes

我的主要劇本文件是:

 - hosts: server1
   remote_user: root
   roles:
      - lamp

執行 playbook 時出現以下錯誤:

ERROR! no action detected in task. This often indicates a misspelled module 
name, or incorrect module path.

The error appears to have been in '/playbooks/lamp/tasks/main.yaml': line 1, 
column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- import_task: httpd.yaml
 ^ here


The error appears to have been in '/playbooks/lamp/tasks/main.yaml': line 1, 
column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- import_task: httpd.yaml
 ^ here

exception type: <class 'ansible.errors.AnsibleParserError'>
exception: no action detected in task. This often indicates a misspelled 
module name, or incorrect module path.

The error appears to have been in '/playbooks/lamp/tasks/main.yaml': line 1, 
column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- import_task: httpd.yaml
 ^ here

我在centos7上使用ansible 7.4。沒有處理程序它是工作文件。但是在使用處理程序時它不起作用。我最近開始學習ansible。請幫助我找到解決方案。我不明白為什麼處理程序不支持..?

有問題的錯誤是因為import_task語法不正確,請改用import_tasks(複數)。

但是處理程序可以附加到任務/從任務通知,而import_tasks不是任務本身,所以它不會做你期望的事情。您應該從應該觸發服務重新啟動(如配置更改)的各個任務中通知處理程序。

引用自:https://serverfault.com/questions/888700