问题描述
在运行一个 Ansible 任务时遇到了错误。他想要运行的 Play 如下所示:
- name: use of handlers
hosts: all
tasks:
- name: install packages
yum:
name: httpd
state: latest
notify: restart package
handlers:
- name: restart package
service:
name: httpd
state: restarted
但是,Ansible 给出了以下错误信息:
fatal: [serverb.local]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (ansible.legacy.dnf) module: notify. Supported parameters include: allowerasing, allow_downgrade, name (pkg), enablerepo, disable_excludes, conf_file, list, disable_plugin, installroot, enable_plugin, disable_gpg_check, download_dir, update_cache (expire-cache), releasever, state, nobest, bugfix, install_weak_deps, update_only, autoremove, exclude, download_only, cacheonly, security, lock_timeout, skip_broken, disablerepo, validate_certs, install_repoquery."}
解决方案
请注意以下操作注意版本差异及修改前做好备份。
方案1
错误的原因是缩进错误。正确的语法应该是:
- name: install packages
yum:
name: httpd
state: latest
notify: restart package
错误信息中已经给出了提示:
"Unsupported parameters for (ansible.legacy.dnf) module: notify.
notify
不是 dnf
或 yum
模块的参数,它是一个 Playbook 关键字,可以应用于一个块或一个任务。在上面的例子中,它必须作为一个任务关键字进行缩进。请参考 Notifying handlers。
正文完