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

查看:439
本文介绍了为什么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. 打开模块列表模块文档并找到文档模块的页面.

  1. Open the list of modules module documentation and find the documentation page for your module.

阅读页面顶部的标题-它通常显示引入该模块的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-playbook 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

    操作模块名称拼写错误.


    Reason #3

    The action module name is misspelled.

    这很明显,但被忽略了.如果您使用错误的模块名称,例如使用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分发的模块.

    操作模块名称正确,但是它不是随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
    

    并检查以下值:

    已配置的模块搜索路径=

    configured module search path =

    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天全站免登陆