ansible-galaxy fails on dependency with empty meta/main.yml - ansible

I have a requirements.yml file that lists dependencies for an Ansible Role:
---
- src: git#gitrepo:group/dependency1.git
scm: git
name: name1
- src: git#gitrepo:group/dependency1.git
scm: git
name: name2
These roles do not have any dependencies themselves, and as they are on a private SCM system (among other reasons), they do not need any metadata. However, loading in Ansible dependencies requires that this file exists. Therefore, the dependencies have a blank meta/main.yml to enable using ansible-galaxy.
When installing dependencies using:
ansible-galaxy install --role-file requirements.yml --roles-path foo
after the first dependency was installed, it would error out with:
ERROR! Unexpected Exception: 'NoneType' object has no attribute 'get'
Using the very very verbose output, the error gets located:
galaxy.py", line 394
After experimentation, running the command several more times would progress through the dependencies, one at a time. Nested dependencies would, therefore, fail; as either the parent would install then error out, or ansible-galaxy would think the parent is already installed and skip dependencies.
The question is: how do I stop this error from occurring and get ansible-galaxy to correctly process my dependencies?

I just fixed this in devel. Should make the 2.4 release of Ansible.

As it turns out, a blank meta/main.yml is not sufficient to process a role as a dependency. My hypothesis is that the role object is initialised with no metadata field if the file is blank, as the line mentioned in the verbose output is:
role_dependencies = role.metadata.get('dependencies') or []
"role" is used prior to this line, so will be an instance, whereas this is the first mention of "metadata".
This section of code is dealing with installing nested dependencies, as the line above is making checks to determine if it should process nested dependencies.
if not no_deps and installed:
role_dependencies = role.metadata.get('dependencies') or []
...
If this line also checked for the existence of metadata, for example:
if not no_deps and installed and metadata:
Then this section would be (rightfully) skipped. However, as Ansible does not make this check, metadata is the 'NoneType' object, which indeed has no attribute 'get'.
What this means is that the meta/main.yml file needs at least one key in it in order to be processed as a dependency. Having a meta/main.yml file of:
---
galaxy_info:
is sufficient for this purpose.

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

Specify Collection dependency for Molecule

Molecule is informed to download role dependencies from Ansible Galaxy via
dependency:
name: galaxy
options:
role-file: requirements.yml
However, there doesn't appear to be any documentation on how Molecule can be informed to download Collections. https://molecule.readthedocs.io/en/stable/configuration.html#ansible-galaxy does not list a collections option and I don't see an open feature request on https://github.com/ansible/molecule for this.
Asking here in case this is a solved issue for Molecule, otherwise I suppose this would be a feature request on the Molecule github repo. How can I inform Molecule that it needs to download a Collection for a ansible-galaxy dependency?
My requirements.yml file looks like this:
---
roles:
- src: gantsign.visual-studio-code
- src: artis3n.bitwarden_app
collections:
- name: artis3n.github
This format is supported by Ansible at https://docs.ansible.com/ansible/devel/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file.
The documentation now covers collections as well since #2609. However, if you look at this pull request you can see it shouldn't have passed because the tests fail. It makes sense now that I was unable to get a working solution on my host more than 8 days ago; I notice the last merge after tests passed was 8 days ago.
I don't think this latest merge has been released yet, but I believe there is a workaround.
The issue I filed against Molecule has been completed, so this functionality is now present in Molecule as of version 3.0.3.

Can I add roles in a private git repo as a meta/dependancy in Ansible?

I have a bunch of Ansible roles that I'd like to reuse. They are each kept in a repo in a private BitBucket.
I want to add projects that are hosted in Git as meta/dependencies for my the roles I'm working on but I can't quite figure out the syntax is.
In this non-working example, a role requires another role to be deployed first with parameters prior to running.
FYI, The remote role "acm_layout" is intended to create a standard directory layout for the server, so that my role can run knowing that all of the standard directories already exist.
---
dependencies:
- { role: project_keys } # Works fine, just reuses a local role
- name: acm_layout # Doesn't work, but this is what I want to fix
src: ssh://git#bigcompany.com/acm/acm_layout.git
scm: git
version: feature/initialize
application_storage_dir: "{{base_storage_dir}}"
application_data_dir: "{{app_data_dir}}"
When I runt this I get the following error:
ERROR! the role 'acm_layout' was not found in [lots of paths deleted]
The error appears to have been in '/home/zs5fgzg/_tmp/horizon_deployment_scf/ansible/roles/horizon_layout/meta/main.yaml': line 4, column 6, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- { role: horizon_keys }
- src: ssh://git#bigcompany.com:7999/acm/acm_layout.git
^ here
So what's the correct way to do this?
Yes, you can use ansible-galaxy install with requirements.yml option to get roles remotely. Create requirements.yml as follows:
https://github.com/avinash6784/elk-stack/blob/master/requirements.yml
And run the following command:
$ ansible-galaxy install -r requirements.yml -p roles/
For more info on how to get roles using ansible-galaxy please visit
http://docs.ansible.com/ansible/latest/galaxy.html

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