SlideShare ist ein Scribd-Unternehmen logo
1 von 66
APRICOT - Feb 28th, 2017
➔
➔
➔
➔
➔
https://git.io/vZKZH
➔
➔
➔
location: sfo
location:
- sfo
- sgn
sites:
- location: sfo
type: customer
- location: sgn
type: backbone
{{ location }}
{{ item }}
{{ item.location }}
{{ item.x.location }}
➔
ansible-playbook -i inventory playbook.yml
➔
● hosts
● host_vars
● group_vars
➔
inventory
➔ /etc/ansible/hosts
● Hard to manage across systems
● Usually need to be root to edit
● Can’t easily keep in revision control
➔ ./inventory/hosts
● Easily manage in revision control
● No root needed!
● Ensure everyone is using correct hosts
hosts
[all-routers:children]
customer-routers
peering-routers
[customer-routers]
car01.sgn01 ansible_host=192.0.2.20 model=mx104
car01.hkg01 ansible_host=192.0.2.21 model=mx104
[peering-routers]
pat01.lax01 ansible_host=192.0.3.40 model=asr1k
pat01.tyo01 ansible_host=192.0.3.41 model=ask9k
[websites]
bronwynlewis.com
hosts
% tree
├ ansible
│ ├── inventory
│ │ ├── group_vars
│ │ │ ├── all.yml
│ │ │ ├── development.yml
│ │ │ └── production.yml
│ │ ├── hosts
│ │ └── host_vars
│ │ ├── jumphost.yml
│ │ └── mail.yml
│ ├── playbook.yml
│ └── roles
hosts & [host|group]_vars
% cat inventory/hosts
[production:children]
admin
website
[admin]
mail
jumphost
[website]
web1
web2
db1
➔
➔ host_vars/mail.yml
● Variables to be used by the mail host
➔ host_vars/jumphost.yml
● Variables to be used by the jumphost host
host_vars
% cat inventory/hosts (before)
[customer-routers]
car01.sgn01 ansible_host=192.0.2.20 model=mx104
% cat inventory/host_vars/car01.sgn01.yml
---
ansible_host: 192.0.2.20
model: mx104
location: sgn
% cat inventory/hosts (after)
[customer-routers]
car01.sgn01
host_vars
➔
➔ group_vars/production.yml
● Vars to be used by any host in production group
➔ group_vars/all.yml
● Contains vars to be used by ALL hosts
group_vars
ansible all -i localhost, -m setup --connection=local
[...]
"ansible_distribution": "Ubuntu",
"ansible_distribution_major_version": "16",
"ansible_distribution_release": "xenial",
"ansible_distribution_version": "16.04",
"ansible_dns": {
"nameservers": [
"8.8.8.8",
"4.2.2.2"
]
},
[...]
% sudo -H pip install passlib
% sudo -H ansible-galaxy install Juniper.junos
% ansible-playbook -i bordergw01.hkg.domain.tld, test.yml
---
- name: Sample play
hosts: bordergw01.hkg.domain.tld
roles:
- Juniper.junos
gather_facts: no
connection: local
vars:
ansible_user: matt
vars_prompt:
name: passwd
prompt: JunOS password
private: yes
tasks:
- name: Collect JunOS facts
junos_get_facts:
host={{ inventory_hostname }}
user={{ ansible_user }}
passwd={{ passwd }}
register: junos
- name: Dump JunOS facts to stdout
debug: msg="{{ junos.facts }}"
% ansible-playbook -i bordergw01.hkg.domain.tld, test.yml
JunOS password:
PLAY [Sample play] **************************************
TASK [Collect JunOS facts] ******************************
TASK [Dump JunOS facts to stdout] ***********************
ok: [bordergw01.hkg.domain.tld] => {
"msg": {
[...]
"hostname": "bordergw01.hkg.domain.tld",
"ifd_style": "CLASSIC",
"master": "RE0",
"model": "MX104",
"personality": "MX",
"serialnumber": "H7931",
"switch_style": "BRIDGE_DOMAIN",
"vc_capable": false,
"version": "13.3R6.5",
"version_RE0": "13.3R6.5",
[...]
➔
● ipaddr filter is a great example
● Perform regex, perform math, etc. against vars
➔
● Can be direct variables
● Can be variables pulled in
{{ foo | default(‘bar’) }}
{{ foo | mandatory }}
mandatory
TASK [hello : Generate "hello"] ***********************************
failed: [localhost] (item={u'name': u'world', u'number': 1}) =>
{"failed": true, "item": {"name": "world", "number": 1}, "msg":
"AnsibleFilterError: Mandatory variable not defined."}
{{ foo | mandatory }}
{{ “hkg.foo.com” | regex_replace('^(.*).(w.*)$', '2') | upper }}
{{ “198.168.0.123/24”|ipaddr('address')|splitext| 
last|regex_replace('^[.]','') }}
{{ item.ipv4 | ipaddr(‘network’) }}
ipaddr(‘address’) 192.0.2.5
ipaddr(‘network’) 192.0.2.0
ipaddr(‘netmask’) 255.255.255.0
ipaddr(‘broadcast’) 192.0.2.255
ipaddr(‘net’) 203.0.113.0/24
ipaddr(‘net’)|ipaddr(‘1’) 203.0.113.1/24
ipaddr(‘net’)|ipaddr(‘1’)|ipaddr(‘address’)
203.0.113.1
‘266.1.2.888/24’ | ipaddr(‘net’) False
‘192.168.0.3/24’ | ipaddr(‘net’) True
% ansible all -i localhost, -m debug -a 
"msg={{'203.0.113.0/24'|ipaddr('net')|ipaddr('-1')|ipaddr('address')}}"
localhost | SUCCESS => {
"msg": "203.0.113.255"
}
% ansible all -i localhost, -m debug -a
"msg={{'266.1.2.3/24'|ipaddr('net')}}"
localhost | SUCCESS => {
"msg": false
}
% ansible all -i localhost, -m debug -a 
"msg={{'2001:db8::/32'|ipaddr('net')|ipaddr('2')}}"
localhost | SUCCESS => {
"msg": "2001:db8::2/32"
{{ item.ipv4 | ipaddr(‘network’) }}
{% set network = item.ipv4 | ipaddr('network') %}
{{ network }}
% cat templates/dns.j2
{% set dnsservers = [‘192.168.1.2’, ‘172.16.100.4’] %}
{% for nameserver in dnsservers %}
ip name-server {{ nameserver }}
{% endfor %}
% cat output
ip name-server 192.168.1.2
ip name-server 172.16.100.4
➔
➔
➔
{% if dhcp is True %}
{% include dhcp.j2 %}
{% endif %}
service dhcp
ip dhcp pool {{ item.hostname | upper }}
[...]
{% if dhcp is True %}
{% include dhcp.j2 %}
{% endif %}
dhcp: True
➔
➔
➔
- users:
- first_name: david
last_name: bowie
team: accounting
- first_name: grace
last_name: jones
team: engineering
{% for x in users %}
{{ x.first_name | title }}, {{ x.team | title }}
{% endfor %}
% cat output
David, Accounting
Grace, Engineering
{% set macros = {
"DNS-SERVERS": "system name-server <*>",
"NTP-SERVERS": "system ntp server <*>"
"SNMP-MANAGERS": "snmp community <*> clients <*>",
%}
{% for key, value in macros.iteritems() %}
<prefix-list>
<name>{{ key }}</name>
<apply-path>{{ value|escape }}</apply-path>
</prefix-list>
{% endfor %}
<prefix-list>
<name>DNS-SERVERS</name>
<apply-path>system name-server &lt;*&gt;</apply-path>
</prefix-list>
<prefix-list>
<name>NTP-SERVERS</name>
<apply-path>system ntp server &lt;*&gt;</apply-path>
</prefix-list>
<prefix-list>
<name>SNMP-MANAGERS</name>
<apply-path>snmp community &lt;*&gt; clients &lt;*&gt;</apply-path>
</prefix-list>
% cat inventory/host_vars/car01.sgn01.yml
---
interfaces:
lo0:
description: "Loopback"
v4_address: 192.0.2.20/32
% cat inventory/host_vars/car01.hkg01.yml
---
interfaces:
lo0:
description: "Loopback"
v4_address: 192.0.2.21/32
% cat inventory/host_vars/pat01.lax01.yml
---
interfaces:
lo0:
description: "Loopback"
v4_address: 192.0.3.40/32
% cat inventory/hosts
[customer-routers]
car01.sgn01
car01.hkg01
[peering-routers]
pat01.lax01
[all-routers:children]
customer-routers
peering-routers
{% for router in groups['all-routers']|sort %}
{# build iBGP sessions to all routers, except self #}
{% if hostvars[router]['inventory_hostname'] != inventory_hostname %}
<neighbor>
<name>{{ hostvars[router]['interfaces']['lo0']['v4_address']|ipaddr('address') }}</name>
<description>{{ router }}</description>
</neighbor>
{% endif %}
{% endfor %}
% cat output/cat01.sgn01.conf
<bgp>
<neighbor>
<name>192.0.2.21</name>
<description>car01.hkg01</description>
</neighbor>
<neighbor>
<name>192.0.3.40</name>
<description>pat01.lax01</description>
</neighbor>
</bgp>
% cat output/pat01.lax01.conf
<bgp>
<neighbor>
<name>192.0.2.20</name>
<description>car01.sgn01</description>
</neighbor>
<neighbor>
<name>192.0.2.21</name>
<description>car01.hkg01</description>
</neighbor>
</bgp>
% cat output/car02.hkg.conf
<bgp>
<neighbor>
<name>192.0.2.20</name>
<description>car01.sgn01</description>
</neighbor>
<neighbor>
<name>192.0.3.40</name>
<description>par01.lax02</description>
</neighbor>
</bgp>
➔ inventory
➔
➔
pat01.lax xe-1/0/2 198.51.100.47/
24
2001:db8:51::47/64 Peering Angeles-IX
car04.sfo ge-2/0/8 192.0.2.248/30 2001:db8:0::/56 Customer 6Ten Stores
br02.sgn xe-1/2/6 203.0.113.2/30 2001:db8:0:910::1/127 Transit PTT (Ckt #123)
bbr01.hkg he-1/4/8 bbr01.sin he-2/1/7 192.0.2.4/31 2001:db8:ba:24::/127 Backbone
% ./inventory/csv2json.py --list
---
{
"_meta": {
"hostvars": {
"pat01.lax": {
"interfaces": {
"xe-1/0/2": {
"description": "PEERING: Angeles-IX”,
"type": "Peering",
"v4_address": "198.51.100.47/24",
"v6_address": "2001:Db8:51::47/647"
}
}
},
"car04.sfo": {
"interfaces": {
"ge-2/0/8": {
"description": "CUSTOMER: 6Ten Stores”,
"type": "Customer",
"v4_address": "192.0.2.249/30",
"v6_address": "2001:db8:0::/56"
}
}
},
"bar02.sgn": {
"interfaces": {
"xe-1/2/6": {
"description": "TRANSIT: PTT (Ckt #123)”,
"type": "Transit",
"v4_address": "203.0.113.2/30",
"v6_address": "2001:db8:0:910::1/127"
}
}
},
"bbr01.hkg": {
"interfaces": {
"he-1/4/8": {
"description": "BACKBONE: bbr01.sin:he-2/1/7”,
"type": "Backbone",
"v4_address": "192.0.2.4/31",
"v6_address": "2001:db8:ba:24::/127"
...
"bbr01.sin": {
"interfaces": {
"he-2/1/7": {
"description": "BACKBONE: bbr01.hkg:he-1/4/8”,
"type": "Backbone",
"v4_address": "192.0.2.5/31",
"v6_address": "2001:db8:ba:24::1/127"
...
"ungrouped": {
"vars": {
"dns_entries": [
{
"domain": "myisp.com.",
"record_name": "he-1-4-8.bbr01.hkg.myisp.com”
"record_type": "A",
"record_value": "192.0.2.4"
},
{
"domain": "2.0.192.in-addr.arpa",
"record_name": "4",
"record_type": "PTR",
"record_value": "he-1-4-8.bbr01.myisp.com."
➔
➔
➔
➔
Juniper “core” Indented, set, or XML “passwd”
Juniper “junos-stdlib” Indented, set, or XML “passwd” Serial console, telnet support
NAPALM Indented “password” Powerful validation & facts support
---
- name: Backup running configuration
junos_get_config: >
host={{ ansible_host }} format=xml
dest=myrouters/{{ inventory_hostname }}_running.xml
- name: Compile configuration
template: >
src=juniper.conf.j2
dest=myrouters/{{ inventory_hostname }}_compiled.xml
- name: Deploy configuration
junos_install_config: >
host={{ ansible_host }} replace=yes timeout=45
file=myrouters/{{ inventory_hostname }}_compiled.xml
- name: Create new user account
user: name={{ item.name }} password={{ item.password }}
when: ansible_distribution == "CentOS"
- name: Create new user account
user: name={{ item.name }} password={{ item.password }}
when:
- ansible_distribution == "CentOS"
- “{{ item.user_type }}” == “admin”
% cat ansible.cfg
[defaults]
ansible_managed = %a %b %d %H:%M:%S %z %Y
% cat roles/juniper/templates/main.j2
<configuration operation="replace" xmlns:junos="junos">
<junos:comment>
##############################################################################
# HEADER: This file was generated by Ansible on {{ ansible_managed }}
# HEADER: Source {{ template_path }}
# HEADER: Built by {{ template_uid }} on {{ template_host }}
##############################################################################
</junos:comment>
<system>
<host-name>{{ inventory_hostname | mandatory }}</host-name>
...
% cat output/edge01.fmt01.conf
<configuration operation="replace" xmlns:junos="junos">
<junos:comment>
##############################################################################
# HEADER: This file was generated by Ansible on Mon Feb 20 18:34:26 -0800 2017
# HEADER: Source /Users/matt/work/ansible/roles/juniper/templates/main.j2
# HEADER: Built by matt on BSD4lyfe.local
##############################################################################
</junos:comment>
<system>
<host-name>edge01.fmt01</host-name>
...
matt@edge01.fmt01> show configuration
/*
##############################################################################
# HEADER: This file was generated by Ansible on Mon Feb 20 18:34:26 -0800 2017
# HEADER: Source /Users/matt/work/ansible/roles/juniper/templates/main.j2
# HEADER: Built by matt on BSD4lyfe.local
#############################################################################
*/
system {
host-name edge01.fmt01;
...
➔
➔
➔ error_on_undefined_vars ansible.cfg
➔ ansible -v
○
○ ntc_show_command
○
○
○
○
○
● http://jedelman.com/
● https://blog.tylerc.me/
● https://pynet.twb-tech.com/
● http://packetpushers.net/
● http://keepingitclassless.net/
● http://ansible-tips-and-tricks.rtfd.org/
me@bronwynlewis.com @bronwyn
matt@peterson.org @dorkmatt

Weitere ähnliche Inhalte

Was ist angesagt?

Red hat ansible automation technical deck
Red hat ansible automation technical deckRed hat ansible automation technical deck
Red hat ansible automation technical deck
Juraj Hantak
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
Sim Janghoon
 
Splunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdfSplunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdf
nitinscribd
 
Presentation f5 – beyond load balancer
Presentation   f5 – beyond load balancerPresentation   f5 – beyond load balancer
Presentation f5 – beyond load balancer
xKinAnx
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Simplilearn
 

Was ist angesagt? (20)

Network Automation with Ansible
Network Automation with AnsibleNetwork Automation with Ansible
Network Automation with Ansible
 
Red hat ansible automation technical deck
Red hat ansible automation technical deckRed hat ansible automation technical deck
Red hat ansible automation technical deck
 
Ansible 101
Ansible 101Ansible 101
Ansible 101
 
Kubernetes Networking with Cilium - Deep Dive
Kubernetes Networking with Cilium - Deep DiveKubernetes Networking with Cilium - Deep Dive
Kubernetes Networking with Cilium - Deep Dive
 
Understanding Active Directory Enumeration
Understanding Active Directory EnumerationUnderstanding Active Directory Enumeration
Understanding Active Directory Enumeration
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
 
Hacking Lab con ProxMox e Metasploitable
Hacking Lab con ProxMox e MetasploitableHacking Lab con ProxMox e Metasploitable
Hacking Lab con ProxMox e Metasploitable
 
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
Linux Interview Questions And Answers | Linux Administration Tutorial | Linux...
 
Vagrant
Vagrant Vagrant
Vagrant
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
 
OSMC 2022 | Logstash, Beats, Elastic Agent, Open Telemetry — what’s the right...
OSMC 2022 | Logstash, Beats, Elastic Agent, Open Telemetry — what’s the right...OSMC 2022 | Logstash, Beats, Elastic Agent, Open Telemetry — what’s the right...
OSMC 2022 | Logstash, Beats, Elastic Agent, Open Telemetry — what’s the right...
 
Splunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdfSplunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdf
 
Introduction to the Container Network Interface (CNI)
Introduction to the Container Network Interface (CNI)Introduction to the Container Network Interface (CNI)
Introduction to the Container Network Interface (CNI)
 
Kubernetes Networking
Kubernetes NetworkingKubernetes Networking
Kubernetes Networking
 
Terraform
TerraformTerraform
Terraform
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
Presentation f5 – beyond load balancer
Presentation   f5 – beyond load balancerPresentation   f5 – beyond load balancer
Presentation f5 – beyond load balancer
 
Asterisk: the future is at REST
Asterisk: the future is at RESTAsterisk: the future is at REST
Asterisk: the future is at REST
 
Zabbix Performance Tuning
Zabbix Performance TuningZabbix Performance Tuning
Zabbix Performance Tuning
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
 

Andere mochten auch

Andere mochten auch (20)

Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Automation of web attacks from advisories to create real world exploits
Automation of web attacks from advisories to create real world exploitsAutomation of web attacks from advisories to create real world exploits
Automation of web attacks from advisories to create real world exploits
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
Automated Deployments with Ansible
Automated Deployments with AnsibleAutomated Deployments with Ansible
Automated Deployments with Ansible
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Testing Ansible with Jenkins and Docker
Testing Ansible with Jenkins and DockerTesting Ansible with Jenkins and Docker
Testing Ansible with Jenkins and Docker
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Japan IPv6 Measurement
Japan IPv6 MeasurementJapan IPv6 Measurement
Japan IPv6 Measurement
 
Evolving the network for 5G
Evolving the network for 5GEvolving the network for 5G
Evolving the network for 5G
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & Ansible
 
Rundeck & Ansible
Rundeck & AnsibleRundeck & Ansible
Rundeck & Ansible
 
The Death of Transit and Beyond
The Death of Transit and BeyondThe Death of Transit and Beyond
The Death of Transit and Beyond
 
Ansible 2.0
Ansible 2.0Ansible 2.0
Ansible 2.0
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)
 
Journey to IPv6 - A Real-World deployment for Mobiles
Journey to IPv6 - A Real-World deployment for MobilesJourney to IPv6 - A Real-World deployment for Mobiles
Journey to IPv6 - A Real-World deployment for Mobiles
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 

Ähnlich wie Network Automation: Ansible 102

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)
Kritika910
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
guoqing75
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
yiditushe
 

Ähnlich wie Network Automation: Ansible 102 (20)

Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
EC2
EC2EC2
EC2
 
49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)49368010 projectreportontraininganddevelopment(1)
49368010 projectreportontraininganddevelopment(1)
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Monkey man
Monkey manMonkey man
Monkey man
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
Automating the Network
Automating the NetworkAutomating the Network
Automating the Network
 
Puppet Data Mining
Puppet Data MiningPuppet Data Mining
Puppet Data Mining
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtime
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
Incrementalism: An Industrial Strategy For Adopting Modern Automation
Incrementalism: An Industrial Strategy For Adopting Modern AutomationIncrementalism: An Industrial Strategy For Adopting Modern Automation
Incrementalism: An Industrial Strategy For Adopting Modern Automation
 
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
 

Mehr von APNIC

Mehr von APNIC (20)

APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
draft-harrison-sidrops-manifest-number-01, presented at IETF 119
draft-harrison-sidrops-manifest-number-01, presented at IETF 119draft-harrison-sidrops-manifest-number-01, presented at IETF 119
draft-harrison-sidrops-manifest-number-01, presented at IETF 119
 
Making an RFC in Today's IETF, presented by Geoff Huston at IETF 119
Making an RFC in Today's IETF, presented by Geoff Huston at IETF 119Making an RFC in Today's IETF, presented by Geoff Huston at IETF 119
Making an RFC in Today's IETF, presented by Geoff Huston at IETF 119
 
IPv6 Operational Issues (with DNS), presented by Geoff Huston at IETF 119
IPv6 Operational Issues (with DNS), presented by Geoff Huston at IETF 119IPv6 Operational Issues (with DNS), presented by Geoff Huston at IETF 119
IPv6 Operational Issues (with DNS), presented by Geoff Huston at IETF 119
 
Is DNS ready for IPv6, presented by Geoff Huston at IETF 119
Is DNS ready for IPv6, presented by Geoff Huston at IETF 119Is DNS ready for IPv6, presented by Geoff Huston at IETF 119
Is DNS ready for IPv6, presented by Geoff Huston at IETF 119
 
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
 
APNIC Update and RIR Policies for ccTLDs, presented at APTLD 85
APNIC Update and RIR Policies for ccTLDs, presented at APTLD 85APNIC Update and RIR Policies for ccTLDs, presented at APTLD 85
APNIC Update and RIR Policies for ccTLDs, presented at APTLD 85
 
NANOG 90: 'BGP in 2023' presented by Geoff Huston
NANOG 90: 'BGP in 2023' presented by Geoff HustonNANOG 90: 'BGP in 2023' presented by Geoff Huston
NANOG 90: 'BGP in 2023' presented by Geoff Huston
 
DNS-OARC 42: Is the DNS ready for IPv6? presentation by Geoff Huston
DNS-OARC 42: Is the DNS ready for IPv6? presentation by Geoff HustonDNS-OARC 42: Is the DNS ready for IPv6? presentation by Geoff Huston
DNS-OARC 42: Is the DNS ready for IPv6? presentation by Geoff Huston
 
APAN 57: APNIC Report at APAN 57, Bangkok, Thailand
APAN 57: APNIC Report at APAN 57, Bangkok, ThailandAPAN 57: APNIC Report at APAN 57, Bangkok, Thailand
APAN 57: APNIC Report at APAN 57, Bangkok, Thailand
 
Lao Digital Week 2024: It's time to deploy IPv6
Lao Digital Week 2024: It's time to deploy IPv6Lao Digital Week 2024: It's time to deploy IPv6
Lao Digital Week 2024: It's time to deploy IPv6
 
AINTEC 2023: Networking in the Penumbra!
AINTEC 2023: Networking in the Penumbra!AINTEC 2023: Networking in the Penumbra!
AINTEC 2023: Networking in the Penumbra!
 
CNIRC 2023: Global and Regional IPv6 Deployment 2023
CNIRC 2023: Global and Regional IPv6 Deployment 2023CNIRC 2023: Global and Regional IPv6 Deployment 2023
CNIRC 2023: Global and Regional IPv6 Deployment 2023
 
AFSIG 2023: APNIC Foundation and support for Internet development
AFSIG 2023: APNIC Foundation and support for Internet developmentAFSIG 2023: APNIC Foundation and support for Internet development
AFSIG 2023: APNIC Foundation and support for Internet development
 

Kürzlich hochgeladen

VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 

Kürzlich hochgeladen (20)

Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 

Network Automation: Ansible 102

  • 1. APRICOT - Feb 28th, 2017
  • 4.
  • 6. location: sfo location: - sfo - sgn sites: - location: sfo type: customer - location: sgn type: backbone
  • 7. {{ location }} {{ item }} {{ item.location }} {{ item.x.location }}
  • 8.
  • 9. ➔ ansible-playbook -i inventory playbook.yml ➔ ● hosts ● host_vars ● group_vars ➔ inventory
  • 10. ➔ /etc/ansible/hosts ● Hard to manage across systems ● Usually need to be root to edit ● Can’t easily keep in revision control ➔ ./inventory/hosts ● Easily manage in revision control ● No root needed! ● Ensure everyone is using correct hosts hosts
  • 11. [all-routers:children] customer-routers peering-routers [customer-routers] car01.sgn01 ansible_host=192.0.2.20 model=mx104 car01.hkg01 ansible_host=192.0.2.21 model=mx104 [peering-routers] pat01.lax01 ansible_host=192.0.3.40 model=asr1k pat01.tyo01 ansible_host=192.0.3.41 model=ask9k [websites] bronwynlewis.com hosts
  • 12. % tree ├ ansible │ ├── inventory │ │ ├── group_vars │ │ │ ├── all.yml │ │ │ ├── development.yml │ │ │ └── production.yml │ │ ├── hosts │ │ └── host_vars │ │ ├── jumphost.yml │ │ └── mail.yml │ ├── playbook.yml │ └── roles hosts & [host|group]_vars % cat inventory/hosts [production:children] admin website [admin] mail jumphost [website] web1 web2 db1
  • 13. ➔ ➔ host_vars/mail.yml ● Variables to be used by the mail host ➔ host_vars/jumphost.yml ● Variables to be used by the jumphost host host_vars
  • 14. % cat inventory/hosts (before) [customer-routers] car01.sgn01 ansible_host=192.0.2.20 model=mx104 % cat inventory/host_vars/car01.sgn01.yml --- ansible_host: 192.0.2.20 model: mx104 location: sgn % cat inventory/hosts (after) [customer-routers] car01.sgn01 host_vars
  • 15. ➔ ➔ group_vars/production.yml ● Vars to be used by any host in production group ➔ group_vars/all.yml ● Contains vars to be used by ALL hosts group_vars
  • 16. ansible all -i localhost, -m setup --connection=local
  • 17. [...] "ansible_distribution": "Ubuntu", "ansible_distribution_major_version": "16", "ansible_distribution_release": "xenial", "ansible_distribution_version": "16.04", "ansible_dns": { "nameservers": [ "8.8.8.8", "4.2.2.2" ] }, [...]
  • 18. % sudo -H pip install passlib % sudo -H ansible-galaxy install Juniper.junos % ansible-playbook -i bordergw01.hkg.domain.tld, test.yml
  • 19. --- - name: Sample play hosts: bordergw01.hkg.domain.tld roles: - Juniper.junos gather_facts: no connection: local vars: ansible_user: matt vars_prompt: name: passwd prompt: JunOS password private: yes
  • 20. tasks: - name: Collect JunOS facts junos_get_facts: host={{ inventory_hostname }} user={{ ansible_user }} passwd={{ passwd }} register: junos - name: Dump JunOS facts to stdout debug: msg="{{ junos.facts }}"
  • 21. % ansible-playbook -i bordergw01.hkg.domain.tld, test.yml JunOS password: PLAY [Sample play] ************************************** TASK [Collect JunOS facts] ****************************** TASK [Dump JunOS facts to stdout] *********************** ok: [bordergw01.hkg.domain.tld] => { "msg": {
  • 22. [...] "hostname": "bordergw01.hkg.domain.tld", "ifd_style": "CLASSIC", "master": "RE0", "model": "MX104", "personality": "MX", "serialnumber": "H7931", "switch_style": "BRIDGE_DOMAIN", "vc_capable": false, "version": "13.3R6.5", "version_RE0": "13.3R6.5", [...]
  • 23.
  • 24. ➔ ● ipaddr filter is a great example ● Perform regex, perform math, etc. against vars ➔ ● Can be direct variables ● Can be variables pulled in
  • 25. {{ foo | default(‘bar’) }} {{ foo | mandatory }}
  • 26. mandatory TASK [hello : Generate "hello"] *********************************** failed: [localhost] (item={u'name': u'world', u'number': 1}) => {"failed": true, "item": {"name": "world", "number": 1}, "msg": "AnsibleFilterError: Mandatory variable not defined."} {{ foo | mandatory }}
  • 27. {{ “hkg.foo.com” | regex_replace('^(.*).(w.*)$', '2') | upper }} {{ “198.168.0.123/24”|ipaddr('address')|splitext| last|regex_replace('^[.]','') }}
  • 28. {{ item.ipv4 | ipaddr(‘network’) }} ipaddr(‘address’) 192.0.2.5 ipaddr(‘network’) 192.0.2.0 ipaddr(‘netmask’) 255.255.255.0 ipaddr(‘broadcast’) 192.0.2.255
  • 30. % ansible all -i localhost, -m debug -a "msg={{'203.0.113.0/24'|ipaddr('net')|ipaddr('-1')|ipaddr('address')}}" localhost | SUCCESS => { "msg": "203.0.113.255" } % ansible all -i localhost, -m debug -a "msg={{'266.1.2.3/24'|ipaddr('net')}}" localhost | SUCCESS => { "msg": false } % ansible all -i localhost, -m debug -a "msg={{'2001:db8::/32'|ipaddr('net')|ipaddr('2')}}" localhost | SUCCESS => { "msg": "2001:db8::2/32"
  • 31. {{ item.ipv4 | ipaddr(‘network’) }} {% set network = item.ipv4 | ipaddr('network') %} {{ network }}
  • 32. % cat templates/dns.j2 {% set dnsservers = [‘192.168.1.2’, ‘172.16.100.4’] %} {% for nameserver in dnsservers %} ip name-server {{ nameserver }} {% endfor %} % cat output ip name-server 192.168.1.2 ip name-server 172.16.100.4
  • 34. {% if dhcp is True %} {% include dhcp.j2 %} {% endif %} service dhcp ip dhcp pool {{ item.hostname | upper }} [...]
  • 35. {% if dhcp is True %} {% include dhcp.j2 %} {% endif %} dhcp: True
  • 37. - users: - first_name: david last_name: bowie team: accounting - first_name: grace last_name: jones team: engineering {% for x in users %} {{ x.first_name | title }}, {{ x.team | title }} {% endfor %} % cat output David, Accounting Grace, Engineering
  • 38.
  • 39. {% set macros = { "DNS-SERVERS": "system name-server <*>", "NTP-SERVERS": "system ntp server <*>" "SNMP-MANAGERS": "snmp community <*> clients <*>", %} {% for key, value in macros.iteritems() %} <prefix-list> <name>{{ key }}</name> <apply-path>{{ value|escape }}</apply-path> </prefix-list> {% endfor %}
  • 40. <prefix-list> <name>DNS-SERVERS</name> <apply-path>system name-server &lt;*&gt;</apply-path> </prefix-list> <prefix-list> <name>NTP-SERVERS</name> <apply-path>system ntp server &lt;*&gt;</apply-path> </prefix-list> <prefix-list> <name>SNMP-MANAGERS</name> <apply-path>snmp community &lt;*&gt; clients &lt;*&gt;</apply-path> </prefix-list>
  • 41. % cat inventory/host_vars/car01.sgn01.yml --- interfaces: lo0: description: "Loopback" v4_address: 192.0.2.20/32 % cat inventory/host_vars/car01.hkg01.yml --- interfaces: lo0: description: "Loopback" v4_address: 192.0.2.21/32 % cat inventory/host_vars/pat01.lax01.yml --- interfaces: lo0: description: "Loopback" v4_address: 192.0.3.40/32 % cat inventory/hosts [customer-routers] car01.sgn01 car01.hkg01 [peering-routers] pat01.lax01 [all-routers:children] customer-routers peering-routers
  • 42. {% for router in groups['all-routers']|sort %} {# build iBGP sessions to all routers, except self #} {% if hostvars[router]['inventory_hostname'] != inventory_hostname %} <neighbor> <name>{{ hostvars[router]['interfaces']['lo0']['v4_address']|ipaddr('address') }}</name> <description>{{ router }}</description> </neighbor> {% endif %} {% endfor %}
  • 43. % cat output/cat01.sgn01.conf <bgp> <neighbor> <name>192.0.2.21</name> <description>car01.hkg01</description> </neighbor> <neighbor> <name>192.0.3.40</name> <description>pat01.lax01</description> </neighbor> </bgp> % cat output/pat01.lax01.conf <bgp> <neighbor> <name>192.0.2.20</name> <description>car01.sgn01</description> </neighbor> <neighbor> <name>192.0.2.21</name> <description>car01.hkg01</description> </neighbor> </bgp> % cat output/car02.hkg.conf <bgp> <neighbor> <name>192.0.2.20</name> <description>car01.sgn01</description> </neighbor> <neighbor> <name>192.0.3.40</name> <description>par01.lax02</description> </neighbor> </bgp>
  • 44.
  • 46. pat01.lax xe-1/0/2 198.51.100.47/ 24 2001:db8:51::47/64 Peering Angeles-IX car04.sfo ge-2/0/8 192.0.2.248/30 2001:db8:0::/56 Customer 6Ten Stores br02.sgn xe-1/2/6 203.0.113.2/30 2001:db8:0:910::1/127 Transit PTT (Ckt #123) bbr01.hkg he-1/4/8 bbr01.sin he-2/1/7 192.0.2.4/31 2001:db8:ba:24::/127 Backbone
  • 47. % ./inventory/csv2json.py --list --- { "_meta": { "hostvars": { "pat01.lax": { "interfaces": { "xe-1/0/2": { "description": "PEERING: Angeles-IX”, "type": "Peering", "v4_address": "198.51.100.47/24", "v6_address": "2001:Db8:51::47/647" } } },
  • 48. "car04.sfo": { "interfaces": { "ge-2/0/8": { "description": "CUSTOMER: 6Ten Stores”, "type": "Customer", "v4_address": "192.0.2.249/30", "v6_address": "2001:db8:0::/56" } } },
  • 49. "bar02.sgn": { "interfaces": { "xe-1/2/6": { "description": "TRANSIT: PTT (Ckt #123)”, "type": "Transit", "v4_address": "203.0.113.2/30", "v6_address": "2001:db8:0:910::1/127" } } },
  • 50. "bbr01.hkg": { "interfaces": { "he-1/4/8": { "description": "BACKBONE: bbr01.sin:he-2/1/7”, "type": "Backbone", "v4_address": "192.0.2.4/31", "v6_address": "2001:db8:ba:24::/127" ... "bbr01.sin": { "interfaces": { "he-2/1/7": { "description": "BACKBONE: bbr01.hkg:he-1/4/8”, "type": "Backbone", "v4_address": "192.0.2.5/31", "v6_address": "2001:db8:ba:24::1/127"
  • 51. ... "ungrouped": { "vars": { "dns_entries": [ { "domain": "myisp.com.", "record_name": "he-1-4-8.bbr01.hkg.myisp.com” "record_type": "A", "record_value": "192.0.2.4" }, { "domain": "2.0.192.in-addr.arpa", "record_name": "4", "record_type": "PTR", "record_value": "he-1-4-8.bbr01.myisp.com."
  • 52.
  • 54. Juniper “core” Indented, set, or XML “passwd” Juniper “junos-stdlib” Indented, set, or XML “passwd” Serial console, telnet support NAPALM Indented “password” Powerful validation & facts support
  • 55. --- - name: Backup running configuration junos_get_config: > host={{ ansible_host }} format=xml dest=myrouters/{{ inventory_hostname }}_running.xml - name: Compile configuration template: > src=juniper.conf.j2 dest=myrouters/{{ inventory_hostname }}_compiled.xml - name: Deploy configuration junos_install_config: > host={{ ansible_host }} replace=yes timeout=45 file=myrouters/{{ inventory_hostname }}_compiled.xml
  • 56.
  • 57. - name: Create new user account user: name={{ item.name }} password={{ item.password }} when: ansible_distribution == "CentOS" - name: Create new user account user: name={{ item.name }} password={{ item.password }} when: - ansible_distribution == "CentOS" - “{{ item.user_type }}” == “admin”
  • 58. % cat ansible.cfg [defaults] ansible_managed = %a %b %d %H:%M:%S %z %Y % cat roles/juniper/templates/main.j2 <configuration operation="replace" xmlns:junos="junos"> <junos:comment> ############################################################################## # HEADER: This file was generated by Ansible on {{ ansible_managed }} # HEADER: Source {{ template_path }} # HEADER: Built by {{ template_uid }} on {{ template_host }} ############################################################################## </junos:comment> <system> <host-name>{{ inventory_hostname | mandatory }}</host-name> ...
  • 59. % cat output/edge01.fmt01.conf <configuration operation="replace" xmlns:junos="junos"> <junos:comment> ############################################################################## # HEADER: This file was generated by Ansible on Mon Feb 20 18:34:26 -0800 2017 # HEADER: Source /Users/matt/work/ansible/roles/juniper/templates/main.j2 # HEADER: Built by matt on BSD4lyfe.local ############################################################################## </junos:comment> <system> <host-name>edge01.fmt01</host-name> ...
  • 60. matt@edge01.fmt01> show configuration /* ############################################################################## # HEADER: This file was generated by Ansible on Mon Feb 20 18:34:26 -0800 2017 # HEADER: Source /Users/matt/work/ansible/roles/juniper/templates/main.j2 # HEADER: Built by matt on BSD4lyfe.local ############################################################################# */ system { host-name edge01.fmt01; ...
  • 62.
  • 65. ● http://jedelman.com/ ● https://blog.tylerc.me/ ● https://pynet.twb-tech.com/ ● http://packetpushers.net/ ● http://keepingitclassless.net/ ● http://ansible-tips-and-tricks.rtfd.org/