ios_command:连接类型ssh对此模块无效



Ansibleraw命令可以通过SSH工作,但此剧本不能与相同的Cisco命令show version一起工作。

它给出了与SSH相关的错误消息:

致命:〔192.168.1.15〕:失败=>{"changed":false,"msg":"连接类型ssh对此模块无效"}

这是库存/主机文件下的库存

[routers]
192.168.1.15
[routers:vars]
ansible_network_os=ios
ansible_user=admin
ansible_password=admin
ansible_connection=network_cli

以及playbookplaybooks/show_version.yml

---

- name: Cisco show version example
hosts: routers
gather_facts: false
tasks:
- name: run show version on the routers
ios_command:
commands: show version | incl Version
register: output
- name: print output
debug:
var: output.stdout_lines

这是我的文件结构

.
├── ansible.cfg
├── hosts
├── inventory
│   └── host-file
└── playbooks
└── show_version.yml

我确实用下面的命令运行剧本,从playbooks文件夹

ansible-playbook show_version.yml

这是SSH问题吗
有人能分享一些经验吗?

根据您的错误消息

Connection type ssh is not valid for this module

至少变量ansible_connection没有设置应有的值。运行环境的最小工作示例

---
- name: Cisco show version example
hosts: routers
gather_facts: false
vars: # for execution environment

ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
ansible_become: yes
ansible_become_method: enable
tasks:
- name: Gather only the config and default facts
cisco.ios.ios_facts:
gather_subset:
- config
- name: Show facts
debug:
msg: "{{ ansible_facts.net_version }}"

对于给定的注释,也许你可以在你的剧本中添加一个调试任务


- name: Show 'ansible_*' values
debug:
msg: 
- "{{ ansible_network_os }}"
- "{{ ansible_connection }}"
- meta: end_play

看看实际加载了什么。

最新更新