Thank you for your reply.
I tried different things with include_role, which raised new problems. I’ll try to summarise them here:
Here is the structure that was tested:
my_repo/
├── src/
│ └── ansible/
│ ├── inventory/
│ │ └── production.ini
│ ├── playbooks/
│ │ └── site.yml
│ └── roles/
│ └── role1/
│ ├── defaults/
│ │ └── main.yml
│ ├── tasks/
│ │ └── main.yml
│ ├── vars/
│ │ └── main.yml
│ └── ...
└── tests/
└── integration/
├── inventory
└── targets/
└── test_role1/
├── tasks/
│ └── main.yml
└── vars/
└── main.yml
What I tried to do within the test_role1 was to include or import the role1.
I tried executing ansible-test with something like this:
ansible-test integration --controller "origin:python=3.13@/home/user/code/.venv/bin/" --target "ssh:user@vm,python=3.9
The command works well without any ‘include’ or ‘import’ tasks, meaning that ansible-test works well with this configuration. However, I cannot ‘link’ Role1 to Test_Role1. The same applies to include or import vars.
Having read your reply, I think my tests folder should be within the ‘src/ansible’ folder, next to the ‘inventory’, ‘roles’ and ‘playbook’ folders, to make the ‘role1’ variables available in my tests.
my_repo/
└── src/
└── ansible/
├── inventory/
│ └── production.ini
├── playbooks/
│ └── site.yml
├── roles/
│ └── role1/
│ ├── defaults/
│ │ └── main.yml
│ ├── tasks/
│ │ └── main.yml
│ ├── vars/
│ │ └── main.yml
│ └── ...
└── tests/
└── integration/
├── inventory
└── targets/
└── test_role1/
├── tasks/
│ └── main.yml
└── vars/
└── main.yml
The ansible-test command no longer works.:
Configured locale: en_US.UTF-8
RLIMIT_NOFILE: (1024, 1048576)
FATAL: Cannot run integration tests without "roles/test/" or "tests/integration/targets/".
I tried to remove the ‘ansible-test’ command from almost every location within my repository, and as far as I can tell, I found this topic: ansible-test does not work with collections installed by galaxy inside a git repository · Issue #68499 · ansible/ansible · GitHub, which contains the same error.
In my configuration, ‘my_repo’ is a Git repository.
What do you think of this? What folder structure would you recommend for testing with ansible-test?
Sorry for this long message!