Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Ansible batch configuration of cisco switches-Interface

Shulou Source: shulou.com Published: 2022-06-01 00:56:05 10月04日 Update

There is no introduction to ansible.

This example mainly introduces several methods of configuring ios interface by ansible, or which modules can be used to configure the interface.

1. List of hosts. This test takes one host as an example.

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

2.playbooks content

[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. Execute 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. View the execution effect

Interface GigabitEthernet1/0/1 switchport mode trunks / GigabitEthernet1/0/2 switchport mode trunks / GigabitEthernet1/0/3 switchport access vlan 100 switchport mode accessory interface GigabitEthernet1/0/4 switchport trunk native vlan 100 switchport trunk allowed vlan 10-255 switchport mode trunk! It can be seen that both ios_config and ios_l2_interface modules can be operated, and only layer 3 interfaces can use ios_comfig or ios_l3_interface modules.

Tags: Interface module configuration host two content only instance effect method test switch Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Docker Apple Huawei