Skip to content

Instantly share code, notes, and snippets.

@titom73
Created September 5, 2019 09:31
Show Gist options
  • Save titom73/d450d32f6f5d85ae8fc25bd255b4be15 to your computer and use it in GitHub Desktop.
Save titom73/d450d32f6f5d85ae8fc25bd255b4be15 to your computer and use it in GitHub Desktop.
Ansible Collection CI
image: inetsix/docker-ansible:2.7
stages:
- environment.build
- analysis.environment
- ansible.build
- test
- ansible.publish
- clean
#######################
# Template management #
#######################
.test_ansible_bootstrap: &test_ansible_bootstrap
tags:
- arista
- emea
- cvp
before_script:
- source .venv/bin/activate
- cd .ci
- sed -i -e "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/$CVP_SERVER/g" env.lab
- cd ..
- chmod 755 tests
- cd tests
- sed -i -e "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/$CVP_SERVER/g" inventory.ini
- cat inventory.ini
#######################
# CI MANAGEMENT #
#######################
ENVIRONMENT.BUILD:
# Deploy all requirements for the pipeline.
stage: environment.build
tags:
- arista
- emea
script:
- pip install virtualenv
- virtualenv -p $(which python) .venv
- source .venv/bin/activate
- pip install -r requirements.txt
- pip install git+https://github.com/ansible/ansible.git@devel
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
ENVIRONMENT.VERSION:
# Test if we are using correct virtual environment
stage: analysis.environment
tags:
- arista
- emea
script:
- source .venv/bin/activate
- ansible --version
- python --version
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
COLLECTION.BUILD:
# Test if cvprac enhancements are correctly deployed.
stage: ansible.build
tags:
- arista
- emea
script:
- source .venv/bin/activate
- cd arista/cvp/
- ansible-galaxy collection build --force
- mv *.tar.gz ../../tests/
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
artifacts:
expire_in: 1 week
paths:
- "tests/*.tar.gz"
CVP_MODULE.DOCUMENTATION:
# Allow to check if modules are seen by ansible
stage: test
<<: *test_ansible_bootstrap
dependencies:
- COLLECTION.BUILD
script:
- ansible-galaxy collection install *.tar.gz -p collections/ansible_collections/
- ansible-doc -t module arista.cvp.cv_device
- ansible-doc -t module arista.cvp.cv_container
- ansible-doc -t module arista.cvp.cv_configlet
- ansible-doc -t module arista.cvp.cv_image
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
CVP_MODULE.CONTAINER:
# Test cv_container module
stage: test
<<: *test_ansible_bootstrap
dependencies:
- COLLECTION.BUILD
script:
- ansible-galaxy collection install *.tar.gz -p collections/ansible_collections/
- ansible-playbook playbook.container.demo.yaml -i inventory.ini --syntax-check
- ansible-playbook playbook.container.demo.yaml -i inventory.ini
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
CVP_MODULE.CONFIGLET:
# Test cv_container module
stage: test
<<: *test_ansible_bootstrap
dependencies:
- COLLECTION.BUILD
script:
- ansible-galaxy collection install *.tar.gz -p collections/ansible_collections/
- ansible-playbook playbook.configlet.demo.yaml -i inventory.ini --syntax-check
- ansible-playbook playbook.configlet.demo.yaml -i inventory.ini
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
CVP_MODULE.DEVICE:
# Test cv_device module
# Since TASKs are not run by ansible, it is required to insert a 3rd part
# script to execute changes. Script will list available tasks for validation
# and execute all pending tasks.
# Every task will require a reboot, so script wait 4 minutes for complete
# reboot of the vEOS VM.
stage: test
<<: *test_ansible_bootstrap
dependencies:
- COLLECTION.BUILD
script:
- pip install inetsix-arista-cvp==0.3.3
- source ../.ci/env.lab
- ansible-galaxy collection install *.tar.gz -p collections/ansible_collections/
- ansible-playbook playbook.device.demo.yaml -i inventory.ini --syntax-check
- ansible-playbook playbook.device.demo.yaml -i inventory.ini --tags=create
- cvp-task-manager -l
- cvp-task-manager -ra
- ansible-playbook playbook.device.demo.yaml -i inventory.ini --tags=show
- ansible-playbook playbook.device.demo.yaml -i inventory.ini --tags=rollback
- cvp-task-manager -l
- cvp-task-manager -ra
- ansible-playbook playbook.device.demo.yaml -i inventory.ini --tags=clean
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
#######################
# ENV Cleanup #
#######################
ENVIRONMENT.CLEAN:
stage: clean
tags:
- arista
- emea
script:
- rm -rf .venv/*
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .venv/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment