Ansible显示错误:
错误!任务中未检测到任何操作 . 这通常表示拼写错误的模块名称或模块路径不正确 .
What is wrong?
确切的成绩单是:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in 'playbook.yml': line 10, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: My task name
^ here
1 回答
原因#1
You are using an older version of Ansible which did not have the module you try to run.
怎么检查?
打开模块列表module documentation并找到模块的文档页面 .
阅读页面顶部的 Headers - 它通常显示引入模块的Ansible版本 . 例如:
并检查输出 . 它应该显示如下:
原因#2
You tried to write a role and put a playbook in my_role/tasks/main.yml.
tasks/main.yml
文件应仅包含任务列表 . 如果你指定:Ansible尝试查找名为
hosts
的操作模块和名为tasks
的操作模块 . 它没有,所以它抛出一个错误 .解决方案:仅指定
tasks/main.yml
文件中的任务列表:原因#3
The action module name is misspelled.
这很明显,但被忽视了 . 如果使用不正确的模块名称,例如
users
而不是user
,Ansible将报告"no action detected in task" .Ansible被设计为高度可扩展的系统 . 它没有可以运行的有限模块集,也无法“提前”检查每个操作模块的拼写 .
实际上你可以编写然后指定你自己的名为
qLQn1BHxzirz
的模块,而Ansible必须尊重它 . 因为它是一种解释型语言,所以只有在尝试执行任务时才会出现错误 .原因#4
You are trying to execute a module not distributed with Ansible.
操作模块名称是正确的,但它不是与Ansible一起分发的标准模块 .
如果您使用的是由第三方提供的模块 - 软件/硬件供应商或公开共享的其他模块,则必须先下载该模块并将其放在适当的目录中 .
您可以将其放在剧本的
modules
子目录中或公共路径中 .Ansible看起来是
ANSIBLE_LIBRARY
或--module-path
命令行参数 .要检查哪些路径有效,请运行:
并检查以下值:
Ansible版本2.4及更高版本应提供路径列表 .
原因#5
You really don't have any action inside the task.
任务必须定义一些操作模块 . 以下示例无效: