Ansible配制Juniper設(shè)備

? ?#最近一直在學(xué)習(xí)姜汁老師的Ansible教程,還特意去看了《安德的游戲》。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名與空間、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、思明網(wǎng)站維護(hù)、網(wǎng)站推廣。

? ? 寫這篇算是一個學(xué)習(xí)和實驗的記錄,就怕萬一下次工作需要的時候自己已經(jīng)忘得一干二凈了,白給。#

????

? ? 首先是Ansible控制主機(jī)的安裝,這里有個坑。當(dāng)我們執(zhí)行playbook的時候 會有Error :xxxxx,Msg:xxxxx,會提示你install ncclient。因為netconf是Py3的模塊,Ansible默認(rèn)使用的是Py2.7。

? ? ?附上解決辦法的鏈接:https://acozine.github.io/html/reference_appendices/python_3_support.html

? 先去了解下juniper.junos:

Juniper.junos Ansible Modules

Contents:

  • juniper_junos_jsnapy

  • juniper_junos_srx_cluster

  • juniper_junos_ping

  • juniper_junos_command

  • juniper_junos_system

  • juniper_junos_facts

  • juniper_junos_config

  • juniper_junos_software

  • juniper_junos_pmtud

  • juniper_junos_table

  • juniper_junos_rpc

? 甚至?xí)l(fā)現(xiàn)有HA的模塊。facts用于收集junos系統(tǒng)信息,config用來今天幫助我們做配置。

????進(jìn)入到config模塊,可以看到模塊的簡介,選項和例子??梢詧?zhí)行包括:loading or rolling back, checking, diffing, retrieving, and committing the configuration 這么多功能,我們先用用最簡單的commit。在使用之前請先安裝好eznc。

? ? 正式開始配置:

? ? 把host和var寫入到hosts文件里:

????[ex3300]

????192.168.11.169

????[ex3300:vars]

????ansible_connection=network_cli

????#ansible_connection=netconf

????ansible_network_os=junos

????ansible_user=netops

????ansible_password=juniper123

? ? 準(zhǔn)備配置文件:

????more junos_config_vars/vsrx_vars_ex3300.yaml?

????---

?????vsrx_config_ex3300:

? ????- set routing-options static route 2.2.2.2/32 discard

????實驗用了Srx320 19.1R3,Vsrx15.1R和Ex3300 12.3R9版本測試。這里的文件名字寫混亂了 關(guān)系不大。

? ? 設(shè)備初始化:

????設(shè)備的MGT接口 ssh/netconf和ssh用戶:

????set?system?root-authentication?encrypted-password?"$1$d2G1wOPF$Lth.0XBee52ROKcFwayxr/"
????set?system?login?user?netops?uid?203
????set?system?login?user?netops?class?super-user
????set?system?login?user?netops?authentication?encrypted-password?"$1$HFIwO3Kj$OQ9IDKraR5rYSns2mRXJh/"
????set?system?services?ftp
????set?system?services?ssh?root-login?allow
????set?system?services?netconf?ssh?port?830
????set?interfaces?me0?unit?0?family?inet?address?192.168.11.169/24?

? ? 寫劇本:

? ? 配置變量采用導(dǎo)入變量文件的方式,用vars_files參數(shù)來定位。

? ? vars_files:

? ? ????- junos_config_vars/vsrx_vars_ex3300.yaml

? ? ?編輯juniper_junos_config的options:

? ???juniper_junos_config:

? ? ? ????config_mode: 'exclusive' #默認(rèn)就是exclusive

? ? ? ????load: 'set' ?#set或者merge模式

? ? ? ????lines: "{{ vsrx_config_ex3300 }}" #包含配置的字符串列表

? ? ? ????commit: yes #也不check或者干嘛了直接commit

? ? 運行。Ansible-playbook junos_config_ex3300.yaml?

????PLAY [configure SRX] ****************************************************************************************

????TASK [configure infomation :] *******************************************************************************

????ok: [192.168.11.169] => {

? ? ????"vsrx_config_ex3300": [ ?#debug輸出var變量也就是配置文件。

? ? ? ? ????"set routing-options static route 3.3.3.3/32 discard"

? ? ????]

????}

????TASK [load configure into vSRX] *****************************************************************************

????這里會有一大段告警 但是不影響結(jié)果 暫時不理會(其實我去官網(wǎng)看了沒看懂)。

????changed: [192.168.11.169]

????TASK [print configure results] ******************************************************************************

????ok: [192.168.11.169] => { #changed == true 從而debug msg

? ? ????"msg": "vSRX configure completed thanks"

????}

????PLAY RECAP **************************************************************************************************

????192.168.11.169 ? ? ? ? ? ? : ok=3 ? ?changed=1 ? ?unreachable=0 ? ?failed=0 ? ?skipped=0 ? ?rescued=0 ? ?ignored=0

????整理下思路:設(shè)備初始化;Ansible的host和var;配置變量(變量文件的方式);Playbook(可以做的事情太多了 這次使用的有 定位變量的文件位置,配置前先輸出配置,利用模塊導(dǎo)入配置到相應(yīng)的主機(jī),配置成功changed以后輸出提示)。

????在官網(wǎng)的例子里面有一個是直接這么來的:

????lines:

??????- 'set system services netconf ssh'

? ? ?

? ?最后回到設(shè)備上去看下配置compare | rollback 1:

?+????route?3.3.3.3/32?discard?

????大功告成,簡單的利用Ansible配置Juniper設(shè)備!

文章標(biāo)題:Ansible配制Juniper設(shè)備
網(wǎng)站地址:http://bm7419.com/article4/iihooe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、靜態(tài)網(wǎng)站外貿(mào)建站、品牌網(wǎng)站制作、用戶體驗、微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)