-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
molecule test does not pickup role #4256
Comments
Are you sure that Ansible itself is able to find the role? Try something similar to:
If Ansible itself is not finding the role, is not a valid bug. |
The result of localhost | FAILED! => {
"changed": false,
"msg": "Failed to lookup user ansible: \"getpwnam(): name not found: 'ansible'\""
} This seems fine, since the first task of the role adds ssh pub keys to the user "ansible", which is not available on my local machine. So I run the command again and override the
|
@ssbarnea I am pretty sure molecule is finding the role since as soon as change the name to something else converge fails. I have just restarted on a fresh branch of my role implementing the scenario "docker" the same way the documentation is mentioning: molecule-docker I just replaced the following: gather_facts: false
tasks:
- - name: Check uname
- ansible.builtin.raw: uname -a
- register: result
- changed_when: false
-
- - name: Print some info
- ansible.builtin.assert:
- that: result.stdout | regex_search("^Linux")
+ - name: Include base role
+ ansible.builtin.include_role:
+ name: base
+ tasks_from: main.yml Same result as before. If I run any other task directly, the containers are executed as expected. Like replaced example. If I use as rolename anything else, as an example: "baser", the task fails becaues the system does not find the role. |
I have the exact same problem. I only have a $ molecule --version
molecule 24.9.0 using python 3.12
ansible:2.17.4
azure:23.5.3 from molecule_plugins
containers:23.5.3 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
default:24.9.0 from molecule
docker:23.5.3 from molecule_plugins requiring collections: community.docker>=3.4.11 ansible.posix>=1.4.0
ec2:23.5.3 from molecule_plugins
gce:23.5.3 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
openstack:23.5.3 from molecule_plugins requiring collections: openstack.cloud>=2.1.0
podman:23.5.3 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
vagrant:23.5.3 from molecule_plugins |
I figured something out, but I am not sure, if this is the intended solution: If I just develop a role without a collection (I plan to move to collection, but not yet) I need to place the molecule inside the role and not inside the repo: The wrong waymkdir new_role
ansible-galaxy init compare
molecule init scenario -d docker default
molecule test It seems to work, but as soon as I try to utilize the role it just ignores it. This is how the directory now looks like: .
├── compare
│ ├── defaults
│ │ └── main.yml
│ ├── files
│ ├── handlers
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ └── main.yml
│ ├── templates
│ ├── tests
│ │ ├── inventory
│ │ └── test.yml
│ └── vars
│ └── main.yml
└── molecule
└── default
├── converge.yml
└── molecule.yml
12 directories, 10 files The working (right?) waymkdir new_role
ansible-galaxy init compare
cd compare
molecule init scenario -d docker default
molecule test The dir looks now like this: .
└── compare
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── molecule
│ └── default
│ ├── converge.yml
│ └── molecule.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
12 directories, 10 files If I now change add tasks to the role, update my diff --git a/compare/meta/main.yml b/compare/meta/main.yml
index 36b9858..bee0152 100644
--- a/compare/meta/main.yml
+++ b/compare/meta/main.yml
@@ -3,6 +3,8 @@ galaxy_info:
author: your name
description: your role description
company: your company (optional)
+ role_name: compare
+ namespace: test
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
diff --git a/compare/molecule/default/converge.yml b/compare/molecule/default/converge.yml
index e600756..bf88b64 100644
--- a/compare/molecule/default/converge.yml
+++ b/compare/molecule/default/converge.yml
@@ -6,3 +6,5 @@
- name: Replace this task with one that validates your content
ansible.builtin.debug:
msg: "This is the effective test"
+ roles:
+ - compare
diff --git a/compare/tasks/main.yml b/compare/tasks/main.yml
index ec76131..b339327 100644
--- a/compare/tasks/main.yml
+++ b/compare/tasks/main.yml
@@ -1,3 +1,6 @@
#SPDX-License-Identifier: MIT-0
---
# tasks file for compare
+- name: DEBUG
+ ansible.builtin.debug:
+ msg: "WHOHJOHOHO" Tested also with include role. |
Prerequisites
pip check
does not report any conflictsEnvironment
What happened
I have role which support (or should support) different distributions.
The role is created with the command
ansible-galaxy init base
let's assume the role only has the following task in
tasks/main.yml
There are a few more tasks, but this task will fail on different distributions.
Further, I've added the molecule scenario with
molecule init scenario
while I was in the role directory.The final structure on the role looks like the following:
When running the command
molecule test
It seems the role is getting included, but it never runs and so it does also not fail on the rockylinux8 docker.Using instead:
it will never be called.
Reproducing example
molecule.yml:
converge.yml:
The text was updated successfully, but these errors were encountered: