Ansible-test not loading collections from requirements.yml

I’m attempting to run the integration tests for the ec2_vpc_nacl moudule of the amazon.aws collection and I’m running into an issue where the community.general collection is not installed in the container.

The command I’m running is:

ansible-test integration ec2_vpc_nacl --docker

(I’ve also tried using different container images such as fedora40).

The integration tests always fail because one of the tasks is attempting to use the community.general.json_query module, but the community.general collection isn’t being installed in the container by ansible-test.

TASK [ec2_vpc_nacl : Set helpful facts about subnets] **************************
fatal: [testhost]: FAILED! => {"msg": "template error while templating string: Could not load \"community.general.json_query\": 'Invalid plugin FQCN (community.general.json_query): unable to locate collection community.general'. String: {{ subnets | community.general.json_query('results[*].subnet.id') }}. Could not load \"community.general.json_query\": 'Invalid plugin FQCN (community.general.json_query): unable to locate collection community.general'"}

(NOTE: To get to the above task the fix from PR 2429 needs to be applied or use the --start-at-task "Fetch AZ availability")

I found that the community.general collection wasn’t added to the integration/tests/requirements.yml file so I added it locally to the file:

---
collections:
  - ansible.windows
  - ansible.utils # ipv6 filter
  - amazon.cloud # used by integration tests - rds_cluster_modify
  - community.general # used by integration test - ec2_vpc_nacl

However, even after adding the collection to the requirements.yml it is not found when running the test.

What do I need to do to get the collection installed in the container to be used during testing?

Not really an answer, but one of my personal bugbears: this should just be using standard Jinja, there’s nothing in there that requires the use of a non-standard filter.

        subnet_ids: "{{ subnets.results | map(attribute='subnet.id') }}"
        subnet_names: "{{ subnets.results | map(attribute='subnet.tags.Name') }}"

There are a limited set of circumstances where json_query is more usable than plain Jinja, and this is not one of them.

1 Like

You need to have it installed / checked out in the same directory structure from where you run ansible-test in amazon.aws. So if you are in /path/to/ansible_collections/amazon/aws, you need another directory /path/to/ansible_collections/community/general (with exactly the same /path/to) where community.general is installed (or its Git repo checked out). Only then will ansible-test find it (and automatically copy it into the Docker container).

The integration/tests/requirements.yml file is not used by ansible-test.

I have thought about changing the test to not use json_query as I think it would be cleaner too.

Thanks @felixfontein. I didn’t realize that and couldn’t find that documented anywhere.