Integration testing with a single inventory configuration

I am trying to write an integration test for custom API automation modules.
here is the scenario,
I have a server where my application is deployed with all the api’s (Mostly one server always).
While writing integration testing, I want to mention the server IP, username, and password in a single inventory file. But Ansible accepts only the inventory file configuration for every task. How to resolve this?

Here I have given the individual API related details for every task, server ip and authentication details.
Actual currently working:
ansible_collections/ansible_modules/tests/integration/targets/personal_info/tasks/main.yml
ansible_collections/ansible_modules/tests/integration/targets/personal_info/inventory_vars.yml
ansible_collections/ansible_modules/tests/integration/targets/work_details/tasks/main.yml
ansible_collections/ansible_modules/tests/integration/targets/work_details/inventory_vars.yml

Here I am trying to give one common file where I can fetch the serverIp
Expecting:
ansible_collections/ansible_modules/tests/integration/targets/personal_info/tasks/main.yml
ansible_collections/ansible_modules/tests/integration/targets/personal_info/inventory_vars.yml
ansible_collections/ansible_modules/tests/integration/targets/work_details/tasks/main.yml
ansible_collections/ansible_modules/tests/integration/targets/work_details/inventory_vars.yml
ansible_collections/ansible_modules/tests/integration/targets/inventory_vars.yml – here I have given only one inventory file, which will be used to get the server details alone. So that whenever the server or user name password changed I can change it here alone.

It sounds like you are not using a YAML inventory file? If you use YAML you can do this, see:

Hi Chris,
Thanks for the inputs, Actually I want to run ansible-test integration, not ansible-playbook. Do we have any way to run ansible-test with mentioning the inventory like this ansible-test integration -i inventory.yml?
Regards,
Sankar

I don’t know, I have never used ansible-test.

No problem. I have tried with ansible_collections/ansible_modules/tests/integration/integration_config.yml. This approach is working fine as expected for my scenario. ansible-test integration is working fine without any extra params passing while executing the command.

ANSIBLE_INVENTORY=tests/integration/inventory.yml ansible-test integration <target_name> – This is one more way of passing the inventory file while executing the command.

1 Like