我正在尝试将ntc-ansible
模块与在Ubuntu(WSL)上运行的Ansible结合使用。我可以通过SSH连接到远程设备(Cisco 2960X),并且可以使用内置的Ansible网络模块(ios_command
)在同一台远程交换机上运行ansible剧本,并且工作正常。
问题:
当我尝试运行任何可与ntc兼容的模块时,它会失败,无法连接到设备。可能很简单,但是我碰壁了。我缺少有关如何使用ntc-ansible模块的信息。 Ansible正在查看模块,正如我在自述文件中作为测试所建议的那样,我可以查看文档。
我在此处安装了ntc-ansible模块:/home/melshman/.ansible/plugins/modules/ntc-ansible 我正在从这里运行我的剧本:〜/ projects / ansible / 第一次使用ntc-ansible模块运行剧本时,它失败了,并且基于错误消息和一些研究,我安装了sshpass(sudo apt-get install sshpass)。但是使用ntc-ansible仍然存在ssh问题……(下面的播放簿和追溯)
我听说有人正在使用索引文件,但是找不到该文件?它住在哪里,我需要做什么?
我应该设置的连接是什么?本地? SSH? Netmiko_ssh?
我应该在平台上使用什么? Cisco_ios? cisco_ios_ssh?
感谢我可以获得的任何帮助。我已经在圈子里跑了好几个小时了。
Ansible版本信息:
VTMNB17024:~/projects/ansible $ ansible --version
ansible 2.5.3
config file = /home/melshman/projects/ansible/ansible.cfg
configured module search path = [u'/home/melshman/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
有效的剧本(ios_command :)注意:var组中的ansible_ssh_pass和ansible_user:
- name: Test Net Automation
hosts: ctil-ios-upgrade
connection: local
gather_facts: no
tasks:
- name: Grab run config
ios_command:
commands:
- show run
register: config
- name: Create backup of running configuration
copy:
content: "{{config.stdout[0]}}"
dest: "backups/show_run_{{inventory_hostname}}.txt"
使用ntc-ansible
模块的剧本(不起作用)(注意:用户名和密码在VAR组中定义:
- name: Cisco IOS Automation
hosts: ctil-ios-upgrade
connection: local
gather_facts: no
tasks:
- name: GET UPTIME
ntc_show_command:
connection: ssh
platform: "cisco_ios"
command: 'show version | inc uptime'
host: "{{ inventory_hostname }}"
username: "{{ username }}"
password: "{{ password }}"
use_templates: True
template_dir: /home/melshman/.ansible/plugins/modules/ntc-ansible/ntc-templates/templates
这是发生错误时得到的回溯:
任务执行期间发生异常。要查看完整的回溯,请使用-vvv。错误是:netmiko.ssh_exception.NetMikoTimeoutException:连接到设备超时:cisco_ios VTgroup_SW:22 致命的:[VTgroup_SW]:失败! => {“已更改”:false,“ module_stderr”:“追踪(最近一次通话最近):\ n文件\” / tmp / ansible_RJRY9m / ansible_module_ntc_save_config.py \“,行279,在\ n main()\ n文件中\“ / tmp / ansible_RJRY9m / ansible_module_ntc_save_config.py \”,主设备中的第251行\ n device = ntc_device(设备类型,主机,用户名,密码,** kwargs)\ n文件\“ / usr / local / lib / python2。 7 / dist-packages / pyntc-0.0.6-py2.7.egg / pyntc / __ init __。py \“,第35行,在ntc_device \ n中返回device_class(* args,** kwargs)\ n文件\” / usr /local/lib/python2.7/dist-packages/pyntc-0.0.6-py2.7.egg/pyntc/devices/ios_device.py \“,第39行,位于__init __ \ n self.open()\ n文件中\“ / usr / local / lib / python2.7 / dist-packages / pyntc-0.0.6-py2.7.egg / pyntc / devices / ios_device.py \”,第55行,以open \ n verbose = False) \ n ConnectHandler中的文件“ build / bdist.linux-x86_64 / egg / netmiko / ssh_dispatcher.py \”,行178 \ n文件\“ build / bdist.linux-x86_64 / egg / netmiko / base_connection.py \” __init __ \ n文件\“ build / bdist.linux-x86_64 / egg / netmiko / bas”中的第207行e_connection.py \“,在Establishment_connection \ nnetmiko.ssh_exception.NetMikoTimeoutException中的第693行:与设备超时的连接:cisco_ios VTgroup_SW:22 \ n”,“ module_stdout”:“”,“ msg”:“模块失败”,“ rc“:1}
答案 0 :(得分:0)
这是使用ntc_show_command到Cisco IOS设备的有效解决方案。
- name: Cisco IOS Automation
hosts: pynet-rtr1
connection: local
gather_facts: no
tasks:
- name: GET UPTIME
ntc_show_command:
connection: ssh
platform: "cisco_ios"
command: 'show version'
host: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_ssh_pass }}"
use_templates: True
template_dir: '/home/kbyers/ntc-templates/templates'
如果要使用ntc模板,我可能不会使用'|在“显示版本”中包括“正常运行时间”。换句话说,让TextFSM首先将输出转换为结构化数据,然后从该结构化数据中获取正常运行时间。
我将stockstock_hostname修改为ansible_host,使其与我的广告资源格式一致(我的ventory_hostname实际上无法在DNS中解析)。
我将用户名和密码修改为“ ansible_user”和“ ansible_ssh_pass”,以与清单保持一致,并与Ansible 2.5 / 2.6变量命名更加一致。
在上述问题上,您的异常消息与您的剧本不符(即您确定那是该剧本的异常)。
这是我的清单文件(我简化了此操作以删除一些不必要的设备并隐藏机密信息)
[all:vars]
ansible_connection=local
ansible_python_interpreter=/home/kbyers/VENV/ansible/bin/python
ansible_user=user
ansible_ssh_pass=password
[local]
localhost ansible_connection=local
[cisco]
pynet-rtr1 ansible_host=cisco1.domain.com
pynet-rtr2 ansible_host=cisco2.domain.com