0

我的剧本:

- name: get junos facts
  hosts: sw
#  connection: local
  gather_facts: no
  roles:
    - juniper.junos

  tasks:

    - name: Retrieve Junos OS version
      junipernetworks.junos.junos_command:
        commands: show version

主持人:

[sw]
EX4200-2
EX4200-1

变量:

ansible_network_os: juniper_junos

Ansible 配置

ansible-playbook [core 2.12.1]
  config file = /usr/local/san/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/python/python38/lib/python3.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections/ansible_collections
  executable location = /usr/local/python/python38/bin/ansible-playbook
  python version = 3.8.10 (default, Dec 30 2021, 10:44:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
  jinja version = 3.0.3
  libyaml = True

运行剧本的结果

[WARNING]: sftp transfer mechanism failed on [10.1.1.196]. Use ANSIBLE_DEBUG=1 to see detailed information

<10.1.1.196> SSH: EXEC sshpass -d13 scp -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/0d45650285 /root/.ansible/tmp/ansible-local-3715dofr3qmk/tmpiaq5tnso '[10.1.1.196]:'"'"'error: unknown command: /bin/sh/AnsiballZ_junos_command.py'"'"''

[WARNING]: scp transfer mechanism failed on [10.1.1.196]. Use ANSIBLE_DEBUG=1 to see detailed information
<10.1.1.196> ESTABLISH SSH CONNECTION FOR USER: xxx
<10.1.1.196> SSH: EXEC sshpass -d13 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="admin"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/0d45650285 10.1.1.196 'dd of=error: unknown command: /bin/sh/AnsiballZ_junos_command.py bs=65536'
<10.1.1.254> (0, b'\nerror: unknown command: /bin/sh\n', b'')
...
fatal: [EX4200-2]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.1.1.196 closed.\r\n",
    "module_stdout": "\r\nerror: unknown command: /bin/sh\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 0
}

看起来 SCP 和 SFTP 有问题。但是我手动执行SCP和SFTP是正常的。

我该如何解决这个错误?

4

2 回答 2

0

我的配置文件是错误的 vars 添加行: ansible_connection: ansible.netcommon.network_cli

于 2022-02-15T07:46:41.560 回答
0

讯息

MODULE FAILURE
error: unknown command: /bin/sh

表示远程节点上没有外壳、缺少权限等。

正如您已经指出的那样,要使用 Ansible Collection Junipernetworks.Junos中的模块,根据Junos OS 平台选项,必须正确配置连接设置。

---
- name: Get Junos facts
  hosts: sw
  gather_facts: false

  vars:

    ansible_network_os: juniper_junos
    ansible_connection: ansible.netcommon.network_cli
  
  roles:

    - juniper.junos

  tasks:

    - name: Retrieve Junos OS version
      junipernetworks.junos.junos_command:
        commands: show version
      regsiter: show_version

此外,建议在示例junos_facts中使用从运行 Juniper Junos 的远程设备收集事实

- name: Collect default set of facts and configuration
  junipernetworks.junos.junos_facts:
    gather_subset: config
于 2022-02-15T09:45:50.240 回答