Skip to content

CI/CD usage example

This documentation is an example of usage of Monkeyble in a CI/CD.

Create an Ansible execution environment

Create a Ansible execution environment that contains Monkeyble CLI and collections.

Example of execution-environment.yml:

version: 1
  galaxy: requirements.yml  # place here your required Ansible role and collections
  python: requirements.txt  # place here your required python libraries
  system: bindep.txt        # place here your required system packages

ansible_config: 'ansible.cfg' 
  prepend: |
    RUN pip3 install --upgrade pip setuptools

In the requirements.txt we should retrieve a line with the Monkeyble cli package. E.g:

monkeyble==1.2.0  # check he last version before placing it here

In the requirements.yml we should retrieve a line with the Monkeyble collection. E.g:

  - name: hpe.monkeyble
    version: 1.2.0  # check the last version before placing it here

Build the execution environment:

ansible-builder build --verbosity 3 \
--tag my_registry.example/repo/execution-environment-ansible \
--container-runtime docker

You can test locally the image against your repository

docker run -it --rm \
-v ${PWD}:/runner/project/ \
-v /path/to/inventory_folder:/runner/inventory/ \
-e ANSIBLE_CONFIG='monkeyble-ci.cfg' \
-w /runner/project/ \
my_registry.example/repo/execution-environment-ansible \
monkeyble test

CI/CD example

Github action

Here is a workflow example based on the built execution environment

name: On pull request
on: [pull_request]  # set to this value when pushing in prod

    runs-on: self-hosted

      - name: Checkout the Ansible repo
        uses: actions/checkout@v3

      - name: Run Monkeyble tests
        run: |
          docker run --rm \
          -v ${PWD}:/runner/project/ \
          -v ${PWD}/inventories:/runner/inventory/ \
          -e ANSIBLE_CONFIG='monkeyble-ci.cfg' \
          -w /runner/project/ \
          my_registry.example/repo/execution-environment-ansible \
          monkeyble test