Lab Task 4.1 - Scenario 1 (Catalyst Center)
Cisco Catalyst Center is a centralized management platform designed for Cisco Catalyst network devices. Key features and capabilities include:
- Network Management: Streamlines the configuration and management of Cisco Catalyst switches and wireless networks.
- Automation: Enables automation of network operations, reducing manual tasks and errors.
- Monitoring and Analytics: Provides comprehensive network monitoring and analytics for performance optimization.
- Scalability: Suitable for both small and large-scale network environments.
In this task, you will learn how to create Ansible playbooks and automate Catalyst Center.
This task is separated into the following steps:
- Create a site hierarchy
- Add devices and assign them to a newly created site
Do you ␆? Good to know (Ansible)
Before beginning this task, note that Ansible is used in this tutorial. If you are not familiar with Ansible, please read the following section.
What is Ansible?
Ansible is an open-source automation tool that is used to automate the provisioning, configuration, and management of servers, network devices and other IT infrastructure.
Ansible uses a simple, human-readable language called YAML that can be used to define automation tasks and workflows.
Ansible uses a push-based model, where automation tasks are pushed to the target servers or network devices. It supports a wide range of built-in modules that can be used to automate configuration management and continuous deployments.
Ansible provides a powerful set of features for managing complex automation workflows, including support for variables, loops, and conditionals.
Step 1: Create site hierarchy
It’s time to create some more files as you already did in the previous tasks:
Quick reminder Ansible playbooks always have a .yml extension. Ensure they are named correctly and placed in their designated folders.
1Repository folder pod01 (Folder)
2
3├── dnac (Folder)
4
5├──── data (Folder)
6
7│ └── 01_site-hierarchy.yaml (*File)
8
9└──── playbooks (Folder)
10
11 └── 01_create-site-hierarchy.yml (*File)
1201_create-site-hierarchy.yml
1---
2- hosts: dnac_servers
3 gather_facts: false
4 tasks:
5 - name: Load variables
6 ansible.builtin.include_vars:
7 file: ../data/01_site-hierarchy.yaml
8 name: site_hierarchy
9
10 - name: Create area hierarchy
11 cisco.dnac.site_create:
12 site:
13 area:
14 name: '{{ item.name }}'
15 parentName: '{{ item.parentName }}'
16 type: "area"
17 with_items:
18 - '{{ site_hierarchy.site.area }}'
19 register: site_creation
20
21 - name: Pause
22 pause:
23 seconds: 5
24
25 - name: Create building hierarchy
26 cisco.dnac.site_create:
27 site:
28 building:
29 name: '{{ item.name }}'
30 parentName: '{{ item.parentName }}'
31 latitude: 52.341419
32 longitude: 4.888043
33 type: "building"
34 with_items:
35 - '{{ site_hierarchy.site.building }}'01_site-hierarchy.yaml
Change the POD number to your assigned POD number. The line of code is highlighted.
1---
2site:
3 area:
4 - name: "POD01"
5 parentName: "Global"
6 building:
7 - name: "CiscoLive"
8 parentName: "Global/POD01"
9 latitude: 52.341419
10 longitude: 4.888043.gitlab-ci.yml
1stages:
2 - create_site
3
4create_site:
5 stage: create_site
6 tags:
7 - docker-runner
8 image: cbeye592/ltrato-2600:dnac
9 id_tokens:
10 VAULT_ID_TOKEN:
11 aud: https://198.18.133.99:8200
12 secrets:
13 DNAC_HOST:
14 vault: DNAC/DNAC_HOST@pod01
15 file: false
16 token: $VAULT_ID_TOKEN
17 DNAC_VERIFY:
18 vault: DNAC/DNAC_VERIFY@pod01
19 file: false
20 token: $VAULT_ID_TOKEN
21 DNAC_USERNAME:
22 vault: DNAC/DNAC_USERNAME@pod01
23 file: false
24 token: $VAULT_ID_TOKEN
25 DNAC_PASSWORD:
26 vault: DNAC/DNAC_PASSWORD@pod01
27 file: false
28 token: $VAULT_ID_TOKEN
29 before_script:
30 - source /root/ansible/bin/activate
31 - chmod -R 700 dnac
32 - cd dnac
33 script:
34 - ansible-playbook -i hosts playbooks/01_create-site-hierarchy.ymlValidation
Verify the successful execution in GitLab and confirm that the site has been created in Catalyst Center.
Great job! The site and building have now been successfully created.
Step 2: Add devices
This step adds the device POD01-CAT8KV-01 to the network inventory.
Go back to the DNA Center hamburger menu and check the current state of the inventory: Provision > Inventory
It should be empty for now.
02_add-devices.yml
Create a new file named 02_add-devices.yml in the dnac/playbook directory and add the following content:
1---
2- hosts: dnac_servers
3 gather_facts: false
4 tasks:
5 - name: Set sentitive variables
6 ansible.builtin.set_fact:
7 DEVICE_USER: "{{ lookup('env', 'DEVICE_USER') }}"
8
9 - name: Set sentitive variables
10 ansible.builtin.set_fact:
11 DEVICE_PASSWORD: "{{ lookup('env', 'DEVICE_PASSWORD') }}"
12
13 - name: Set sentitive variables
14 ansible.builtin.set_fact:
15 DEVICE_SNMP_COMMUNITY: "{{ lookup('env', 'DEVICE_SNMP_COMMUNITY') }}"
16
17 - name: Load variables
18 ansible.builtin.include_vars:
19 file: ../data/02_add-devices.yaml
20 name: add_devices
21
22 - name: Receive site details
23 cisco.dnac.site_info:
24 name: '{{ item.name }}'
25 with_items:
26 - '{{ add_devices.site }}'
27 register: site_result
28
29 - name: Set Site ID variable
30 ansible.builtin.set_fact:
31 site_id: "{{ site_result.results[0].dnac_response.response[0].id }}"
32
33 - name: Add Cat8000v to the inventory
34 cisco.dnac.network_device:
35 type: "NETWORK_DEVICE"
36 ipAddress: '{{ item.ipAddress }}'
37 cliTransport: "ssh"
38 userName: '{{ DEVICE_USER }}'
39 password: '{{ DEVICE_PASSWORD }}'
40 snmpVersion: "v2"
41 snmpROCommunity: '{{ DEVICE_SNMP_COMMUNITY }}'
42 snmpRWCommunity: '{{ DEVICE_SNMP_COMMUNITY }}'
43 snmpRetry: 3
44 snmpTimeout: 3
45 enablePassword:
46 computeDevice: false
47 id: ""
48 with_items:
49 - '{{ add_devices.site }}'
50
51 - name: Pause
52 pause:
53 seconds: 5
54
55 - name: Assign the device POD site
56 cisco.dnac.assign_device_to_site:
57 device:
58 - ip: '{{ item.ipAddress }}'
59 siteId: '{{ site_id }}'
60 with_items:
61 - '{{ add_devices.site }}'02_add-devices.yaml
Create a new file named 02_add-devices.yaml in the dnac/data directory and add the following content:
Please check that your values correspond to your POD Number and the correct IP address is set for the device onboarding !
1---
2site:
3 - name: "Global/POD01/CiscoLive"
4 ipAddress: 198.18.1.13.gitlab-ci.yml
Replace the content of the .gitlab-ci.yml file with the following:
1stages:
2 - add_device
3
4add_device:
5 stage: add_device
6 tags:
7 - docker-runner
8 image: cbeye592/ltrato-2600:dnac
9 id_tokens:
10 VAULT_ID_TOKEN:
11 aud: https://198.18.133.99:8200
12 secrets:
13 DNAC_HOST:
14 vault: DNAC/DNAC_HOST@pod01
15 file: false
16 token: $VAULT_ID_TOKEN
17 DNAC_VERIFY:
18 vault: DNAC/DNAC_VERIFY@pod01
19 file: false
20 token: $VAULT_ID_TOKEN
21 DNAC_USERNAME:
22 vault: DNAC/DNAC_USERNAME@pod01
23 file: false
24 token: $VAULT_ID_TOKEN
25 DNAC_PASSWORD:
26 vault: DNAC/DNAC_PASSWORD@pod01
27 file: false
28 token: $VAULT_ID_TOKEN
29 DEVICE_SNMP_COMMUNITY:
30 vault: DNAC/DEVICE_SNMP_COMMUNITY@pod01
31 file: false
32 token: $VAULT_ID_TOKEN
33 DEVICE_USER:
34 vault: DNAC/DEVICE_USER@pod01
35 file: false
36 token: $VAULT_ID_TOKEN
37 DEVICE_PASSWORD:
38 vault: DNAC/DEVICE_PASSWORD@pod01
39 file: false
40 token: $VAULT_ID_TOKEN
41 before_script:
42 - source /root/ansible/bin/activate
43 - chmod -R 700 dnac
44 - cd dnac
45 script:
46 - ansible-playbook -i hosts playbooks/02_add-devices.ymlValidation
Verify in Catalyst Center that the device has been added to your previously created site.
Congratulations on your Catalyst Center pipeline, as you have surely noticed it takes a bit of practice using Cisco Catalyst Center (REST) APIs.
Putting those tasks together in a CI/CD pipeline can help you to speed up your deployments.
Now let’s move on to the Datacenter part!