|
13 | 13 | | 间接访问 | 使用堡垒机(跳转主机) | 使用堡垒机(跳转主机) |
|
14 | 14 | | 连接设置 | `ansible_connection: ansible.netcommon.network_cli` | `ansible_connection: ansible.netcommon.netconf` |
|
15 | 15 | | `enable` 模式(权限提升) | 不受 Junos OS 支持 | 不受 Junos OS 支持 |
|
16 |
| -| 返回数据格式 | `stdout[0].` | <li>json: <code>result[0]['software-information'][0]['host-name'][0]['data'] foo lo0</code></li><li>text: <code>result[1].software-information[0].physical-interface[0].name[0].data foo lo0</code></li><li>xml: <code>result[1].rpc-reply.interface-information[0].physical-interface[0].name[0].data foo lo0</code></li> |
| 16 | +| 返回数据格式 | `stdout[0].` | <li>json: <code>result[0]['software-information'][0]['host-name'][0]['data'] foo lo0</code></li><li>text: <code>result[1].interface-information[0].physical-interface[0].name[0].data foo lo0</code></li><li>xml: <code>result[1].rpc-reply.interface-information[0].physical-interface[0].name[0].data foo lo0</code></li> |
17 | 17 |
|
18 | 18 |
|
19 | 19 | `ansible_connection: local` 已被弃用。请使用 `ansible_connection: ansible.netcommon.netconf` 或 `ansible_connection=ansible.netcommon.network_cli` 代替。
|
| 20 | + |
| 21 | + |
| 22 | +## 在 Ansible 中使用 CLI |
| 23 | + |
| 24 | +### 示例 CLI 仓库变量 `[junos:vars]` |
| 25 | + |
| 26 | + |
| 27 | +```ini |
| 28 | +[junos:vars] |
| 29 | +ansible_connection=ansible.netcommon.network_cli |
| 30 | +ansible_network_os=junipernetworks.junos.junos |
| 31 | +ansible_user=myuser |
| 32 | +ansible_password=!vault... |
| 33 | +ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"' |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +{{#include ./ce.md:43:45}} |
| 38 | + |
| 39 | + |
| 40 | +### 示例 CLI 任务 |
| 41 | + |
| 42 | + |
| 43 | +```yaml |
| 44 | +- name: Retrieve Junos OS version |
| 45 | + junipernetworks.junos.junos_command: |
| 46 | + commands: show version |
| 47 | + when: ansible_network_os == 'junipernetworks.junos.junos' |
| 48 | +``` |
| 49 | +
|
| 50 | +
|
| 51 | +## 在 Ansible 中使用 NETCONF |
| 52 | +
|
| 53 | +### 启用 NETCONF |
| 54 | +
|
| 55 | +
|
| 56 | +在咱们可以使用 NETCONF 连接交换机前,咱们必须: |
| 57 | +
|
| 58 | +- 使用 `pip install ncclient`(`python -m pip install ncclient`)命令,在控制节点上安装 `ncclient` 这个 python 软件包; |
| 59 | +- 在 Junos OS 设备上启用 NETCONF。 |
| 60 | + |
| 61 | + |
| 62 | +要经由 Ansible 在新交换机上启用 NETCONF,就要通过 CLI 连接使用 `junipernetworks.junos.junos_netconf` 这个模组。像上面的 CLI 示例中一样,设置咱们平台级变量,然后运行一个如下的 playbook 任务: |
| 63 | + |
| 64 | + |
| 65 | +```yaml |
| 66 | +- name: Enable NETCONF |
| 67 | + connection: ansible.netcommon.network_cli |
| 68 | + junipernetworks.junos.junos_netconf: |
| 69 | + when: ansible_network_os == 'junipernetworks.junos.junos' |
| 70 | +``` |
| 71 | + |
| 72 | +启用 NETCONF 后,就要修改咱们的变量,以使用 NETCONF 连接。 |
| 73 | + |
| 74 | + |
| 75 | +### 示例 NETCONF 仓库的 `[junos:vars]` |
| 76 | + |
| 77 | + |
| 78 | +```ini |
| 79 | +[junos:vars] |
| 80 | +ansible_connection=ansible.netcommon.netconf |
| 81 | +ansible_network_os=junipernetworks.junos.junos |
| 82 | +ansible_user=myuser |
| 83 | +ansible_password=!vault | |
| 84 | +ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"' |
| 85 | +``` |
| 86 | + |
| 87 | + |
| 88 | +### 示例 NETCONF 任务 |
| 89 | + |
| 90 | +```yaml |
| 91 | +- name: Backup current switch config (junos) |
| 92 | + junipernetworks.junos.junos_config: |
| 93 | + backup: yes |
| 94 | + register: backup_junos_location |
| 95 | + when: ansible_network_os == 'junipernetworks.junos.junos' |
| 96 | +``` |
| 97 | + |
| 98 | +{{#include ./ce.md:193:}} |
0 commit comments