为什么Ansible会显示;错误!在“任务”中未检测到任何操作;错误?
Ansible显示一个错误: 错误!在任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确 怎么了?为什么Ansible会显示;错误!在“任务”中未检测到任何操作;错误?,ansible,Ansible,Ansible显示一个错误: 错误!在任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确 怎么了? 确切记录如下: 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 m
确切记录如下:
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
您使用的是旧版本的Ansible,它没有您尝试运行的模块。
如何检查
ansible-playbook --version
并检查输出。它应该显示如下内容:
ansible剧本2.4.1.0
原因#2 您试图编写一个角色,并在
我的角色/tasks/main.yml
中放入剧本
tasks/main.yml
文件应仅包含任务列表。如果您指定:
---
- name: Configure servers
hosts: my_hosts
tasks:
- name: My first task
my_module:
parameter1: value1
Ansible尝试查找名为hosts
的操作模块和名为tasks
的操作模块。它没有,所以它抛出了一个错误
解决方案:仅在tasks/main.yml
文件中指定任务列表:
---
- name: My first task
my_module:
parameter1: value1
原因#3 操作模块名称拼写错误。 这很明显,但被忽视了。如果您使用了不正确的模块名称,例如
users
而不是user
,Ansible将报告“任务中未检测到任何操作”
Ansible被设计成一个高度可扩展的系统。它没有可以运行的有限模块集,并且不能“提前”检查每个操作模块的拼写
事实上,您可以编写并指定自己的名为qLQn1BHxzirz
的模块,Ansible必须尊重这一点。由于它是一种解释性语言,因此它仅在尝试执行任务时“发现”错误
理由#4 您正在尝试执行一个未使用Ansible分发的模块。 操作模块名称正确,但它不是随Ansible分发的标准模块 如果您使用的是第三方(软件/硬件供应商)提供的模块或其他公开共享的模块,则必须首先下载该模块并将其放置在适当的目录中 您可以将其放置在playbook的
modules
子目录或公共路径中
Ansible查看Ansible\u库
或--模块路径
命令行参数
要检查哪些路径有效,请运行:
ansible-playbook --version
并检查以下各项的值:
配置的模块搜索路径=
Ansible 2.4版及更高版本应提供路径列表
原因#5 任务中确实没有任何操作。 任务必须定义一些操作模块。以下示例无效:
- name: My task
become: true
我无法在@techraf answer上真正提高。 我想为我的特殊情况添加理由 理由#6 错误地使用
角色:
将角色导入/包含为子任务。
这不起作用,您不能以这种方式将角色作为子任务包含在剧本中
---
- hosts: somehosts
tasks:
- name: include somerole
roles:
- somerole
使用include_角色
根据
现在,您可以使用import\u role或include\u role将角色与任何其他任务内联使用:
将角色放在与主机内联的正确位置
包括顶部的角色
---
- hosts: somehosts
roles:
- somerole
tasks:
- name: some static task
import_role:
name: somerole
hosts: some host
- include_role:
name: example
您需要了解之间的区别对我来说,“systemd”模块出现问题。原来我的
ansible--version
是2.0.0.2,模块是在2.2版本中首次引入的。将我的ansible更新到最新版本修复了该问题
playbook.yaml
- name: "Enable and start docker service and ensure it's not masked"
systemd:
name: docker
state: started
enabled: yes
masked: no
错误
ERROR! no action detected in task
etc..
etc..
etc..
- name: "Enable and start docker service and ensure it's not masked"
^ here
错误解释:
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
没有要执行的任务意味着它无法执行剧本中描述的操作
根本原因:
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
- 已安装的Ansible版本不支持它
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
ansible--version
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
- 将Ansible升级到支持您尝试使用的功能的版本
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
Ubuntu的快速说明:
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
附言:遵循这条路径,从2.0.2版升级到2.9版
升级后,同一个剧本发挥了巨大的作用当我引用
调试
任务作为ansible.builtin.debug
导致CI中出现语法错误(但在本地工作):
在本地和CI中工作:
- name: "Echo the jenkins job template"
debug:
var: template_xml
verbosity: 1
我相信(但尚未证实)本地与CI之间的差异是可解释的
- 本地:2.10
- CI:2.7
ansible-galaxy collection install ansible.posix
我想知道为什么没有行动的任务对ansible来说是个问题。我可能想创建一个当变量具有特定值时失败的任务。它失败是因为ansible是垃圾,是部署时其他垃圾中最好的一个,但从SD的角度来看,这种神奇的行为简直是疯狂