• 【GNS3 GraduProj】路由器Ansible脚本测试(文件备份)


     R1DhcpPoolReception.yml

    (测试成功)

    1. ---
    2. - name: Routers Configuration
    3. hosts: R1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: DHCP Config
    8. ios_config:
    9. parents: "ip dhcp pool Reception"
    10. lines:
    11. - network 192.168.10.0 255.255.255.0
    12. - default-router 192.168.10.1
    13. - dns-server 192.168.10.1
    14. register: print_output
    15. - debug: var=print_output

    R1DhcpPoolReceptionVar.yml

    (测试成功)

    1. ---
    2. - name: Routers Configuration
    3. hosts: R1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: DHCP Config
    8. ios_config:
    9. parents: "ip dhcp pool {{ item.pool }}"
    10. lines:
    11. - "network {{ item.network }} 255.255.255.0"
    12. - "default-router {{ item.def_dns }}"
    13. - "dns-server {{ item.def_dns }}"
    14. with_items:
    15. - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
    16. register: print_output
    17. - debug: var=print_output

    R1dhcpall.yml

    (测试成功)

    1. ---
    2. - name: Routers Configuration
    3. hosts: R1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: DHCP Config
    8. ios_config:
    9. parents: "ip dhcp pool {{ item.pool }}"
    10. lines:
    11. - "network {{ item.network }} 255.255.255.0"
    12. - "default-router {{ item.def_dns }}"
    13. - "dns-server {{ item.def_dns }}"
    14. with_items:
    15. - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
    16. - { pool : Store, network : 192.168.20.0, def_dns : 192.168.20.1 }
    17. - { pool : Logistics, network : 192.168.30.0, def_dns : 192.168.30.1 }
    18. register: print_output
    19. - debug: var=print_output

    R1Ospf.yml

    (测试成功)

    1. ---
    2. - name: Routers Configuration
    3. hosts: R1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: R1 OSPF Config
    8. ios_config:
    9. parents: "router ospf 10"
    10. lines:
    11. - network 192.168.10.0 0.0.0.255 area 0
    12. - network 192.168.20.0 0.0.0.255 area 0
    13. - network 192.168.30.0 0.0.0.255 area 0
    14. register: print_output
    15. - debug: var=print_output

    R1Config.yml

    (OSPF与DHCP脚本合并,测试成功)

    1. ---
    2. - name: R1 Configuration
    3. hosts: R1
    4. gather_facts: false
    5. connection: network_cli
    6. tasks:
    7. - name: DHCP Config
    8. ios_config:
    9. parents: "ip dhcp pool {{ item.pool }}"
    10. lines:
    11. - "network {{ item.network }} 255.255.255.0"
    12. - "default-router {{ item.def_dns }}"
    13. - "dns-server {{ item.def_dns }}"
    14. with_items:
    15. - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
    16. - { pool : Store, network : 192.168.20.0, def_dns : 192.168.20.1 }
    17. - { pool : Logistics, network : 192.168.30.0, def_dns : 192.168.30.1 }
    18. register: print_output
    19. - debug: var=print_output
    20. - name: R1 OSPF Config
    21. ios_config:
    22. parents: "router ospf 10"
    23. lines:
    24. - network 192.168.10.0 0.0.0.255 area 0
    25. - network 192.168.20.0 0.0.0.255 area 0
    26. - network 192.168.30.0 0.0.0.255 area 0
    27. register: print_output
    28. - debug: var=print_output

    R1Config2.yml

    (R1的接口、DHCP、OSPF配置合并,测试成功)

    1. ---
    2. - name: R1 Configuration
    3. hosts: R1
    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. - "encapsulation dot1Q {{ item.vlan }}"
    12. - "ip address {{ item.address }} 255.255.255.0"
    13. with_items:
    14. - { interface : FastEthernet2/0.10, vlan : 10, address : 192.168.10.1 }
    15. - { interface : FastEthernet2/0.20, vlan : 20, address : 192.168.20.1 }
    16. - { interface : FastEthernet2/0.30, vlan : 30, address : 192.168.30.1 }
    17. register: print_output
    18. - debug: var=print_output
    19. - name: DHCP Config
    20. ios_config:
    21. parents: "ip dhcp pool {{ item.pool }}"
    22. lines:
    23. - "network {{ item.network }} 255.255.255.0"
    24. - "default-router {{ item.def_dns }}"
    25. - "dns-server {{ item.def_dns }}"
    26. with_items:
    27. - { pool : Reception, network : 192.168.10.0, def_dns : 192.168.10.1 }
    28. - { pool : Store, network : 192.168.20.0, def_dns : 192.168.20.1 }
    29. - { pool : Logistics, network : 192.168.30.0, def_dns : 192.168.30.1 }
    30. register: print_output
    31. - debug: var=print_output
    32. - name: OSPF Config
    33. ios_config:
    34. parents: "router ospf 10"
    35. lines:
    36. - network 192.168.10.0 0.0.0.255 area 0
    37. - network 192.168.20.0 0.0.0.255 area 0
    38. - network 192.168.30.0 0.0.0.255 area 0
    39. register: print_output
    40. - debug: var=print_output

  • 相关阅读:
    高性能网络编程 - select、 poll 、epoll 、libevent
    Android 使用addr2line分析so异常
    算法读书笔记-3
    科技资讯|苹果下一代Vision Pro头显将更小更轻,预装处方镜片
    6.2 文件的缓存位置
    基于python的c语言学习笔记(2)
    【IoT】生产制造:锅仔片上机做 SMT 加工吗?
    独孤思维:没学会走就要跑,你只能一辈子是穷b
    noip模拟赛多校第八场 T3 遥控机器人 (最短路 + 技巧拆点)
    Dremio:新一代数据湖仓引擎
  • 原文地址:https://blog.csdn.net/weixin_50155732/article/details/138160340