Ansible collections often require python dependencies and other Ansible collections to run. Resolving these dependencies across different environments is tedious work. To solve this problem Ansible provides execution environments.
A collection developer will want to provide users with an execution environment that can be used to execute their collection. The developer should develop his/her collection against the execution environment that the end-user will use to run the collection. This document provides a development flow to modify collection source code outside of the execution environment container while being able to run the modified collection source code inside the execution environment container.
I will show you how to use an execution environment for developing against the f5networks.f5_modules
collection.
git clone https://gist.github.com/eda91ab3af382d1c86a7039ed0a6c75a.git my_dev_env
cd my_dev_env
git clone https://github.com/F5Networks/f5-ansible
# tree -L 1
.
├── ansible.cfg
├── execution_environment_dev.yml
├── execution_environment_prod.yml
├── f5-ansible
├── requirements.txt
└── requirements.yml
The execution environment needs to have the dependencies for the collection we are developing against.
requirements.txt
is copied from f5-ansible/ansible_collections/f5networks/f5_modules/requirements.txt
requirements.yml
is copied from the dependencies:
section of f5-ansible/ansible_collections/f5networks/f5_modules/galaxy.yml
pip install ansible-builder
ansible-builder -f execution_environment_dev.yml -t my_dev_env
podman run -it -v ${PWD}:/my_dev_env -v ${PWD}/f5-ansible/ansible_collections/f5networks:/usr/share/ansible/collections/ansible_collections/f5networks f5 /bin/bash
The above starts your development execution environment container and drops you into a /bin/bash
session. From here, you will be able to run ansible-playbook main.yml
that contains calls to the module you are developing, f5networks.f5_modules
in our case. Below is an example of the f5networks.f5_modules.bigip_pool
module being called.
cd /my_dev_env
ansible-playbook main.yml -vvv
# main.yml
---
- name: Using Collections
hosts: localhost
tasks:
- f5networks.f5_modules.bigip_pool:
name: my-pool
The above playbook will fail. However, the Ansible output tells the file path of the module we called and this path is the collection that we mapped into the container. Therefore, we can now modify our collection source code outside of the container and test that code by running it inside the execution environment. An execution environment that is very similar to the one that the users will run.
...
Using module file /usr/share/ansible/collections/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_pool.py
...
execution_environment_dev.yml
Uses the default community execution environment quay.io/ansible/ansible-runner:latest
.
execution_environment_prod.yml
Will use the official supported images i.e. registry.redhat.io/ansible-automation-platform-20-early-access/ee-supported-rhel8:2.0.0
node that building execution environments using this spec will require being ran from a registered RHEL system so that repositories are available to resolve system dependencies.