Professional Documents
Culture Documents
LTRSPG-1192
Cisco Webex App
Questions?
Use Cisco Webex App to chat
with the speaker after the session
How
1 Find this session in the Cisco Live Mobile App
2 Click “Join the Discussion”
3 Install the Webex App or go directly to the Webex space Enter your personal notes here
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 2
• Introduction to Ansible
• Using Ansible
• Command Line, Playbooks & Templates
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 3
Session Objective
• Understanding of the basic principles of Ansible
• Being able to write a playbook including various Ansible concepts
• Getting hands-on experience in using Ansible with IOS-XE, IOS-XR
and NX-OS
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 4
Timetable
• 2:00 pm - 2:30 pm Ansible & Lab Intro
• 2:30 pm - 5:45 pm Lab time
• 5:45 pm - 6:00 pm Wrap up
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 5
Introduction to
Ansible
Ansible Characteristics
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 7
Documentation:
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
Ansible Packaging
• Ansible consists basically of 2 packages
• ansible-core
• ansible
• ‘ansible-core’
• runtime
• fundamental modules & plugins
• ‘ansible’
• Community developed modules
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
Documentation:
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
Installing Ansible
• On Fedora: Upgrade from v2.9 and earlier not possible!
$ sudo dnf install ansible pip3 uninstall ansible
pip3 install ansible
• On RHEL and CentOS:
$ sudo yum install ansible
• Ubuntu
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
• MacOS:
$ pip3 install ansible
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 9
Getting started with Ansible
Servers
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
Using Ansible
Common Ansible Terms
?
Let‘s first cover the
basic terms and concepts.
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 12
Ansible Configuration – ansible.cfg
• The place for adjusting default settings based on your requirements
• Multiple alternative places for parameters and settings exist
• Typically, default settings are sufficient for most users
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 13
Further reading:
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
[csr]
• Where does Ansible look for the inventory file: BRANCH_1_CSR
BRANCH_2_CSR
ansible_host=198.18.1.12
ansible_host=198.18.1.22
• Option 1 (Default): /etc/ansible/hosts [switch]
BRANCH_1_SWITCH ansible_host=198.18.1.11
• Option 2: “inventory” parameter in local ansible.cfg BRANCH_2_SWITCH ansible_host=198.18.1.21
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 14
Further reading:
https://docs.ansible.com/ansible/latest/user_guide/modules.html
https://docs.ansible.com/ansible/latest/modules/modules_by_category.html
Modules
• Prepared “scripts“ performing actions on a host
• E.g. Commands, APIs
• Majority of modules ship with Ansible
• Starting from 2.10 modules are grouped in collections
• You can write your own modules
Network modules per Ansible
version
2000
1500
1000
500
0
2.5 2.6 2.7 2.8 2.9
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 15
Further reading:
https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html
https://docs.ansible.com/ansible/latest/modules/ping_module.html
Ad-hoc Commands
• Allows you to execute tasks quickly without saving steps
• Useful to understand the basics of how Ansible works
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 16
Further reading:
https://docs.ansible.com/ansible/latest/user_guide/playbooks.html
Playbooks
$ cat sample.yaml
---
• Ansible‘s method of procedures (MoP) - hosts: control
gather_facts: no
connection: local
• Playbooks store task sequences for later reuse tasks:
- name: PING ANSIBLE CONTROL
• Can have one or more plays and tasks ping:
$ ansible-playbook sample.yaml
PLAY [control]
**********************************************************************************************************************
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 17
Further reading:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_templating.html
Jinja2 Templates
• Jinja2 templates further enhance modelling $ cat ios_interface.yaml
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 18
Typical Folder Structure
YAML playbooks
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 19
Lab Introduction
dCloud Lab Setup
• Control node: Ansible VM based on Ubuntu
• Managed nodes: 1 XRv core router, 2 CSR1kv branch routers, 2 NX-OSv switches, 2 sever
VMs
• Student VM: Windows with Atom text editor, Putty SSH client
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 21
Lab Scenario
Exercise Ansible Concepts & Objectives
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 22
Lab Access
• Use the Cisco AnyConnect Client and your provided VPN username and
password to connect to your lab instance
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 23
Windows VM
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 24
Atom editor 1
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 26
Lab Guide http://cs.co/ltrspg1192
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 27
Things to keep in mind
• No best practices
• Lab guide provides less and less help
• Be careful when copy and paste:
indentation is important
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 28
Lab Time
Ansible
vs.|&
Cisco
NSO
10,000-feet Comparison
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 31
Further reading:
Ansible Playbooks
NSO
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 32
Exercise 1 - Location matters!
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 33
Exercise 2 – To quote or not to quote
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 34
Exercise 3 – Prefer more specific modules
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 35
Complete your Session Survey
• Please complete your session survey
after each session. Your feedback
is important.
• Complete a minimum of 4 session
surveys and the Overall Conference
survey (open from Thursday) to
receive your Cisco Live t-shirt.
• All surveys can be taken in the Cisco Events Mobile App or
by logging in to the Session Catalog and clicking the
"Attendee Dashboard” at
https://www.ciscolive.com/emea/learn/sessions/session-catalog.html
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 36
Continue
Agenda Your Education
LTRSPG-1192 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 37
Thank you