资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ansible批量配置cisco交换机---接口篇-创新互联

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

创新互联建站专注于建阳企业网站建设,响应式网站建设,成都商城网站开发。建阳网站建设公司,为建阳等地区提供建站服务。全流程按需制作,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

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模块。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:ansible批量配置cisco交换机---接口篇-创新互联
当前网址:http://cdkjz.cn/article/dhecpo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220