|
| 1 | +# IOS-XR 平台选项 |
| 2 | + |
| 3 | +[思科 IOS-XR 专辑](https://galaxy.ansible.com/ui/repo/published/cisco/iosxr) 专辑支持多种连接。本页提供了有关每种连接在 Ansible 中工作原理及使用方法的详细介绍。 |
| 4 | + |
| 5 | + |
| 6 | +## 可用连接 |
| 7 | + |
| 8 | + |
| 9 | +| | CLI | NETCONF,仅限于 `iosxr_banner`、`iosxr_interface`、`iosxr_logging`、`iosxr_system` 与 `ios_user` 模组 | |
| 10 | +| 协议 | SSH | 透过 SSH 的 XML | |
| 11 | +| 凭据 | 若存在 SSH 密钥/ `ssh-agent`,则使用 SSH 密钥/ `ssh-agent`,若使用密码,则接受 `-u my_user -k` | 若存在 SSH 密钥/ `ssh-agent`,则使用 SSH 密钥/ `ssh-agent`,若使用密码,则接受 `-u my_user -k` | |
| 12 | +| 间接访问 | 使用堡垒机(跳转主机) | 使用堡垒机(跳转主机) | |
| 13 | +| 连接设置 | `ansible_connection: ansible.netcommon.network_cli` | `ansible_connection: ansible.netcommon.netconf` | |
| 14 | +| `enable` 模式(权限提升) | 不支持 | 不支持 | |
| 15 | +| 返回数据格式 | 请参考单独模组文档 | 请参考单独模组文档 | |
| 16 | + |
| 17 | + |
| 18 | +`ansible_connection: local` 已被弃用。请使用 `ansible_connection: ansible.netcommon.netconf` 或 `ansible_connection=ansible.netcommon.network_cli` 代替。 |
| 19 | + |
| 20 | + |
| 21 | +## 在 Ansible 中使用 CLI |
| 22 | + |
| 23 | +### 示例 CLI 仓库 `[iosxr:vars]` |
| 24 | + |
| 25 | +```ini |
| 26 | +[iosxr:vars] |
| 27 | +ansible_connection=ansible.netcommon.network_cli |
| 28 | +ansible_network_os=cisco.iosxr.iosxr |
| 29 | +ansible_user=myuser |
| 30 | +ansible_password=!vault... |
| 31 | +ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"' |
| 32 | +``` |
| 33 | + |
| 34 | +{{#include ./ce.md:43:45}} |
| 35 | + |
| 36 | + |
| 37 | +### 示例 CLI 任务 |
| 38 | + |
| 39 | +```yaml |
| 40 | +- name: Retrieve IOS-XR version |
| 41 | + cisco.iosxr.iosxr_command: |
| 42 | + commands: show version |
| 43 | + when: ansible_network_os == 'cisco.iosxr.iosxr' |
| 44 | +``` |
| 45 | +
|
| 46 | +
|
| 47 | +## 在 Ansible 中使用 NETCONF |
| 48 | +
|
| 49 | +
|
| 50 | +### 启用 NETCONF |
| 51 | +
|
| 52 | +在咱们使用 NETCONF 连接交换机前,咱们必须: |
| 53 | +
|
| 54 | +- 使用 `pip install ncclient` 命令,在控制节点上安装 `ncclient` 这个 python 软件包; |
| 55 | +- 在思科 IOS-XR 设备上启用 NETCONF。 |
| 56 | + |
| 57 | + |
| 58 | +要在 Ansible 下于某个新交换机上启用 NETCONF,可通过 CLI 连接使用 `cisco.iosxr.iosxr_netconf` 模组。像上面的 CLI 示例一样,设置咱们的平台级变量,然后运行一个如下的 playbook 任务: |
| 59 | + |
| 60 | + |
| 61 | +```yaml |
| 62 | +- name: Enable NETCONF |
| 63 | + connection: ansible.netcommon.network_cli |
| 64 | + cisco.iosxr.iosxr_netconf: |
| 65 | + when: ansible_network_os == 'cisco.iosxr.iosxr' |
| 66 | +``` |
| 67 | + |
| 68 | +在 NETCONF 启用后,就要把咱们的变量修改为使用 NETCONF 连接。 |
| 69 | + |
| 70 | + |
| 71 | +### 示例 NETCONF 仓库 `[iosxr:vars]` |
| 72 | + |
| 73 | + |
| 74 | +```ini |
| 75 | +[iosxr:vars] |
| 76 | +ansible_connection=ansible.netcommon.netconf |
| 77 | +ansible_network_os=cisco.iosxr.iosxr |
| 78 | +ansible_user=myuser |
| 79 | +ansible_password=!vault | |
| 80 | +ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"' |
| 81 | +``` |
| 82 | + |
| 83 | + |
| 84 | +### 示例 NETCONF 任务 |
| 85 | + |
| 86 | +```yaml |
| 87 | +- name: Configure hostname and domain-name |
| 88 | + cisco.iosxr.iosxr_system: |
| 89 | + hostname: iosxr01 |
| 90 | + domain_name: test.example.com |
| 91 | + domain_search: |
| 92 | + - ansible.com |
| 93 | + - redhat.com |
| 94 | + - cisco.com |
| 95 | +``` |
| 96 | + |
| 97 | +{{#include ./ce.md:193:}} |
0 commit comments