网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

ansible批量配置cisco交换机---接口篇

关于ansible不做介绍。
本例主要通过实例介绍ansible配置ios接口的几种方法,或者说可利用哪些模块配置接口。

成都创新互联云计算的互联网服务提供商,拥有超过13年的服务器租用、绵阳电信机房机柜租用、云服务器、虚拟主机、网站系统开发经验,已先后获得国家工业和信息化部颁发的互联网数据中心业务许可证。专业提供云主机、虚拟主机域名申请、VPS主机、云服务器、香港云服务器、免备案服务器等。

1 .主机列表,本次测试以1台主机为例

[root@Ansible-01 ansible]# cat hosts
[cisco]
172.16.254.130 ansible_connection=local 

2.playbooks内容

[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.执行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.查看执行效果

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
!
  1. 可见 ios_config和 ios_l2_interface 两个模块都可以操作,只有三层接口则可以使用ios_comfig或者ios_l3_interface模块。

网站标题:ansible批量配置cisco交换机---接口篇
文章源于:http://bjjierui.cn/article/pjogjs.html

其他资讯