# ansible-test and roles variables.

**URL:** <https://forum.ansible.com/t/ansible-test-and-roles-variables/45334>\
**Category:** Get Help\
**Tags:** variables, ansible-test\
**Created:** [February 13, 2026, 4:14pm UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334 "2026-02-13T16:14:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntoineGGG](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AntoineGGG](https://forum.ansible.com/u/AntoineGGG)\
**Post date:** [February 13, 2026, 4:14pm UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334/1 "2026-02-13T16:14:13Z")

</div>

Hi, I’m trying to use Ansible Test to build an integration test and have a few questions.

- I read a few topics about the integration-config.yml file. What can I put in this file? Is there any documentation about it?

- I have some roles to test with variables declared in them. How can I use these variables in my tests? I don’t want to duplicate the variables declared inside the roles in the integration/targets folders. Is there any documentation about variable usage for Ansible Test?

Thanks a lot .

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [February 13, 2026, 7:20pm UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334/2 "2026-02-13T19:20:49Z")

</div>

The inventory\_config.yml file is loaded from `tests/integration/integration_config.yml` in collections. It can contain arbitrary variables. The only [documentation](https://docs.ansible.com/projects/ansible/latest/dev_guide/testing_integration.html#integration-config-yml) I found seems outdated (those example templates no longer exist).

You can use role variables in your test targets by passing `public: True` to [include\_role](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/include_role_module.html#parameter-public), or by using `import_role` (which sets public to True by [default](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/import_role_module.html#parameter-public)). If you use `include_role`, those role variables will be available following that task. If you use `import_role`, the role variables will be available anywhere in the test target. Here’s some [documentation](https://docs.ansible.com/projects/ansible/latest/playbook_guide/playbooks_reuse.html#reusing-files-and-roles) on the differences between includes and imports.

---

<div class="post-metadata">

**Author:** ![AntoineGGG](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AntoineGGG](https://forum.ansible.com/u/AntoineGGG)\
**Post date:** [February 17, 2026, 10:09am UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334/3 "2026-02-17T10:09:48Z")

</div>

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:

```auto
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:

```auto
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.

```auto
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.:

```auto
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](https://github.com/ansible/ansible/issues/68499), 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!

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [February 18, 2026, 6:43pm UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334/4 "2026-02-18T18:43:06Z")

</div>

The roles directory needs to be in the root of the collection. The layout for collections is documented here [Collection structure — Ansible Community Documentation](https://docs.ansible.com/projects/ansible/latest/dev_guide/developing_collections_structure.html#collection-directories-and-files).

`ansible-test` needs to be run from the root of the collection, and the path must include `ansible_collections`. There’s some documentation for that here [Testing collections — Ansible Community Documentation](https://docs.ansible.com/projects/ansible/latest/dev_guide/developing_collections_testing.html#testing-tools).

> **Here's a minimal layout containing a role and integration test**
>
> ```console
> /home/shertel/collections/ansible_collections/ns/col
> ├── roles
> │ └── role1
> │ └── vars
> │ └── main.yml
> └── tests
> └── integration
> ├── integration_config.yml
> └── targets
> └── test_role1
> └── tasks
> └── main.yml
> 
> 9 directories, 3 files
> 
> ```

> **roles/role1/vars/main.yml**
>
> ```yaml
> test_role_variable: defined_for_role1
> 
> ```

> **tests/integration/integration\_config.yml**
>
> ```yaml
> test_variable: defined_for_tests
> 
> ```

> **tests/integration/targets/test\_role1/tasks/main.yml**
>
> ```yaml
> - assert:
> that:
> - test_variable is defined
> 
> - include_role:
> name: role1 # Or ns.col.role1
> public: True
> 
> - assert:
> that:
> - test_role_variable is defined
> 
> ```

> **Running the test**
>
> ```console
> $ pwd
> /home/shertel/collections/ansible_collections/ns/col
> $ ansible-test integration test_role1
> WARNING: Unable to determine context for the following test targets, they will be run on the target host: test_role1
> Running test_role1 integration test role
> 
> PLAY [testhost] ****************************************************************
> 
> TASK [Gathering Facts] *********************************************************
> ok: [testhost]
> 
> TASK [test_role1 : assert] *****************************************************
> ok: [testhost] => {
> "changed": false,
> "msg": "All assertions passed"
> }
> 
> TASK [include_role : role1] ****************************************************
> included: role1 for testhost
> 
> TASK [test_role1 : assert] *****************************************************
> ok: [testhost] => {
> "changed": false,
> "msg": "All assertions passed"
> }
> 
> PLAY RECAP *********************************************************************
> testhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   
> 
> WARNING: Reviewing previous 1 warning(s):
> WARNING: Unable to determine context for the following test targets, they will be run on the target host: test_role1
> 
> ```

---

<div class="post-metadata">

**Author:** ![AntoineGGG](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AntoineGGG](https://forum.ansible.com/u/AntoineGGG)\
**Post date:** [February 19, 2026, 6:43am UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334/5 "2026-02-19T06:43:53Z")

</div>

Thanks a lot for your reply, and for sharing resources. I’ll give a try.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 21, 2026, 6:44am UTC](https://forum.ansible.com/t/ansible-test-and-roles-variables/45334/6 "2026-03-21T06:44:53Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
