• 【GNS3 GraduProj】交换机Ansible脚本测试(文件备份)


     为交换机S1创建vlan:S1VlanCreate.yml

    (测试成功)

    1. ---
    2. - name: S1 Configuration
    3. hosts: S1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: Interface Config
    8. ios_command:
    9. commands:
    10. - vlan database
    11. - vlan 10
    12. - vlan 20
    13. - vlan 30
    14. - exit
    15. register: print_output
    16. - debug: var=print_output

    为S1接口配置VLAN:S1InterVlan.yml

    (测试成功,但显示change,因为在模拟交换机的运行配置中“switchport mode access”不会显示,因此总是会出现配置更新(即“change”)的结果)

    1. ---
    2. - name: S1 Configuration
    3. hosts: S1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: Interface Config
    8. ios_config:
    9. parents: "interface {{ item.interface }}"
    10. lines:
    11. - switchport mode access
    12. - "switchport access vlan {{ item.vlan }}"
    13. with_items:
    14. - { interface : FastEthernet1/1, vlan : 10 }
    15. - { interface : FastEthernet1/2, vlan : 20 }
    16. - { interface : FastEthernet1/3, vlan : 30 }
    17. register: print_output
    18. - debug: var=print_output

    为所有交换机的f1/0接口配置trunk:S1InterTrunk.yml

    (测试成功,同上,在模拟交换机配置中命令“switchport trunk encapsulation dot1q”不被显示(也可能是默认,而不支持),故删去此命令后无“change”,而只显示“ok”。但最终因为查验交换机支持此条与上面那条命令,故都保存。)

    1. ---
    2. - name: Switches Global Configuration
    3. hosts: Switches
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: Interface Trunk Config
    8. ios_config:
    9. parents: "interface FastEthernet1/0"
    10. lines:
    11. - switchport mode trunk
    12. register: print_output
    13. - debug: var=print_output

    以上三者合在一个剧本中:S1Switches.yml

    1. ---
    2. - name: S1 Configuration
    3. hosts: S1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: Vlan Config
    8. ios_command:
    9. commands:
    10. - vlan database
    11. - vlan 10
    12. - vlan 20
    13. - vlan 30
    14. - exit
    15. register: print_output
    16. - debug: var=print_output
    17. - name: Interface Acces Config
    18. ios_config:
    19. parents: "interface {{ item.interface }}"
    20. lines:
    21. - switchport mode access
    22. - "switchport access vlan {{ item.vlan }}"
    23. with_items:
    24. - { interface : FastEthernet1/1, vlan : 10 }
    25. - { interface : FastEthernet1/2, vlan : 20 }
    26. - { interface : FastEthernet1/3, vlan : 30 }
    27. register: print_output
    28. - debug: var=print_output
    29. - name: Switches Global Configuration
    30. hosts: Switches
    31. gather_facts: false
    32. connection: network_cli
    33. tasks:
    34. - name: Interface Trunk Config
    35. ios_config:
    36. parents: "interface FastEthernet1/0"
    37. lines:
    38. - switchport trunk encapsulation dot1q
    39. - switchport mode trunk
    40. register: print_output
    41. - debug: var=print_output

  • 相关阅读:
    RequestContextHolder详解
    vue+antd——实现table表格的打印——分页换行,每页都有表头——基础积累
    计算机二级WPS 选择题(模拟和解析八)
    两名高管遭解雇,Twitter:只出不进
    使用C语言实现双向链表(带头结点)
    c#设计模式-行为型模式 之 访问者模式
    (二十二)Flask之上下文管理第三篇【收尾—讲一讲g】
    SpringCLoud——docker中的数据卷
    IBM Spectrum LSF 重要的目录和配置文件
    python中is和==的区别,地址和重新复制后,地址变化
  • 原文地址:https://blog.csdn.net/weixin_50155732/article/details/138160420