Trigger VyOS basic tasks via Gitlab
This lab requires attendees to run same VyOS basic deployment playbook again as they did on day 2 but this time trigger via Gitlab instead of Ansible command line.
Step 1 - Ensure previous lab task has been completed and Ansible container exists at the container registry
Step 2 - Ensure vyos-basic-setup.yml playbook exists at desired path i.e /home/a01/git-repo/vyos-basic-setup.yml
Step 3 - Ensure inventory file exists at the desired path i.e /home/a01/git-repo/inventory
Note: These paths/files names can be changed but the same must be reflecting at Gitlab CI/CD configuration.
Step 4 - Update .gitlab-ci.yml This can be done locally & changes can be pushed. It is advised to do this via Gitlab itself so that integrated linter can be used.
Add a new stage in existing file for this
stages:
- Docker build
- Setup
Next, add the job to trigger the playbook using Ansible docker image:
vyos_basic_setup:
image: "$CI_REGISTRY_IMAGE:latest"
stage: Setup
script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- ansible-playbook -i inventory vyos-basic-setup.yml
- exit
when: manual
Step 5 - Add your SSH private key from server on Gitlab as a variable cat /home/a01/.ssh/id_rsa select the output and copy. Next go to your Gitlab project > Settings (from left sidebar) > CI/CD > Variables and click expand. Click on add variable Add the key as - SSH_PRIVATE_KEY and paste your SSH private key from server as the value and click add.
Next, trigger this playbook manually from web UI and ensure it works.