Return to your VSCode application window. It is now time to setup and initialize your Git repo.
Ensure you are at the top level directory for your project folder:
cd /home/cisco/Documents/nxapilab/
Set your Git global settings:
git config --global user.name "POD-06"
git config --global user.email "user06@ciscolive.com"
git config --global init.defaultBranch main
Initialize your local project directory as git repo:
git init
Add the remote pointer to your Git repo:
git remote add origin git@10.0.208.215:CL-POD06/LTRDCN-3903.git
In Git repos, it is very common to have a hidden file called .gitignore
. This is a reserved filename and it is used to
ignore specific file extensions and/or directories from being added to the Git repo. An example of a specific file you do not want added to your
Git repo is your .python-version
hidden file that specifies your pyenv environment.
touch /home/cisco/Documents/nxapilab/.gitignore
cat <<EOF >> /home/cisco/Documents/nxapilab/.gitignore
*.env
scripts/
tests/results/*.zip
# VScode
.vscode/*
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# pyenv
.python-version
EOF
As you previously stepped through building out your infrastructure as code with Ansible, there were host specific variables created for your staging spine switch and leaf switches. Again, host specific in this case is switch specific. The Ansible roles you created are agnostic to the fabric they are run against. So, you need to simply create the host specific variable files for the prod fabric switches. Since the staging fabric is a development fabric and thus a mirror image of your prod fabric, you simply need to copy the each host specific file for staging to its prod counterpart.
cp ansible-nxos/host_vars/10.15.6.11.yml ansible-nxos/host_vars/10.15.6.14.yml
cp ansible-nxos/host_vars/10.15.6.12.yml ansible-nxos/host_vars/10.15.6.15.yml
cp ansible-nxos/host_vars/10.15.6.13.yml ansible-nxos/host_vars/10.15.6.16.yml
sed -i '0,/^\([[:space:]]*hostname: *\).*/s//\hostname: prod-spine1/;' ansible-nxos/host_vars/10.15.6.14.yml
sed -i '0,/^\([[:space:]]*hostname: *\).*/s//\hostname: prod-leaf1/;' ansible-nxos/host_vars/10.15.6.15.yml
sed -i '0,/^\([[:space:]]*hostname: *\).*/s//\hostname: prod-leaf2/;' ansible-nxos/host_vars/10.15.6.16.yml
As discussed in the previous step, the Ansible host file needs to be created for prod as you did for staging.
touch /home/cisco/Documents/nxapilab/ansible-nxos/prod.yml
cat <<EOF >> /home/cisco/Documents/nxapilab/ansible-nxos/prod.yml
# hosts file for Ansible playbook
---
all:
children:
spines:
hosts:
10.15.6.14:
leafs:
hosts:
10.15.6.15:
10.15.6.16:
EOF
And finally, the pyATS testbed YAML file needs to be created for your prod fabric so that the tests can run against your prod fabric.
touch /home/cisco/Documents/nxapilab/tests/prod-testbed.yaml
cat <<EOF >> /home/cisco/Documents/nxapilab/tests/prod-testbed.yaml
---
testbed:
name: NX-API Prod Lab
alias: Prod
credentials:
default:
username: admin
password: cisco.123
devices:
prod-spine1:
alias: n9kv-s1
type: switch
os: nxos
platform: n9k
connections:
defaults:
via: rest
ssh:
protocol: ssh
ip: 10.15.6.14
rest:
class: rest.connector.Rest
protocol: https
ip: 10.15.6.14
prod-leaf1:
alias: n9kv-l1
type: switch
os: nxos
platform: n9k
connections:
defaults:
via: rest
ssh:
protocol: ssh
ip: 10.15.6.15
rest:
class: rest.connector.Rest
protocol: https
ip: 10.15.6.15
prod-leaf2:
alias: n9kv-l2
type: switch
os: nxos
platform: n9k
connections:
defaults:
via: rest
ssh:
protocol: ssh
ip: 10.15.6.16
rest:
class: rest.connector.Rest
protocol: https
ip: 10.15.6.16
EOF
After initializing your Git repo and creating the files specific to your prod fabric, it is time to add these files with Git in preparation for commiting them to the repo.
You perform the action of adding files with git add
. You will add your ansible-nxos
and tests
directories. Again, the Ansible playbooks and
pyATS tests are not specific to either fabric and are designed to work on either fabric. Lastly, you'll add your .gitignore
file. You may notice the removal of the hidden
Travis YAML files. Ansible Galaxy creates these by default for Travis CI which is another option as a CI/CD platform. Since we're using GitLab for this lab, we're simply going to remove them.
rm -rf ansible-nxos/roles/common/.travis.yml
rm -rf ansible-nxos/roles/underlay/.travis.yml
rm -rf ansible-nxos/roles/overlay/.travis.yml
git add ansible-nxos/
git add tests/
git add .gitignore
With your directories and files added, you can now commit them to your Git repo with git commit
.
The -m
option is for a comment/message for the comment.
git commit -m "Initial commit"
Finally, with your project directory initialized as a Git repo, your files added and committed, you can push everything to your Git repo on the GitLab instance.
git push -u origin main
Enumerating objects: 65, done. Counting objects: 100% (65/65), done. Delta compression using up to 8 threads Compressing objects: 100% (40/40), done. Writing objects: 100% (65/65), 10.84 KiB | 853.00 KiB/s, done. Total 65 (delta 8), reused 0 (delta 0), pack-reused 0 To 10.0.208.215:CL-POD05/LTRDCN-3903.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
Return to GitLab. Your may have to refresh the browswer window. Your GitLab repo should now looks similar to the screenshot below with the directories and files you just pushed now stored in source control:
Continue to the next section to setup your GitLab CI file for the CI/CD pipeline.