Table of Contents
Git pull from GitHub
Its time to get some ACI config deployed via Ansible but we are not here to write some Ansible code.
Lets sync from a GitHub repo where everything is already prepared.
cd
git clone https://github.com/beye91/aci-ansible-test.git
rm -rf aci-ansible-test/.git
Cloning into 'aci-ansible-test'...
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 22 (delta 0), reused 22 (delta 0), pack-reused 0
Unpacking objects: 100% (22/22), 6.91 KiB | 1.15 MiB/s, done.
Git pull from GitLab
In order to clone our project from the GitLab repo. Click on Repository > Files > Clone > Copy URL
Now copy the link that you copied into the “git clone” command.
cd
git clone "YOUR-URL"
Cloning into 'aci-ansible-cicd'...
Username for 'http://198.18.134.28': root
Password for 'http://root@198.18.134.28':
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 12 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), 3.82 KiB | 1.27 MiB/s, done.
You should see the following files:
cd aci-ansible-cicd
ls -la
drwxrwxr-x 4 cisco cisco 4096 Aug 9 20:10 .
drwxr-xr-x 18 cisco cisco 4096 Aug 9 20:10 ..
drwxrwxr-x 8 cisco cisco 4096 Aug 9 20:11 .git
-rw-rw-r-- 1 cisco cisco 371 Aug 9 19:47 .gitlab-ci.yml
-rw-rw-r-- 1 cisco cisco 19 Aug 9 19:30 README.md
Copy all files from the cloned GitHub repository to our cloned GitLab repository:
cp -r ../aci-ansible-test/* .
ls -la
drwxrwxr-x 4 cisco cisco 4096 Aug 9 20:10 .
drwxr-xr-x 18 cisco cisco 4096 Aug 9 20:10 ..
-rw-rw-r-- 1 cisco cisco 2153 Aug 9 19:49 ansibledata.yml
-rw-rw-r-- 1 cisco cisco 740 Aug 9 20:10 create_snapshot.yml
drwxrwxr-x 8 cisco cisco 4096 Aug 9 20:11 .git
-rw-rw-r-- 1 cisco cisco 371 Aug 9 19:47 .gitlab-ci.yml
-rw-rw-r-- 1 cisco cisco 433 Aug 9 19:36 hosts
-rw-rw-r-- 1 cisco cisco 697 Aug 9 19:30 playbook.yml
-rw-rw-r-- 1 cisco cisco 19 Aug 9 19:30 README.md
-rw-rw-r-- 1 cisco cisco 61 Aug 9 19:30 requirements.yml
drwxrwxr-x 3 cisco cisco 4096 Aug 9 19:31 roles
-rw-rw-r-- 1 cisco cisco 1064 Aug 9 19:30 usage_info.txt
Git push to GitLab
Push the local changes to the GitLab repository and type your username and password for the GitLab:
git add * && git commit -m 'Commit' && git push
Username for 'http://198.18.134.28': root
Password for 'http://root@198.18.134.28':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 640 bytes | 640.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To http://198.18.134.28/gitlab-instance-6ab63a11/aci-ansible-cicd.git
9bdae3c..45d6198 main -> main
Change the pipeline
Open the pipeline editor from CI/DC > Editor:
Replace the entire code with the following:
workflow:
rules:
- if: $CI_COMMIT_BRANCH != "main" && $CI_PIPELINE_SOURCE != "merge_request_event"
when: never
- when: always
stages:
- deploy_aci_config
run_ansible_playbook:
stage: deploy_aci_config
tags:
- shell
before_script:
- ansible-galaxy collection install cisco.aci
script:
- ansible-playbook -i hosts playbook.yml
Commit the changes and check the pipeline status:
Click on the run_ansible_playbook to see what has been executed. As it was successful, login to the APIC GUI and check the tenant config:
Awesome!! Our pipeline execution was successful! 🥳