您好,登錄后才能下訂單哦!
關(guān)于ansible不做介紹。
本例主要通過實例介紹ansible配置ios接口的幾種方法,或者說可利用哪些模塊配置接口。
1 .主機列表,本次測試以1臺主機為例
[root@Ansible-01 ansible]# cat hosts
[cisco]
172.16.254.130 ansible_connection=local
2.playbooks內(nèi)容
[root@Ansible-01 interface]# cat interface-phy.yml
---
- name: interface config
hosts: cisco
# vars:
# creds:
# username: "{{ username }}"
# password: "{{ password }}"
gather_facts: no
tasks:
- name: action interface G1-2 configure
ios_config:
lines:
- no shutdown
- switch mode trunk
- switch trunk allow vlan all
- do wr
parents: interface range gigabitEthernet 1/0/1 - 2
- name: action interface G3 configuration
ios_l2_interface:
name: GigabitEthernet1/0/3
mode: access
access_vlan: 100
- name: action interface G3 configuration
ios_l2_interface:
name: GigabitEthernet1/0/4
mode: trunk
native_vlan: 100
trunk_allowed_vlans: 10-255
- name: save configuration
ios_command:
commands:
- wr
3.執(zhí)行playbooks
[root@Ansible-01 interface]# ansible-playbook interface-phy.yml -u admin -k
SSH password:
PLAY [interface config] **************************************************************************************************************
TASK [action interface G1-2 configure] ***********************************************************************************************
changed: [172.16.254.130]
TASK [action interface G3 configuration] *********************************************************************************************
changed: [172.16.254.130]
TASK [action interface G4 configuration] *********************************************************************************************
changed: [172.16.254.130]
TASK [save configuration] ************************************************************************************************************
ok: [172.16.254.130]
PLAY RECAP ***************************************************************************************************************************
172.16.254.130 : ok=4 changed=3 unreachable=0 failed=0
4.查看執(zhí)行效果
interface GigabitEthernet1/0/1
switchport mode trunk
!
interface GigabitEthernet1/0/2
switchport mode trunk
!
interface GigabitEthernet1/0/3
switchport access vlan 100
switchport mode access
!
interface GigabitEthernet1/0/4
switchport trunk native vlan 100
switchport trunk allowed vlan 10-255
switchport mode trunk
!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。