Professional Documents
Culture Documents
Introduction to Ansible Network Automation: A Practical Primer Brendan Choi full chapter instant download
Introduction to Ansible Network Automation: A Practical Primer Brendan Choi full chapter instant download
https://ebookmass.com/product/introduction-to-ansible-network-
automation-a-practical-primer-brendan-choi/
https://ebookmass.com/product/introduction-to-software-testing-a-
practical-guide-to-testing-design-automation-and-execution-1st-
edition-panagiotis-leloudas/
https://ebookmass.com/product/supply-network-5-0-how-to-improve-
human-automation-in-the-supply-chain-bernardo-nicoletti/
https://ebookmass.com/product/introduction-to-prescriptive-ai-a-
primer-for-decision-intelligence-solutioning-with-python-akshay-
kulkarni/
Learn Engineering with LEGO: A Practical Introduction
to Engineering Concepts Grady Koch
https://ebookmass.com/product/learn-engineering-with-lego-a-
practical-introduction-to-engineering-concepts-grady-koch/
https://ebookmass.com/product/enzymes-a-practical-introduction-
to-structure-mechanism-and-data-analysis-3rd-edition-robert-a-
copeland/
https://ebookmass.com/product/psychophysics-second-edition-a-
practical-introduction-kingdom/
https://ebookmass.com/product/enabling-tools-and-techniques-for-
organic-synthesis-a-practical-guide-to-experimentation-
automation-and-computation-stephen-g-newman-s-g-ed/
https://ebookmass.com/product/etextbook-978-1305947412-
spreadsheet-modeling-decision-analysis-a-practical-introduction-
to-business-analytics/
Introduction to Ansible
Network Automation
A Practical Primer
Brendan Choi
Erwin Medina
Introduction to Ansible Network Automation: A Practical Primer
Brendan Choi Erwin Medina
Sydney, NSW, Australia Sydney, NSW, Australia
Acknowledgments�������������������������������������������������������������������������������������������������xvii
Introduction������������������������������������������������������������������������������������������������������������xix
iii
Table of Contents
iv
Table of Contents
v
Table of Contents
Chapter 6: Learning Ansible Basic Concepts I: SSH and Ad Hoc Commands������� 259
6.1 SSH Overview and Setup in Ansible������������������������������������������������������������������������������������ 260
6.1.1 Configuring SSH for Ansible: General Steps��������������������������������������������������������������� 260
6.1.2 Understanding the Ansible SSH Concept�������������������������������������������������������������������� 262
6.1.3 Practical Usage of SSH in Ansible������������������������������������������������������������������������������ 263
6.2 Running Ad Hoc Commands on Linux Devices with Ansible����������������������������������������������� 274
6.3 Running Ad Hoc Commands on Routers and Switches with Ansible���������������������������������� 277
6.4 Running Elevated Ad Hoc Commands with Ansible������������������������������������������������������������� 278
6.5 Summary���������������������������������������������������������������������������������������������������������������������������� 281
vi
Table of Contents
Chapter 9: Learning Ansible Basic Concepts III: Git, Tags, Managing Files,
and Services��������������������������������������������������������������������������������������������������������� 403
Getting Started with GitHub������������������������������������������������������������������������������������������������������ 404
9.1 Creating and Uploading Playbooks to GitHub, Featuring cowsay���������������������������������������� 407
9.2 Ansible Tags Explained�������������������������������������������������������������������������������������������������������� 423
9.3 Managing Files�������������������������������������������������������������������������������������������������������������������� 428
9.4 Managing Services������������������������������������������������������������������������������������������������������������� 436
9.5 Copying and Updating Text Files with Ansible Playbook����������������������������������������������������� 445
9.6 Use GitHub to Back Up Your Files���������������������������������������������������������������������������������������� 456
9.7 Summary���������������������������������������������������������������������������������������������������������������������������� 457
Chapter 10: Learning Ansible Basic Concepts IV: Users, Roles, Host Variables,
Templates, and Password Vault���������������������������������������������������������������������������� 459
10.1 Users��������������������������������������������������������������������������������������������������������������������������������� 462
10.2 Roles��������������������������������������������������������������������������������������������������������������������������������� 477
10.3 Variable Options in Ansible������������������������������������������������������������������������������������������������ 486
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
Chapter 17: Creating User Accounts on Palo Alto and Fortinet Firewalls������������� 793
17.1 Use Ansible Vault to Encrypt Sensitive Information���������������������������������������������������������� 796
17.2 Administrator Account Creation on Palo Alto Firewalls: From Manual to Automation������� 799
17.3 Writing a YAML Playbook to Create an Administrator Account on a Palo Alto Firewall����� 801
17.4 Running the YAML Playbook to Create an Administrator Account on a Palo Alto
Network Firewall��������������������������������������������������������������������������������������������������������������� 807
17.5 Administrator Account Creation on Fortinet Firewalls: From Manual to Automation�������� 811
17.6 Writing a YAML Playbook to Create an Administrator Account on a Fortinet Firewall������� 812
17.7 Running the YAML Playbook to Create an Administrator Account on a
Fortinet Firewall���������������������������������������������������������������������������������������������������������������� 817
17.8 Summary�������������������������������������������������������������������������������������������������������������������������� 821
x
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 925
xi
About the Authors
Brendan Choi is a highly accomplished tech lead at Secure
Agility, with over 19 years of hands-on experience in the
ICT industry. He is a certified Cisco, VMware, and Fortinet
Engineer and has worked for renowned enterprises such
as Cisco Systems, NTT (Dimension Data), and Fujitsu, as
well as reputable Australian IT integrators like Telstra and
Secure Agility. Brendan specializes in optimizing enterprise
IT infrastructure management and enterprise business
process optimization, utilizing both open and proprietary
tools. He is the author of Python Network Automation: By
Building an Integrated Virtual Lab as well as Introduction
to Python Network Automation: The First Journey. Through these publications, Brendan
shared his knowledge with the IT community. He has trained over 200 network and
systems engineers on Python and Ansible Network Automation and enjoys sharing
industry-acquired knowledge through social media, blogging, and his YouTube channel.
Brendan’s current interests revolve around private cloud, enterprise networking,
security, virtualization, Linux, and automation technologies. His dedication and passion
for enterprise infrastructure management are evident in his commitment to continuous
learning, knowledge sharing, and contributing to the ICT industry as a whole.
xiii
About the Authors
xiv
About the Technical Reviewer
Nikhil Jain is an Ansible expert with over 12 years of DevOps
experience. He has been using Ansible and contributing to
it from its inception. He currently works closely with Ansible
Engineering.
He is an open source enthusiast and is part of the Ansible
Pune Meetup organizing team. He has presented multiple
Ansible sessions at various global and local events. Apart
from sitting in front of his computer automating things using
Ansible, he loves watching sports and is a regular part of the
local cricket team.
xv
Acknowledgments
I would like to express my heartfelt gratitude to Ty Starr at Telstra Purple and Kai
Schweisfurth at Ethan Group, my previous team managers, for providing me with the
opportunities to work with my former teams. Under Ty’s stewardship, I was able to
teach myself how to use Ansible for automation and knowledge share. Similarly, under
Kai’s guidance, I developed a passion for network automation using Python and eagerly
shared my learnings with my colleagues. I would also like to extend my thanks to my
former colleague, Justin Cheong at Mastercard, who consistently encouraged me to
write my first book and gave me the courage to become a published author. My deepest
appreciation goes to my coauthor, Erwin Medina, for his unwavering dedication, hard
work, and expertise, which greatly contributed to the completion of this book. I am also
grateful to my wife, Sue, and our children, Hugh, Leah, and Caitlin, for their unwavering
support throughout the process of creating this book. Their love and understanding
have been my pillars of strength. To my extended family, friends, and colleagues, I would
like to express my sincere thanks for your constant support. Lastly, I want to thank our
readers for embarking on their incredible network automation journey with us.
—Brendan Choi
I cannot express enough thanks to Brendan Choi for continuously mentoring me and
taking me under his wings to go through this journey. His passion, dedication, and drive
to accomplish this book to primarily teach and inspire serve to be the greatest part for
me. He taught me the valuable lesson of learning, sharing, and inspiring. I would like
to thank my wife, Jenny, and my son, Deon, for their support and prayers throughout
this process. To my friends and colleagues who have become like family, I extend my
heartfelt gratitude. To the readers, I sincerely thank you, and I hope that this book will
provide help and inspiration as you embark on your journey, just as I was inspired by
Brendan.
—Erwin Medina
xvii
Introduction
The use of Ansible in enterprise network administration has gained significant
popularity among leading IT organizations. It is recognized as the most effective tool for
automating network devices within a short time frame, revolutionizing the way network
administrators manage their infrastructure. In response to this growing demand, we
present Introduction to Ansible Network Automation: A Practical Primer, a book that
offers readers a structured learning path to build a solid foundation in Ansible.
Written by real ICT professionals for true ICT professionals, this book cuts
through the fluff and delivers practical knowledge without false assumptions. We
have written this book based on the assumption that all our readers enjoy working in
the ICT industry and prefer a hands-on learning approach over a purely theoretical one.
This book is not for the faint-hearted but is designed for individuals with an unwavering
“never-say-die” attitude who refuse to give up at work and in their lives. We aim to
provide an authentic experience, taking readers on the actual journey of acquiring
network automation skills using Ansible from the ground up.
While there are numerous Linux and network Ansible automation resources
available, most of them assume that readers have already reached an adequate skill level
to start writing working YAML code from day one. These resources rarely show what it
takes to reach that level and often focus solely on selling the dream of Ansible without
discussing the effort and challenges involved. Our book offers a truthful approach,
immersing readers in the journey and allowing them to feel what it’s like to acquire
network automation skills using Ansible. They will install and configure everything
themselves, follow along with the book, make mistakes, stumble, and ultimately push
themselves to learn the necessary skills to become comfortable with using Ansible
playbooks and YAML scripts.
As you can tell from the title, this book serves as a sequel to Introduction to Python
Network Automation: The First Journey by Brendan Choi. Both titles are indispensable
resources for IT professionals and students seeking to enhance their automation skills
and apply them in real-world scenarios in enterprise production networks. This book
provides a comprehensive learning journey, guiding readers to master Ansible and
utilize it for automating enterprise network devices such as routers, switches, firewalls,
xix
Introduction
Wireless LAN Controllers (WLCs), and Linux servers. What sets this book apart is
its laser-focused emphasis on Linux, Ansible, and network automation; really, we
have squeezed three basic books into one! It is specifically designed for IT engineers
and students who want to get hands-on experience and build an Ansible Network
Automation lab from scratch. Real-life examples of Ansible playbooks developed from
actual enterprise infrastructure are provided, giving readers a thorough understanding
of how Ansible can be effectively utilized in the real world.
By engaging with this book, readers will acquire valuable knowledge and skills in
network automation using Ansible. The book takes readers on a structured learning
path, gradually building their understanding and proficiency in Ansible. Firstly,
readers will develop a comprehensive understanding of Ansible and its essential
concepts for automating network devices. They will learn how to apply these concepts
to real-world scenarios, gaining the skills required to automate enterprise network
devices effectively. Secondly, readers will master the basics of Ansible operations
within Linux automation and progress to applying Ansible concepts to network
devices. They will establish a solid foundation for network automation tasks by
navigating and utilizing Ansible within the Linux environment. Thirdly, readers will
learn to develop and execute Ansible ad hoc commands and playbooks for various
network operations, including configuration management, software updates,
and system monitoring. Through practical examples and exercises, readers will gain
hands-on experience in crafting Ansible playbooks to automate critical network tasks.
Next, readers will work with real-life examples of Ansible playbooks developed
from enterprise infrastructure. This practical experience will enable them to write
Ansible YAML scripts confidently, ensuring they are well prepared to tackle network
automation challenges in real-world environments. Lastly, readers will acquire the
skills necessary to automate network operations using Ansible in selective scenarios
for enterprise production environments. They will gain insights into streamlining
network management processes and transitioning from manual tasks to full automation,
enhancing efficiency and productivity. Through the content and exercises provided in
this book, readers will be equipped with the knowledge and skills to effectively apply
Ansible in network automation, empowering them to navigate the ever-evolving world of
network administration with confidence and proficiency.
xx
Introduction
We designed this book for diverse readers seeking to enhance their network
automation skills using Ansible. It caters to IT students, network engineers, and
developers managing IP services, networking devices, servers, cloud, and data centers.
Technical leaders implementing network automation, mentors training team members,
instructors teaching network automation, and Cisco Networking Academy students
pursuing certifications in network administration will find value in this book. It targets
those interested in integrating network automation into their development process and
offers practical knowledge for a wide readership. By leveraging Ansible, readers can learn
and apply network automation techniques effectively. Join us on this journey to expand
your network automation capabilities and unlock new possibilities in your work.
xxi
CHAPTER 1
Is Ansible Good
for Network Automation?
This chapter offers a brief overview of the current trends in the networking industry and
the reasons why Ansible has become a popular tool for enterprise IT configuration and
orchestration. The authors introduce Ansible, explaining its workings at a high level
and its relevance to working IT engineers, operations managers, as well as to business
stakeholders from a commercial stance. The chapter also lays out a comprehensive
study plan that will guide readers through the technologies and help them improve their
skills. Moreover, the chapter delves into the basic hardware and software required to
embark on an Ansible automation journey. It provides information on the minimum PC/
laptop requirements needed to build a fully working Ansible/Linux/network automation
lab on a single laptop, along with a recommended software set for installing virtual
devices such as Linux servers, routers, switches, and firewalls. By the end of this chapter,
readers will have a solid understanding of why Ansible is important to the Information
and Communication Technology (ICT) industry, what they need to know to become
proficient in it, and what resources they require to build their own Ansible lab. This
chapter will serve as the foundation for the subsequent chapters in the book, allowing
readers to develop their skills and knowledge in a structured and organized manner.
3
© Brendan Choi and Erwin Medina 2023
B. Choi and E. Medina, Introduction to Ansible Network Automation,
https://doi.org/10.1007/978-1-4842-9624-0_1
Another random document with
no related content on Scribd:
Pilkkasiko tuo nainen häntä? Hänen äänessään oli säilynyt
eräänlainen walesilainen terävyys huolimatta kaikesta lännen
vaikutuksesta. Jospa hän tiesi? Ja samassa Ashurst ajatteli: "Ei! ei!
lähden tieheni täältä. En rupea asettamaan itseäni niin
luonnottomaan, kieroon asemaan."
"Kyllä."
"Miten siis?"
"En."
"Niin on, kyllä nyt heinä kasvaa. Tänä vuonna ovat saarnet
myöhäisempiä kuin tammet. Kun tammi ehtii lehteen ennen kuin
saarnit —"
"Mitä tarkoitatte?"
Kello oli sinä iltana lähes kaksitoista, kun Ashurst laski käsistään
"Odysseiansa" (taskukokoa), jota oli puolen tunnin ajan pidellyt
käsissään sitä kuitenkaan lukematta, ja hiipi pihamaan poikki
hedelmäpuutarhaan. Kuu oli vast'ikään kullanhohteisena noussut
kukkulan yläpuolelle ja kurkisti kuin loistava, valvova henki saarnen
puolipaljaiden oksien lomasta. Omenapuiden varjossa oli vielä
pimeää; Ashurst pysähtyi tutkimaan, mihin suuntaan hänen oli
kuljettava, ja tunnusteli maata jalallaan. Aivan hänen takanaan
liikahti tumma röykkiö kumeasti röhkien: kolme suurta sikaa paneutui
takaisin vierekkäin pitkäkseen muurin vierustalle. Ashurst kuunteli.
Oli aivan tyyni, mutta joen hiljainen, iloinen solina kuului paljon
voimakkaammin kuin päivällä. Jokin yölintu — hän ei tuntenut sitä —
piipitti yksitoikkoisesti. Kaukana kuului ruisrääkkä ääntelevän.
Yksinäinen pöllö huusi. Ashurst astui pari askelta eteenpäin ja
pysähtyi taaskin tuntien päänsä ympärillä sumuista valkeutta.
Tummissa, liikkumattomissa puissa oli lukematon määrä umppuja ja
kukkia pehmeinä ja epämääräisinä vironnut elämään hiipimässä
kuunvalossa. Ashurstilla oli omituinen tunne, että hänellä oli seuraa,
ikäänkuin miljoonittain valkoisia perhosia tai henkiä olisi asettunut
tumman taivaan ja vielä tummemman maan väliin aukoen ja sulkien
siipiään hänen silmiensä korkeudella. Hetken huumaavassa,
hiljaisessa, tuoksuttomassa kauneudessa hän melkein unohti, miksi
oli tullut puutarhaan. Se värisevä loisto, johon päivä oli pukenut
luonnon, ei ollut hävinnyt yön tullen, oli vain saanut tämän uuden
muodon. Hän käveli eteenpäin runkojen ja oksien lomitse, joita
verhosi tuo elävä valkeus, ja pääsi vihdoin ison omenapuun juurelle.
Hän ei voinut erehtyä siitä edes pimeässä, sillä se oli muita lähes
toista vertaa korkeampi ja laajempi ja ojenteli oksiaan kauas kedolle
ja purolle päin. Sen tiheiden oksien alla hän pysähtyi uudelleen
kuuntelemaan. Kuului taaskin samat äänet kuin äsken — myöskin
unisten sikojen heikkoa röhkinää. Hän laski kätensä paksulle,
melkein lämpimälle puunrungolle, jonka karhea, sammaleinen pinta
tuoksahti heikosti turpeelle hänen sitä koskettaessa. Tuleekohan
tyttö — niin, mahtaakohan hän tulla? Ja seistessään värisevien,
kuunvalossa aavemaisina, kuin lumottuina kohoavien puiden
keskellä hän alkoi epäillä kaikkea. Kaikki oli täällä kuin yliluonnollista,
sopimatonta maisille rakastaville. Tämä seutu sopi vain jumalille ja
jumalattarille, fauneille ja nymfeille — ei hänelle ja nuorelle
maalaistytölle. Eiköhän hän melkein tuntisi mielenhuojennusta, jos
tyttö jäisi tulematta. Mutta kaiken aikaa hän kuulosteli. Tuntematon
lintu piipitti ja kuului solinaa pikku purosta, jonka pinnalle kuu loi
katseitaan puun oksaverkon takaa. Hänen silmiensä korkeudella
näyttivät omenankukat käyvän joka hetki yhä elävämmiksi, tuntuivat
salaperäisessä valkeassa kauneudessaan yhä enemmän ikäänkuin
muuttuvan osaksi hänen omaa jännittynyttä odotustaan. Hän katkaisi
pienoisen oksan — kolme kukkaa. Pyhyydenloukkausta poimia
hedelmäpuiden kukkasia — pehmeitä, pyhiä nuoria kukkasia — ja
heittää ne pois. Samassa hän kuuli veräjän narahtavan; siat
liikahtivat taaskin rohkaisten; ja nojautuen puunrunkoon Ashurst
painoi kätensä sen sammaliseen kupeeseen pidättäen hengitystään.
Tuntui kuin tyttö olisi ollut henki, joka leijui puiden lomitse — niin
äänettömästi hän liikkui. Samassa Ashurst näki hänet aivan
lähellään — näki hänen tumman hahmonsa ikäänkuin osana
pienestä puusta, hänen valkoiset kasvonsa kuin osana sen
kukkasista. Tyttö oli aivan ääneti ja katsoi häntä kohti. Ashurst
kuiskasi: "Megan!" ja ojensi kätensä. Tyttö syöksähti eteenpäin,
suoraan hänen rintaansa vasten. Kun tytön sydämen sykintä tuntui
nuorukaisen omaa vasten, Ashurst tunsi ritarillisuuden tunteiden ja
intohimon voimakkaina liikkuvan povessaan. Koska tyttö ei ollut
hänen säätyään, vaan noin yksinkertainen ja nuori ja ajattelematon,
noin voimakas rakkaudessaan ja avuton, niin miten Ashurst olisi
voinut muuta kuin esiintyä hänen suojelijanaan pimeydessä! Mutta
koska tyttö oli kuin itse luontoa ja kauneutta, kuin osa tästä
kevätyöstä samalla tavoin kuin kukkaset, niin kuinka hän, Ashurst,
saattoi olla ottamatta kaikkea, minkä tyttö tahtoi hänelle antaa —
kuinka hän saattoi olla päästämättä kevättä puhkeamaan täyteen
kukoistukseen tytön ja omassa sydämessään! Ja näiden kahden
ristiriitaisen tunteen raatelemana hän painoi tytön lujasti rintaansa
vasten ja suuteli hänen hiuksiaan. Kuinka kauan he siinä seisoivat
sanaakaan vaihtamatta, sitä hän ei tiennyt. Puro solisi entiseen
tapaansa, pöllöt huutelivat, kuu kiipesi yhä korkeammalle ja muuttui
samalla valkoisemmaksi. Heidän ympärillään ja yläpuolellaan kävivät
kukat yhä loistavammaksi elävässä kauneudessaan. Heidän
huulensa olivat löytäneet toisensa, ja he olivat vaiti. Jos he olisivat
puhuneet, olisi kaikki samassa hetkessä muuttunut epätodelliseksi.
Keväällä ei ole sanoja, vain solinaa ja kuiskauksia. Keväällä on
paljon enemmän kuin sanoja puhkeavissa kukkasissaan ja
lehdissään, purojen solinassa, valoisassa, uupumattomassa
etsinnässään. Ja toisinaan kevät muuttuu eläväksi ja kietoo jonkin
salaperäisen olennon tavoin käsivartensa rakastavien ympärille
koskettaen heitä taikasauvallaan, niin että he seisten huulet huulia
vasten unohtavat kaiken muun paitsi suudelman. Kun tytön sydän
sykki Ashurstin sydäntä ja huulet värjyivät hänen huuliaan vasten, ei
nuorukainen tuntenut muuta kuin sekoittumatonta onnentunnetta —
kohtalo oli määrännyt tytön häntä varten, rakkaus ei antanut pettää
itseään. Mutta kun heidän huulensa erkanivat ja he hengähtivät,
alkoi ristiriita samassa. Intohimo oli nyt voimakkaampi, ja
nuorukainen huokasi:
"Sano Frankiksi."
"En voi olla rakastamatta teitä. Tahdon aina olla teidän luonanne
— siinä kaikki."
"Kaikki?"
"Ah!"
"En ole kyllin hyvä sinulle! Sano, Megan, milloin aloit rakastaa
minua?"
Tyttö kuiskasi:
"Katsokaa!"
"Missä?"
"Ei. Yksinkertaista."
Meganin vyötärö!
"Hm — tavallinen."
"Hyvä."
Nainen huokasi.