task 8.1 · chapter 8 of 8: run it like production · 25 min
Execution environments
objective
Build an execution environment with the lab’s collections, and run site.yml inside it with ansible-navigator.
execution-environment.ymlansible-navigator.ymlopen a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter
| Image | ans101-ee:1, built by make ee |
|---|---|
| Switches' network | ans101-mgmt |
What is an Ansible execution environment?
Your playbooks work in this codespace because it has the right Ansible, the right cisco.ios collection and
the right Python libraries, like the SSH library network_cli uses. A colleague’s laptop, a CI runner or AAP might have different versions, and “works on
my machine” is the result.
An execution environment (EE) is a container image with Ansible and everything your playbooks need, pinned. You build it once and run your playbooks inside it, anywhere. AAP runs every job in one.
ansible-builderbuilds the image fromexecution-environment.yml.ansible-navigatorruns a playbook inside it, instead of with the Ansible on your machine.
What goes in execution-environment.yml?
version: 3
images:
base_image:
name: quay.io/fedora/fedora-minimal:43 # the Linux it starts from
dependencies:
ansible_core:
package_pip: ansible-core==2.20.1 # which Ansible, pinned
ansible_runner:
package_pip: ansible-runner==2.4.3 # what navigator uses to run playbooks
python:
- ansible-pylibssh==1.4.0 # the SSH library network_cli uses
galaxy: requirements.yml # which collections: the same file the codespace uses
ansible-navigator.yml tells navigator which image to use, and how to run it. The EE is a container, with its
own network, so it can’t see the switches unless you connect it to theirs.
The collections, and the build
Point the EE at the same pinned collections the codespace uses: add the
galaxy:line at the end ofdependencies:, after thepython:list that’s already there:editexecution-environment.ymlCtrl+P → execution-environment.ymlpython: - ansible-pylibssh==1.4.0 galaxy: requirements.ymlBuild it. The first build takes a few minutes:
run in the terminalmake eeLook inside:
docker run --rm ans101-ee:1 ansible-galaxy collection list cisco.ios. Same version asansible-galaxy collection list cisco.iosin the codespace. That’s the point.Try running the fabric in it:
ansible-navigator run playbooks/site.yml. It fails to reach the switches: the container can’t see them. That’s the challenge.
Reach the switches from inside the EE
Connect the EE to the switches’ management network, ans101-mgmt, so ansible-navigator run playbooks/site.yml works.
hint
ansible-navigator passes extra options to the container engine with container-options:, a list, under
execution-environment:.
hint
The Docker option is --network=<name>. If navigator says it can’t resolve spine1, the option is missing or
misspelled.
show the solutionansible-navigator.yml
or pull it into your lab: make solve T=8.1, then git diff --staged shows what changed
ansible-navigator:
mode: stdout
execution-environment:
image: ans101-ee:1
pull:
policy: never
container-options: ["--network=ans101-mgmt"]
5 check: run it, then prove it
$ ansible-navigator run playbooks/site.yml
$ make check T=8.1when it's right, you'll see
╭─ task 8.1 · execution environments
│ ✓ execution environment ans101-ee:1 is built (make ee)
│ ✓ ansible-navigator runs playbooks/site.yml in the EE
╰─ 2/2 checks passed verified
background: part 8, Building an EE