Skip to content

Commit

Permalink
Make: Ansible Execution Env update (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
titom73 authored Feb 7, 2022
1 parent c599740 commit c7dca83
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ report.html
assets
*log.txt*

# Ansible builder
*context/
*_build/
Containerfile


# Translations
Expand Down
113 changes: 113 additions & 0 deletions ansible_collections/arista/cvp/docs/faq/containers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Ansible Execution Environment

## Ansible EE and builder overview

An automation execution environment is a container image used to execute Ansible playbooks and roles. It provides a defined, consistent, portable environment for executing automation.

Ansible Builder was developed to automate the process of building Execution Environments. It does this by using the dependency information defined in various Ansible Content Collections, as well as by the user. Ansible Builder will produce a directory that acts as the build context for the container image build, which will contain the Containerfile, along with any other files that need to be added to the image.

You can read more on [Ansible website](https://www.ansible.com/blog/introduction-to-ansible-builder) or also [here](https://docs.ansible.com/automation-controller/latest/html/userguide/execution_environments.html)

## Ansible Execution Environment for arista.cvp

Repository provides 2 different Execution environment definition:

- Execution Environment to execute stable version of CV Collection
- Execution Environment to execute development version of CV collection

!!! info
Even if CV collection provides such image, Execution Environments should be defined per ansible project and CV images only for testing. Indeed, our images are built with only our own requirements that can differ from your global project.

### Build your runner for stable version

By default, `ansible-builder` uses podman to build image, if you want to use docker instead, add `--container-runtime docker` to your CLI

```bash
# clone repository
git clone https://github.com/aristanetworks/ansible-cvp.git

# Move to root of the repo
cd ansible-cvp

# Build image
$ ansible-builder build --tag <your-image-tag> -f ansible_collections/arista/cvp/meta/execution-environment.yml
Running command:
podman build -f context/Containerfile -t inetsix/ansible-ee-avd:devel context
Complete! The build context can be found at: /Users/tgrimonet/Projects/avd-stack/ansible-cvp/context

# Validate collection is installed
## PODMAN method
podman container run -it --rm inetsix/ansible-ee-avd:pr ansible-galaxy collection list

## Docker method
docker run -it --rm inetsix/ansible-ee-avd:pr ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 2.5.0
ansible.utils 2.4.3
arista.eos 4.0.0
community.general 4.3.0

# /home/runner/.ansible/collections/ansible_collections
Collection Version
---------- -------
arista.cvp 3.2.0

# Execute your playbook (not covered here)
...
```

This image is based on the [latest ansible image version](https://quay.io/repository/ansible/ansible-runner?tag=latest&tab=tags). You can change it to use a specific version with: `--build-arg EE_BASE_IMAGE=quay.io/ansible/ansible-runner:latest`

!!! info
You can use this image with AWX to execute code using Ansible Execution Environment

### Build image for testing a PR

By default, `ansible-builder` use podman to build image, if you want to use docker instead, add `--container-runtime docker` to your CLI

```bash
# clone repository
git clone https://github.com/aristanetworks/ansible-cvp.git

# Move to root of the repo
cd ansible-cvp

# Build image
$ ansible-builder build --tag <your-image-tag> -f execution-environment.yml -c .
Running command:
podman build -f context/Containerfile -t inetsix/ansible-ee-avd:devel context
Complete! The build context can be found at: /Users/tgrimonet/Projects/avd-stack/ansible-cvp/context

# Validate collection is installed
## PODMAN method
podman container run -it --rm inetsix/ansible-ee-avd:pr ansible-galaxy collection list

## Docker method
docker run -it --rm inetsix/ansible-ee-avd:pr ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 2.5.0
ansible.utils 2.4.3
arista.cvp 0.0.0
arista.eos 4.0.0
community.general 4.3.0

# Execute your testing (not covered here)
...
```

This image is based on the [latest ansible image version](https://quay.io/repository/ansible/ansible-runner?tag=latest&tab=tags). You can change it to use a specific version with: `--build-arg EE_BASE_IMAGE=quay.io/ansible/ansible-runner:latest`.

This build will copy local version of your collection to the container to `/usr/share/ansible/collections/ansible_collections`

## Resources

- [Ansible builder](https://ansible-builder.readthedocs.io/en/stable/) documentation
- [Ansible runner](https://ansible-runner.readthedocs.io/en/stable/) documentation
- Ansible [introduction to builder and runner](https://www.ansible.com/blog/introduction-to-ansible-builder)
- Network To Code [introduction to builder and runner](https://blog.networktocode.com/post/ansible-builder-runner-ee/)
6 changes: 3 additions & 3 deletions ansible_collections/arista/cvp/meta/execution-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version: 1

build_arg_defaults:
EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:stable-2.12-latest'
EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:latest'

dependencies:
galaxy: ../collections.yml
Expand All @@ -20,5 +20,5 @@ additional_build_steps:
git \
vim \
sshpass
# append:
# - RUN ls -la /etc
append:
- RUN ansible-galaxy collection install arista.cvp
1 change: 1 addition & 0 deletions ansible_collections/arista/cvp/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ansible-core>=2.11.3,<2.13.0
ansible-builder
ansible-lint
galaxy-importer>=0.3.1
pycodestyle
Expand Down
25 changes: 25 additions & 0 deletions execution-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# execution-environment.yml
---
version: 1

build_arg_defaults:
EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:latest'

dependencies:
galaxy: ansible_collections/arista/cvp/collections.yml
python: ansible_collections/arista/cvp/requirements.txt

additional_build_steps:
prepend: |
RUN pip install --upgrade pip setuptools
RUN yum install -y \
make \
wget \
curl \
less \
git \
vim \
sshpass
append:
- COPY ansible_collections/arista/cvp/ /usr/share/ansible/collections/ansible_collections/arista/cvp
- RUN ls -la /usr/share/ansible/collections/ansible_collections/arista
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ nav:
- Activate logging: docs/how-to/debug.md
- Frequently Asked Questions:
- Error Messages: docs/faq/errors.md
- Ansible Execution Environment: docs/faq/containers.md
- Roles documentation:
- DHCP Configuration role: roles/dhcp_configuration/README.md
- Cloudvision Configlet Sync: roles/configlets_sync/README.md
Expand Down

0 comments on commit c7dca83

Please sign in to comment.