为什么 Ansible 显示“错误!在任务中没有检测到动作"错误? [英] Why does Ansible show "ERROR! no action detected in task" error?

查看:38
本文介绍了为什么 Ansible 显示“错误!在任务中没有检测到动作"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ansible 显示错误:

Ansible shows an error:

错误!在任务中未检测到任何操作.这通常表示模块名称拼写错误或模块路径不正确.

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

怎么了?

准确的成绩单是:

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,其中没有您尝试运行的模块.

如何检查?

  1. 打开模块列表模块文档并找到文档模块页面.

阅读页面顶部的标题 - 它通常显示引入模块的 Ansible 版本.例如:

Read the header at the top of the page - it usually shows the Ansible version in which the module was introduced. For example:

2.2 版中的新功能.

New in version 2.2.

  • 确保您运行的是指定版本的 Ansible 或更高版本.运行:

  • Ensure you are running the specified version of Ansible or later. Run:

    ansible-playbook --version
    

    并检查输出.它应该显示如下内容:

    And check the output. It should show something like:

    ansible-剧本 2.4.1.0

    ansible-playbook 2.4.1.0

  • <小时>

    原因#2

    您尝试编写一个角色并将剧本放在 my_role/tasks/main.yml 中.


    Reason #2

    You tried to write a role and put a playbook in my_role/tasks/main.yml.

    tasks/main.yml 文件应该只包含任务列表.如果您指定:

    The tasks/main.yml file should contain only a list of tasks. If you specified:

    ---
    - name: Configure servers
      hosts: my_hosts
      tasks:
        - name: My first task
          my_module:
            parameter1: value1
    

    Ansible 尝试查找名为 hosts 的操作模块和名为 tasks 的操作模块.它没有,所以它会抛出一个错误.

    Ansible tries to find an action module named hosts and an action module named tasks. It doesn't, so it throws an error.

    解决方案:在tasks/main.yml文件中只指定一个任务列表:

    Solution: specify only a list of tasks in the tasks/main.yml file:

    ---
    - name: My first task
      my_module:
        parameter1: value1
    

    <小时>

    原因 #3

    操作模块名称拼写错误.

    这很明显,但被忽视了.如果您使用不正确的模块名称,例如 users 而不是 user,Ansible 将报告在任务中未检测到操作".

    This is pretty obvious, but overlooked. If you use incorrect module name, for example users instead of user, Ansible will report "no action detected in task".

    Ansible 被设计为一个高度可扩展的系统.它没有一组有限的模块可供您运行,也不能提前"检查每个动作模块的拼写.

    Ansible was designed as a highly extensible system. It does not have a limited set of modules which you can run and it cannot check "in advance" the spelling of each action module.

    事实上,您可以编写并指定自己的名为 qLQn1BHxzirz 的模块,Ansible 必须尊重这一点.由于它是一种解释型语言,它只有在尝试执行任务时才会发现"错误.

    In fact you can write and then specify your own module named qLQn1BHxzirz and Ansible has to respect that. As it is an interpreted language, it "discovers" the error only when trying to execute the task.

    您正在尝试执行未随 Ansible 分发的模块.

    action 模块名称是正确的,但它不是 Ansible 分发的标准模块.

    The action module name is correct, but it is not a standard module distributed with Ansible.

    如果您使用第三方提供的模块 - 软件/硬件供应商或其他公开共享的模块,您必须先下载该模块并将其放置在适当的目录中.

    If you are using a module provided by a third party - a vendor of software/hardware or another module shared publicly, you must first download the module and place it in appropriate directory.

    您可以将其放置在剧本的 modules 子目录或公共路径中.

    You can place it either in modules subdirectory of the playbook or in a common path.

    Ansible 查找 ANSIBLE_LIBRARY--module-path 命令行参数.

    Ansible looks ANSIBLE_LIBRARY or the --module-path command line argument.

    要检查哪些路径有效,请运行:

    To check what paths are valid, run:

    ansible-playbook --version
    

    并检查以下值:

    配置的模块搜索路径=

    Ansible 2.4 及更高版本应提供路径列表.

    Ansible version 2.4 and later should provide a list of paths.

    您在任务中确实没有任何操作.

    任务必须定义一些动作模块.以下示例无效:

    The task must have some action module defined. The following example is not valid:

    - name: My task
      become: true
    

    这篇关于为什么 Ansible 显示“错误!在任务中没有检测到动作"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆