Creating an Execution Environment
-
In this section we will show you step by step how to build an Execution Environment (EE) from code. You will also be publishing this EE to your own private automation hub which you will use in the rest of the tasks.
From that point onwards we will be able to configure the Platform using this execution environment which has all the required dependencies included. We will then make use of ansible-navigator as our tooling to run the configuration playbooks from then on.
Task 1 - Create our EE Definition
-
Create a file
/home/lab-user/casc_lab/group_vars/all/ah_ee_list.yml
where we will create a list calledee_list
that has 4 key things to set per item which are:-
name
this is required and will be what the EE image will be called -
system
this is any system packages that would be needed. Set under dependencies. -
python
these are any python modules that need to be added through pip (excluding ansible). Set under dependencies. -
galaxy
any collections that you would like to be built into your EE image. Set under dependencies.which the role will loop over and for each item in this list it will create and publish an EE using the provided variables. Take the example below and use this in your code.
--- ee_list: - name: "{{ aap_hostname }}/config_as_code" pull: always dependencies: galaxy: collections: - name: infra.aap_configuration version: 3.1.0 - name: infra.ee_utilities version: 4.0.0 - name: ansible.platform version: 2.5.20250213 - name: ansible.hub version: 1.0.0 - name: ansible.controller version: 4.6.8 - name: containers.podman version: 1.16.3 - name: community.general version: 10.4.0 build_files: - src: /home/lab-user/casc_lab/ansible.cfg dest: configs build_steps: prepend_galaxy: - COPY _build/configs/ansible.cfg /etc/ansible/ansible.cfg ee_build_arg_defaults: ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: '-vvvv' prepend_galaxy: - COPY _build/configs/ansible.cfg /etc/ansible/ansible.cfg ee_base_image: "{{ aap_hostname }}/ee-minimal-rhel8:latest" ee_image_push: false ee_prune_images: false ee_create_ansible_config: false ee_pull_collections_from_hub: false ee_create_controller_def: true ...
-
-
Further documentation for those who are interested to learn more see:
Task 2 - Double check your Execution Environments
-
Check the file
/home/lab-user/casc_lab/group_vars/all/execution_environments.yml
and add make sure theconfig_as_code
execution environment is there, you can also look in the gui. It should be listed with image path{{ aap_hostname }}/config_as_code
that is pullalways
and uses the credentialcr_ah
.--- controller_execution_environments: <...> - name: "config_as_code" image: "{{ aap_hostname }}/config_as_code" pull: always credential: cr_ah ...
-
Further documentation for those who are interested to learn more see:
Task 3 - Create the the Playbook
Create a playbook to build an EE
-
The next step is to create a playbook/file
playbooks/build_ee.yml
which will run the ee_builder role to create the EE and push it to your Private Automation Hub.- name: Playbook to configure execution environments hosts: execution gather_facts: false connection: local vars_files: - "../vault.yml" tasks: - name: Include ee_builder role ansible.builtin.include_role: name: infra.ee_utilities.ee_builder ...
Task 4 - Run the Playbook
-
Run the playbook pointing to the recently created inventory file and limit the run to just execution to build your new custom EE and publish it to Private Automation Hub.
ansible-playbook -i inventory.yml -l execution playbooks/build_ee.yml
-
Further documentation for those who are interested to learn more see:
Task 5 - If the Playbook Fails
-
Push your new custom EE and publish it to Private Automation Hub.
-
Make sure to replace aap_hostname with your instance {nginx_web_url}, if this fails about overwriting an existing in the controller try a 2nd time it should work. This is an issue with the lab.
podman login #aap_hostname podman push ##aap_hostname##/config_as_code