oliverl_21.ios_config

ansible-role-ios_config

Cisco IOS 配置 Ansible 角色

当前任务:

  • Radius 服务器定义
  • ISE/802.1x 全局设置
  • 设备传感器配置
  • 802.1x 接口配置(部分,缺少接口选择的逻辑)
  • PnP ZTP 工作流程

特性:

  • 根据清单变量通过堡垒机/跳转主机连接
  • 从 Paramiko 切换到 libssh

待办事项:

需求

Radius 服务器定义:

  • IP 地址
  • 主机名
  • Radius 密钥
  • Radius 源接口

接口定义

  • 接入 VLAN
  • 后备 VLAN(可选)
  • 语音 VLAN(可选)
  • 低影响模式(可选)

切换到 LibSSH

参考

使用 libssh 模块(目前仅支持 Linux)

pip3 install ansible-pylibssh

为此角色启用 libssh

# roles/ios_config/default.yml
ansible_network_cli_ssh_type: libssh

在 ansible.cfg 中添加以下内容以全局启用

# ansible.cfg
[persistent_connection]
ssh_type = libssh

堡垒机/跳转主机连接

要使用堡垒机/跳转主机连接网络设备,请创建:

# inventory/group_vars/all/ansible_ssh.yml
ansible_ssh_proxy_command: >-
  {% if bastion_host is defined and bastion_host != '' %}
  ssh {{ hostvars[bastion_host]['ansible_user'] }}@{{ hostvars[bastion_host]['ansible_host'] }}
  -o Port={{ hostvars[bastion_host]['ansible_ssh_port'] | default(22) }}
  -W %h:%p
  {% endif %}

ansible_ssh_common_args: >-
  {% if bastion_host is defined and bastion_host != '' %}
  -o ProxyCommand="{{ ansible_ssh_proxy_command }}"
  {% endif %}

# 所有主机的默认堡垒主机
bastion_host: ""

在您的清单主机/组变量中添加 bastion_host: "your-host",将使用跳转主机。跳转主机必须在清单中定义。

示例

# inventory/group_vars/ios.yml
---
ansible_user: admin
ansible_network_os: ios
bastion_host: tux01
# inventory/<inventoryfile>
[debian]
tux01 ansible_host=tux01.example.org

[debian:vars]
ansible_user=tux
ansible_become_method=sudo

角色变量

  • fact_gather_enabled
    • 默认值为 true
  • push_config
    • 定义是否应将配置推送到设备或本地存储配置差异
  • ios_int_config_enabled
    • 启用接口配置
  • ios_sensor_config_enabled
    • 启用 IOS 设备传感器配置
  • ios_1xglobal_config_enabled
    • 启用 IOS ISE/802.1x 全局配置
  • int_global_config_enabled
    • 启用 802.1x 接口配置
  • pnp_config_enabled
    • 启用生成 PnP 配置,需与 fact_gather_enabled: false 一起使用

依赖

角色:无

集合:

  • cisco.ios
  • ansible.netcommon

示例剧本

待办事项

- name: example
  hosts: csw02
  gather_facts: false
  connection: network_cli
  roles:
    - { role: ios_config, ios_config_enabled: false, ios_sensor_config_enabled: true, ios_1xglobal_config_enabled: true }

许可证

GPL-3.0 或更高版本

作者信息

oliverl-21

关于项目

Cisco IOS Configuration role

安装
ansible-galaxy install oliverl_21.ios_config
许可证
Unknown
下载
103
拥有者
nothing to tell