Ansible 通知语法问题 - 名称 ^ 任务中未检测到任何操作
Ansible notify syntax issue - name ^ no action detected in task
我不确定我在这里遗漏了什么。
Ansible 2.1.2.0
Python 2.7.5
CentOS Linux 7.2.1511 版(核心)
剧本 文件看起来像:
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ cat netdata.yml
---
- hosts: all
gather_facts: no
roles:
- netdata
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
角色的 (netdata) main.yml 看起来像:
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ cat roles/netdata/tasks/main.yml
---
# ansible-playbook -i
#- name: Netdata details
# debug:
# msg: "server = {{ netdata_server }}"
##
#- name: Check if netdata systemctl is running
# command: "systemctl status netdata"
# ignore_errors: yes
# register: netdata_systemctl_status
#
#- name: Report status of Netdata Service
# debug:
# msg: "{{ netdata_systemctl_status.stdout_lines }}"
#
- name: Start netdata systemctl if it is not running
debug:
msg: "Restarting netdata systemctl now"
notify: restart netdata systemctl
#when: netdata_systemctl_status | failed
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
处理程序通知通知程序,它的主文件如下所示:
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ cat roles/netdata/handlers/main.yml
---
# PS.
# Order of listing notifiers in this file matters.
# Order of listing notifiers while calling/notifying a notifier in a task/action doesn't.
- name: restart netdata systemctl
systemd:
name: netdata
state: restarted
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
那么,为什么 Ansible 会给我以下错误?
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ ansible-playbook -i "`hostname`," --connection=local netdata.yml
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/home/vagrant/aks/netdata_ansible/ansible/roles/netdata/handlers/main.yml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: restart netdata systemctl
^ here
The error appears to have been in '/home/vagrant/aks/netdata_ansible/ansible/roles/netdata/handlers/main.yml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: restart netdata systemctl
^ here
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
systemd
module 是在 Ansible 2.2 中引入的。
systemd - Manage services.
New in version 2.2.
您使用的是 Ansible 2.1.2,因此 Ansible 报告任务中未定义已知操作。
我不确定我在这里遗漏了什么。
Ansible 2.1.2.0
Python 2.7.5
CentOS Linux 7.2.1511 版(核心)
剧本 文件看起来像:
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ cat netdata.yml
---
- hosts: all
gather_facts: no
roles:
- netdata
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
角色的 (netdata) main.yml 看起来像:
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ cat roles/netdata/tasks/main.yml
---
# ansible-playbook -i
#- name: Netdata details
# debug:
# msg: "server = {{ netdata_server }}"
##
#- name: Check if netdata systemctl is running
# command: "systemctl status netdata"
# ignore_errors: yes
# register: netdata_systemctl_status
#
#- name: Report status of Netdata Service
# debug:
# msg: "{{ netdata_systemctl_status.stdout_lines }}"
#
- name: Start netdata systemctl if it is not running
debug:
msg: "Restarting netdata systemctl now"
notify: restart netdata systemctl
#when: netdata_systemctl_status | failed
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
处理程序通知通知程序,它的主文件如下所示:
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ cat roles/netdata/handlers/main.yml
---
# PS.
# Order of listing notifiers in this file matters.
# Order of listing notifiers while calling/notifying a notifier in a task/action doesn't.
- name: restart netdata systemctl
systemd:
name: netdata
state: restarted
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
那么,为什么 Ansible 会给我以下错误?
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $ ansible-playbook -i "`hostname`," --connection=local netdata.yml
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/home/vagrant/aks/netdata_ansible/ansible/roles/netdata/handlers/main.yml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: restart netdata systemctl
^ here
The error appears to have been in '/home/vagrant/aks/netdata_ansible/ansible/roles/netdata/handlers/main.yml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: restart netdata systemctl
^ here
[vagrant@myvagrant ~/aks/netdata_ansible/ansible] $
systemd
module 是在 Ansible 2.2 中引入的。
systemd - Manage services.
New in version 2.2.
您使用的是 Ansible 2.1.2,因此 Ansible 报告任务中未定义已知操作。