Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

Why does Ansible show "ERROR! no action detected in task" error?

Ansible shows an error:

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

What is wrong?


The exact transcript is:

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Reason #1

You are using an older version of Ansible which did not have the module you try to run.

How to check it?

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

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

    New in version 2.2.

  3. 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


Reason #2

You tried to write a role and put a playbook in my_role/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 tries to find an action module named hosts and an action module named tasks. It doesn't, so it throws an error.

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

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

Reason #3

The action module name is misspelled.

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 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.

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.


Reason #4

You are trying to execute a module not distributed with 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.

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

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

To check what paths are valid, run:

ansible-playbook --version

and check the value of:

configured module search path =

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


Reason #5

You really don't have any action inside the task.

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

- name: My task
  become: true

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...