I'm calling a module, Ansible still complains about "no action" - ansible

I'm getting an error with Ansible, "ERROR! No action detected in task." According to Why does Ansible show "ERROR! no action detected in task" error? , it looks like my error should be that I tried to write a role, and put a playbook in my role/tasks/main.yml. And the solution is to specify only a list of tasks in the tasks/main.yml file. Like this:
---
- name: My first task
my_module:
parameter1: value1
So my file looks like this:
---
- name: using a module
ansible.builtin.command: echo hello there
So I am using a module, just like in the example shown elsewhere on StackOverflow, but still I get the error message. What am I missing?
This is for Ansible 2.9 on RHEL 7.7. Thanks.

You are using ansible v2.9.
The (optional) full <namespace>.<collection>.<module_name> you are using in your task is only valid starting from ansible v2.10.
Use the short name: ansible.builtin.command => command.
You can also switch to the ansible v2.9 version on the documentation on the site to prevent this kind of problem when copy/pasting. See the dropdown on the top left

From the information you provided here it doesn't appear that you're using an actual module, but instead you've placed a task list file in a module search path. Modules are implemented as programming language code that gets bundled and piped over the connection plugin to be executed in order to carry out task work on the managed host in the inventory.

Related

Ansible ERROR! no action detected in task if I use full module name

I try to do a simple apt update on a remote system. My playbook looks like this
---
- hosts: all
become: true
tasks:
- name: update
ansible.builtin.apt:
update_cache: yes
When I run it I get the error
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/opt/LabOS/ansible/test_pb.yml': line 6, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: update
^ here
However if I remove the module path (ansible.builtin.) it runs just fine. According to the documentation both notations should work. What am I missing here?
My ansible-playbook version is 2.7.7
The (optional) full name of the module like ansible.builtin.apt is only available starting from ansible version 2.10.
Since, you are on an older version, it gives an error and you can use only the short name of the module, for example: apt

ERROR! couldn't resolve module/action . This often indicates a misspelling, missing collection, or incorrect module path

I've got an Ansible Collections in my Ansible playbook as follows:
- name: Create a profile for the user
community.windows.win_user_profile:
username: test
name: test
state: present
and the collection is installed via
ansible-galaxy collection install ansible.windows
so I can see it at ~/.ansible/collections.
However I keep getting:
ERROR! couldn't resolve module/action 'community.windows.win_user_profile'. This often indicates a misspelling, missing collection, or incorrect module path.
I've also copied it alongside the playbook just in case but still get the same error message.
Any suggestions?
I got the same error with Ansible 2.9 on Ubuntu 20.04 after install community.general. The solution in this case was installing ansible.posix
ansible-galaxy collection install ansible.posix
as this contains the mount module https://docs.ansible.com/ansible/latest/collections/ansible/posix/mount_module.html
There are two Windows collections: community and Supported. I know that's confusing :(
Looks like you've installed ansible.windows, though you are using community.windows
The fix is:
ansible-galaxy collection install community.windows
ansible 2.9 uses collections different.
One way is to add them to the top:
---
- hosts: all
collections:
- community.windows
and then later use:
- name: Create a profile for the user
win_user_profile:
username: test
name: test
state: present
for reference:
Use Ansible Collections
collections are backwardcompatible
Dirty:
dont do this, but it works.
ansible-config dump |grep DEFAULT_MODULE_PATH
and copy them there (example replace path and name)...
cp -p ~/.ansible/collections/ansible_collections/community/general/plugins/modules/system/sudoers.py ./library/
Adding below details to your question would be helpful
Ansible host operating system
Ansible version
I guess, this is error is specific to ansible version. I guess you are using ansible 2.9 version or lower version. whereas, Installing collections with ansible-galaxy is only supported in ansible 2.9+.
Reference link : https://galaxy.ansible.com/ansible/windows ( look into 'Note' section )
You can upgrade your ansible version and give a try.
Reference link : https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#upgrading-from-2-9-or-earlier-to-2-10

Unable to update xml element value with ansible-playbook

I am using below playbook to update specific element value in xml file and its throwing error. I have installed python-lxml module as well as ansible version 2.7.8
---
- name: Set element
xml:
path: /home/emsuser/appD_agent_master/machineagent/machine_agent/conf/controller-info.xml
xpath: /controller-info/application-name
value: "Vicom Enterprise blackout Manager"
...
responce:
ERROR! 'xml' is not a valid attribute for a Play
The error appears to have been in '/home/emsuser/playbooks/editMechineAgentConf.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Set element
^ here
I am not sure where I am doing mistake. Please help me out . I am new to ansible.
Your code is not a playbook, it's a task file.
In a playbook, you have a tasks: section listing your tasks.
Take a look at the Playbooks intro documentation.

How to Include task from another role in ansible?

I want to include a task from a different role.
I would not want to hardcode it like
- name : Set topology based on Jenkins job name
include: ../../pre-req/tasks/set-topo.yml
tags: core
Is there a way to do this with dependency? I tried creating a meta directory with files and tasks, somehow it' s not getting triggered.
something like this
vim roles/pre-req/meta/main.yml
---
allow_duplicates: yes
dependencies:
- { role: topo, tags: ['core'] }
I would not want to hardcode it like
Why not? You want to include a task, and that's how you include a task.
If what you want to do is include the entire other role, Ansible 2.2 (released yesterday) added include_role.

Ansible archive module "no action detected in task"

I want to use the archive module of ansible but it is unfortunately not working. I have the following version installed: ansible 2.3.0 (devel 2131eaba0c)
my playbook looks like this:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
The output looks like this:
"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/prj/sndbox1/app/jenkins/jobs/release/workspace/tasks/build_rpclient.yml': line 125, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
^ here
We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
As far as I understood the doc, the extra modules are shipped within ansible, so I assume I don't need to separately install this module.
However, what am I doing wrong? Is there any configuration I need to change in order to tell ansible where to look for the extra modules?
Thanks in advance!
Edit: Included the the full log message
Edit 2:
I tried to put the archive.py directly into my working directory --> [library]/archive.py
Now I get the following error:
"failed": true, "msg": "Could not find imported module support code for archive. Looked for either get_exception or pycompat24"
I have the same use case here, I'm using Ansible version 2.2.0.0. Installed via brew on MacOS sierra.
I've managed to solve the issue by adding the following into my local ansible.cfg file.
On defautls section, you must change the library entry:
[defaults]
library = /usr/local/Cellar/ansible/2.2.0.0_2/libexec/lib/python2.7:library
If you have a different setup, check:
pip show ansible
/usr/share/ansible if you are on Linux machine.

Resources