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
Ansible automatically loads all executable files found in certain directories as modules. For local modules, use the name of the file as the module name: for example, if the module file is ~/. ansible/plugins/modules/local_users.py , use local_users as the module name.
Ansible 2.9 — Ansible Documentation.
Ansible Playbooks are lists of tasks that automatically execute against hosts. Groups of hosts form your Ansible inventory. Each module within an Ansible Playbook performs a specific task. Each module contains metadata that determines when and where a task is executed, as well as which user executes it.
I can't really improve upon @techraf answer https://stackoverflow.com/a/47159200/619760. I wanted to add reason #6 my special case
Incorrectly using roles:
to import/include roles as a subtask.
This does not work, you can not include roles in this way as subtasks in a play.
--- - hosts: somehosts tasks: - name: include somerole roles: - somerole
According to the documentation
you can now use roles inline with any other tasks using import_role or include_role:
- hosts: webservers tasks: - debug: msg: "before we run our role" - import_role: name: example - include_role: name: example - debug: msg: "after we ran our role"
Include the roles at the top
--- - hosts: somehosts roles: - somerole tasks: - name: some static task import_role: name: somerole hosts: some host - include_role: name: example
You need to understand the difference between import/include static/dynamic
You are using an older version of Ansible which did not have the module you try to run.
How to check it?
Open the list of modules module documentation and find the documentation page for your module.
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.
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
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
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.
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.
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
Explanation of the error :
No tasks to execute means it can not do the action that was described in your playbook
Root cause:
How to check :
ansible --version
Solution:
How to upgrade Ansible:
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#selecting-an-ansible-version-to-install
Quick instruction for Ubuntu :
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
P.S: followed this path and upgraded from version 2.0.2 to 2.9 After upgrade, same playbook worked like a charm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With