CloudEngine 操作系统平台选项
CloudEngine CE OS 属于 community.network 专辑的一部分,支持多种连接。本页提供了有关每种连接在 Ansible 中的工作原理和使用方法的详细介绍。
译注:CloudEngine 是华为公司的新一代交换机平台。其中 CE 系列是数据中心交换机平台,S 系列是园区交换机平台。
在使用 CE 平台时,显示告警信息
[DEPRECATION WARNING]: community.network.ce has been deprecated. This collection and all content in it is unmaintained and deprecated. This feature will be removed from community.network in version 6.0.0. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.。表示未来community.network可能不再支持 CloudEngine 平台。 将在community.network专辑6.0.0版本中弃用。参见:
可用的连接
CLI | NETCONF | |
|---|---|---|
| 协议 | SSH | 透过 SSH 的 XML |
| 凭据 | 若存在 SSH 密钥/ ssh-agent,则使用 SSH 密钥/ ssh-agent,若使用密码,则接受 -u my_user -k | 若存在 SSH 密钥/ ssh-agent,则使用 SSH 密钥/ ssh-agent,若使用密码,则接受 -u my_user -k |
| 间接访问 | 使用堡垒机(跳转主机) | 使用堡垒机(跳转主机) |
| 连接设置 | ansible_connection: ansible.netcommon.network_cli | ansible_connection: ansible.netcommon.netconf |
enable 模式(权限提升) | 不受 CE OS 支持 | 不受 CE OS 支持 |
| 返回数据格式 | 参考单独模组文档 | 参考单独模组文档 |
ansible_connection: local 已被弃用。请使用 ansible_connection: ansible.netcommon.netconf 或 ansible_connection=ansible.netcommon.network_cli 代替。
示例 CLI 仓库 [ce:vars]
[ce:vars]
ansible_connection=ansible.netcommon.network_cli
ansible_network_os=community.network.ce
ansible_user=myuser
ansible_password=!vault...
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"'
- 若咱们使用的是 SSH 密钥(包括
ssh-agent),则可以移除ansible_password配置项; - 若咱们直接访问的主机(不通过堡垒机/跳转主机),则可移除
ansible_ssh_common_args配置项; - 若咱们通过堡垒机/跳转主机访问咱们的主机,则咱们不能在
ProxyCommand指令中包含咱们的 SSH 密码。为防止秘密外泄(例如在ps的输出中),SSH 不支持使用环境变量提供密码。
示例 CLI 任务
---
- hosts: ce-sw
gather_facts: no
tasks:
- name: Retrieve CE OS version
community.network.ce_command:
commands: display version
register: res
- debug:
msg: "{{ res }}"
在 Ansible 中使用 NETCONF
启用 NETCONF
在使用 NETCONF 连接交换机之前,咱们必须:
- 使用
pip install ncclient命令,在控制节点上安装ncclient这个 python 软件包; - 在 CloudEngine OS 设备上启用
NETCONF。
要使用 Ansible 在某个新交换机上启用 NETCONF,就要使用带有 CLI 连接的 community.network.ce_config 模组。像上面的 CLI 示例中一样,设置咱们的平台级别变量,然后像下面这样运行一个 playbook 任务:
---
- hosts: ce-sw
gather_facts: no
tasks:
- name: Enable NETCONF
connection: ansible.netcommon.network_cli
community.network.ce_config:
lines:
- snetconf server enable
register: res
- debug:
msg: "{{ res }}"
启用 NETCONF 后,就要把咱们的变量,修改为使用 NETCONF 连接。
译注:出了执行上述任务启用
NETCONF还需进行以下设置。
给 SSH 连接用户添加
snetconf的 SSHservice-type:ssh user hector service-type stelnet snetconf;配置
NETCONF端口号。若未配置会报出"Error: b'Could not open socket to ce-sw:830'"错误。
netconf
protocol inbound ssh port 830
commit
quit
示例 NETCONF 仓库 [ce:vars]
ce-sw:
ansible_host: ce-sw
ansible_network_os: community.network.ce
ansible_connection: ansible.netcommon.netconf
ansible_ssh_user: hector
ansible_ssh_pass: 'my_pass'
示例 NETCONF 任务
---
- hosts: ce-sw
gather_facts: no
tasks:
- name: Create a vlan, id is 50(ce)
community.network.ce_vlan:
vlan_id: 50
name: WEB
register: res
- debug:
msg: "{{ res }}"
说明
工作于 ansible.netcommon.network_cli 下的模组
community.network.ce_acl_interfacecommunity.network.ce_commandcommunity.network.ce_configcommunity.network.ce_evpn_bgpcommunity.network.ce_evpn_bgp_rrcommunity.network.ce_evpn_globalcommunity.network.ce_factscommunity.network.ce_mlag_interfacecommunity.network.ce_mtucommunity.network.ce_netstream_agingcommunity.network.ce_netstream_exportcommunity.network.ce_netstream_globalcommunity.network.ce_netstream_templatecommunity.network.ce_ntp_authcommunity.network.ce_rollbackcommunity.network.ce_snmp_contactcommunity.network.ce_snmp_locationcommunity.network.ce_snmp_trapscommunity.network.ce_startupcommunity.network.ce_stpcommunity.network.ce_vxlan_arpcommunity.network.ce_vxlan_gatewaycommunity.network.ce_vxlan_global
工作于 ansible.netcommon.netconf 下的模组
community.network.ce_aaa_servercommunity.network.ce_aaa_server_hostcommunity.network.ce_aclcommunity.network.ce_acl_advancecommunity.network.ce_bfd_globalcommunity.network.ce_bfd_sessioncommunity.network.ce_bfd_viewcommunity.network.ce_bgpcommunity.network.ce_bgp_afcommunity.network.ce_bgp_neighborcommunity.network.ce_bgp_neighbor_afcommunity.network.ce_dldpcommunity.network.ce_dldp_interfacecommunity.network.ce_eth_trunkcommunity.network.ce_evpn_bd_vnicommunity.network.ce_file_copycommunity.network.ce_info_center_debugcommunity.network.ce_info_center_globalcommunity.network.ce_info_center_logcommunity.network.ce_info_center_trapcommunity.network.ce_interfacecommunity.network.ce_interface_ospfcommunity.network.ce_ip_interfacecommunity.network.ce_lacpcommunity.network.ce_link_statuscommunity.network.ce_lldpcommunity.network.ce_lldp_interfacecommunity.network.ce_mlag_configcommunity.network.ce_netconfcommunity.network.ce_ntpcommunity.network.ce_ospfcommunity.network.ce_ospf_vrfcommunity.network.ce_rebootcommunity.network.ce_sflowcommunity.network.ce_snmp_communitycommunity.network.ce_snmp_target_hostcommunity.network.ce_snmp_usercommunity.network.ce_static_routecommunity.network.ce_static_route_bfdcommunity.network.ce_switchportcommunity.network.ce_vlancommunity.network.ce_vrfcommunity.network.ce_vrf_afcommunity.network.ce_vrf_interfacecommunity.network.ce_vrrpcommunity.network.ce_vxlan_tunnelcommunity.network.ce_vxlan_vap
警告:
切勿以明文方式存储密码。我们建议使用 SSH 密钥验证 SSH 连接。Ansible 支持
ssh-agent来管理 SSH 密钥。如果必须使用密码来验证 SSH 连接,建议使用 Ansible Vault 对密码进行加密。
(End)