networktocode / ntc-ansible Goto Github PK
View Code? Open in Web Editor NEWMulti-vendor network modules
License: Other
Multi-vendor network modules
License: Other
Hi,
I just installed ntc, worked with it for a while and then went back working with other playbooks. When I ran one I got back this error:
fatal: [vbox-pxe]: FAILED! => {"failed": true, "msg": "module (setup) is missing interpreter line"}
soon after that I realized that none of my playbook was working anymore. Since installing ntc was the lat change I made I undid it and everything started working again.
Eventually I tracked down the problem to the fact that the installation guidelines from git also includes a setup.py in the module dir. When working with ntc gather_facts is false so everything works, but when gather_facts is true and setup is ran, because ntc is in the library path, its setup.py gets loaded instead of ansible's setup module, producing the error above.
I can confirm this by deleting setup.py both in ntc-ansible and ntc-templates. When both are gone all my standard playbooks that gather_facts worked again.
I don't know what an appropriate fix is but for now it may be worth to point this out in the installation guidelines.
best,
Add support to ntc-ansible so you can use an ssh key to login to the remote system. use_keys and key_file need to be added as methods so they can be passed to the netmiko module.
- ntc_show_command:
connection=ssh
platform=avaya_ers
command='show vlan'
host="{{ inventory_hostname }}"
username="{{ username }}"
password=""
use_keys=true
key_file="/home/manager/ansible/id_dsa"
I was doing a new install on a freshly built ubuntu 14.04 server.
pip install terminal
. After that everything worked.ntc_reboot
is successfully reloading the devices but is hanging and not completing while running the playbook. Output from playbook with -vvvv
:
TASK [ntc_reboot] **************************************************************
task path: /home/vagrant/shared/upgrade_image_via_scp.yaml:22
<192.168.0.2> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<192.168.0.2> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1467890049.71-207683745299788 `" && echo ansible-tmp-1467890049.71-207683745299788="` echo $HOME/.ansible/tmp/ansible-tmp-1467890049.71-207683745299788 `" ) && sleep 0'
<192.168.0.3> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<192.168.0.3> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1467890049.71-53402090761216 `" && echo ansible-tmp-1467890049.71-53402090761216="` echo $HOME/.ansible/tmp/ansible-tmp-1467890049.71-53402090761216 `" ) && sleep 0'
<192.168.0.1> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<192.168.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1467890049.71-272974655451123 `" && echo ansible-tmp-1467890049.71-272974655451123="` echo $HOME/.ansible/tmp/ansible-tmp-1467890049.71-272974655451123 `" ) && sleep 0'
<192.168.0.2> PUT /tmp/tmprj7rOh TO /home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-207683745299788/ntc_reboot
<192.168.0.2> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-207683745299788/ntc_reboot; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-207683745299788/" > /dev/null 2>&1 && sleep 0'
<192.168.0.1> PUT /tmp/tmp_oQfD8 TO /home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-272974655451123/ntc_reboot
<192.168.0.1> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-272974655451123/ntc_reboot; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-272974655451123/" > /dev/null 2>&1 && sleep 0'
<192.168.0.3> PUT /tmp/tmpiy_vFc TO /home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-53402090761216/ntc_reboot
<192.168.0.3> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-53402090761216/ntc_reboot; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1467890049.71-53402090761216/" > /dev/null 2>&1 && sleep 0'
And it just hangs here at this point.
$ ansible --version
ansible 2.1.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
the relevant playbook:
- name: upgrade image via scp
gather_facts: no
hosts: routers
tasks:
- ntc_file_copy:
local_file: /home/vagrant/shared/images/{{ image_one }}
platform: "{{ platform }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
host: "{{ ansible_host }}"
file_system: "flash0:"
register: scp
- debug: var=scp
- ntc_install_os:
platform: "{{ platform }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
host: "{{ ansible_host }}"
system_image_file: "{{ image_one }}"
register: install
- debug: var=install
- ntc_reboot:
platform: "{{ platform }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
host: "{{ ansible_host }}"
confirm: true
register: reboot
- debug: var=reboot
the rest of the files are in this repo
Sorry, I'm not sure where to start with troubleshooting this.
I'm going to write the template for the NX-OS "show interface brief" command but I'm having some issues with state transitions. (I'm rewriting it since my previous one had some bugs)
My raw file is this:
--------------------------------------------------------------------------------
Port VRF Status IP Address Speed MTU
--------------------------------------------------------------------------------
mgmt0 -- up 10.1.100.20 100 1500
mgmt1 10 down 10.1.100.2 1000 1500
--------------------------------------------------------------------------------
Ethernet VLAN Type Mode Status Reason Speed Port
Interface Ch #
--------------------------------------------------------------------------------
Eth1/1 -- eth routed down Administratively down auto(D) --
Eth1/2 1 eth access down Administratively down auto(D) --
Eth1/3 1 eth access down XCVR not inserted auto(D) --
Eth1/4 2 eth trunk down XCVR not inserted auto(D) 10
Eth1/5 2 eth trunk down XCVR not inserted auto(D) 10
Eth1/8 1 eth access down XCVR not inserted auto(D) --
Eth1/9 1 eth access down XCVR not inserted auto(D) --
Eth1/10 -- eth routed down XCVR not inserted auto(D) --
Eth2/1 -- eth routed down Link not connected auto(D) --
Eth2/2 -- eth routed down Link not connected auto(D) --
Eth2/3 -- eth routed down Link not connected auto(D) --
Eth2/4 -- eth routed down Link not connected auto(D) --
Eth2/5 2 eth trunk down XCVR not inserted auto(D) 12
Eth2/6 2 eth trunk down XCVR not inserted auto(D) 12
Eth2/7 1 eth access down XCVR not inserted auto(D) --
Eth2/8 1 eth access down Administratively down auto(D) --
--------------------------------------------------------------------------------
Port-channel VLAN Type Mode Status Reason Speed Protocol
Interface
--------------------------------------------------------------------------------
Po10 1 eth trunk down No operational members auto(D) lacp
Po11 1 eth trunk down No operational members auto(D) lacp
Po12 1 eth trunk down No operational members auto(D) lacp
--------------------------------------------------------------------------------
Interface Status Description
--------------------------------------------------------------------------------
Lo10 up --
-------------------------------------------------------------------------------
Interface Secondary VLAN(Type) Status Reason
-------------------------------------------------------------------------------
Vlan1 -- down Administratively down
Vlan5 -- down VLAN/BD is down
Vlan10 -- down VLAN/BD is down
Vlan20 -- down VLAN/BD is down
Vlan66 -- down Administratively down
Vlan77 -- down Administratively down
Vlan146 -- down Administratively down
So, I want to build a template with 5 states: MANAGEMENT, ETHERNET, PORTCH, LOOPBACK and VLAN. These are my Values
Value INTERFACE (\S+)
Value VRF (\S+)
Value STATUS (up|down)
Value IP (\d+\.\d+\.\d+\.\d+)
Value SPEED (\S+)
Value MTU (\d+)
Value VLAN ([\d+--]+)
Value TYPE (\S+)
Value MODE (routed|access|trunk)
Value REASON (\S+(\s\S+)*)
Value PORTCH (\S+)
Value DESCRIPTION (\S+(\s\S+)*)
And here it is my first 2 states:
Start
^Port\s+VRF\s+Status\s+IP\s+Address\s+Speed\s+MTU -> Management
Management
^${INTERFACE}\s+${VRF}\s+${STATUS}\s+${IP}\s+${SPEED}\s+${MTU} -> Record
If I test this, I obtain a well parsed table:
FSM Table:
['INTERFACE', 'VRF', 'STATUS', 'IP', 'SPEED', 'MTU', 'VLAN', 'TYPE', 'MODE', 'REASON', 'PORTCH', 'DESCRIPTION']
['mgmt0', '--', 'up', '10.1.100.20', '100', '1500', '', '', '', '', '', '']
['mgmt1', '10', 'down', '10.1.100.2', '1000', '1500', '', '', '', '', '', '']
Then, I want to go back to the Start state as soon as the "-----" pattern is catched and so I update my states:
Start
^Port\s+VRF\s+Status\s+IP\s+Address\s+Speed\s+MTU -> Management
Management
^${INTERFACE}\s+${VRF}\s+${STATUS}\s+${IP}\s+${SPEED}\s+${MTU} -> Record
^.*----- -> Start
But when I test it again I catch absolutely nothing:
FSM Table:
['INTERFACE', 'VRF', 'STATUS', 'IP', 'SPEED', 'MTU', 'VLAN', 'TYPE', 'MODE', 'REASON', 'PORTCH', 'DESCRIPTION']
I understood that, for some reason, TextFSM doesn't recognize the pattern to go back to Start.
The completed template should be this, but it catches nothing
Start
^Port\s+VRF\s+Status\s+IP\s+Address\s+Speed\s+MTU -> Management
^Ethernet\s+VLAN\s+Type\s+Mode\s+Status\s+Reason\s+Speed\s+Port -> Ethernet
^Interface\s+Status\s+Description -> Loopback
^Interface\s+Secondary\s+VLAN\(Type\)\s+Status\s+Reason -> VLAN
Management
^${INTERFACE}\s+${VRF}\s+${STATUS}\s+${IP}\s+${SPEED}\s+${MTU} -> Record
^.*----- -> Start
Ethernet
^${INTERFACE}\s+${VLAN}\s+${TYPE}\s+${MODE}\s+${STATUS}\s+${REASON}\s+${SPEED}\s+${PORTCH} -> Record
^.*----- -> Start
Loopback
^${INTERFACE}\s+${STATUS}\s+${DESCRIPTION} -> Record
^.*----- -> Start
VLAN
^${INTERFACE}\s+${TYPE}\s+${STATUS}\s+${REASON} -> Record
But eventually if I change state transitioning lines like follows, I catch only Management interfaces.
Management
^${INTERFACE}\s+${VRF}\s+${STATUS}\s+${IP}\s+${SPEED}\s+${MTU} -> Record
^\n -> Start
Ethernet
^${INTERFACE}\s+${VLAN}\s+${TYPE}\s+${MODE}\s+${STATUS}\s+${REASON}\s+${SPEED}\s+${PORTCH} -> Record
^\n -> Start
Loopback
^${INTERFACE}\s+${STATUS}\s+${DESCRIPTION} -> Record
^\n -> Start
VLAN
^${INTERFACE}\s+${TYPE}\s+${STATUS}\s+${REASON} -> Record
FSM Table:
['INTERFACE', 'VRF', 'STATUS', 'IP', 'SPEED', 'MTU', 'VLAN', 'TYPE', 'MODE', 'REASON', 'PORTCH', 'DESCRIPTION']
['mgmt0', '--', 'up', '10.1.100.20', '100', '1500', '', '', '', '', '', '']
['mgmt1', '10', 'down', '10.1.100.2', '1000', '1500', '', '', '', '', '', '']
But, again, if I change only the Management line, I start to capture more:
Management
^${INTERFACE}\s+${VRF}\s+${STATUS}\s+${IP}\s+${SPEED}\s+${MTU} -> Record
^.*---- -> Start
Ethernet
^${INTERFACE}\s+${VLAN}\s+${TYPE}\s+${MODE}\s+${STATUS}\s+${REASON}\s+${SPEED}\s+${PORTCH} -> Record
^\n -> Start
Loopback
^${INTERFACE}\s+${STATUS}\s+${DESCRIPTION} -> Record
^\n -> Start
VLAN
^${INTERFACE}\s+${TYPE}\s+${STATUS}\s+${REASON} -> Record
FSM Table:
['INTERFACE', 'VRF', 'STATUS', 'IP', 'SPEED', 'MTU', 'VLAN', 'TYPE', 'MODE', 'REASON', 'PORTCH', 'DESCRIPTION']
['mgmt0', '--', 'up', '10.1.100.20', '100', '1500', '', '', '', '', '', '']
['mgmt1', '10', 'down', '10.1.100.2', '1000', '1500', '', '', '', '', '', '']
['Eth1/1', '', 'down', '', 'auto(D)', '', '--', 'eth', 'routed', 'Administratively down', '--', '']
['Eth1/2', '', 'down', '', 'auto(D)', '', '1', 'eth', 'access', 'Administratively down', '--', '']
['Eth1/3', '', 'down', '', 'auto(D)', '', '1', 'eth', 'access', 'XCVR not inserted', '--', '']
['Eth1/4', '', 'down', '', 'auto(D)', '', '2', 'eth', 'trunk', 'XCVR not inserted', '10', '']
['Eth1/5', '', 'down', '', 'auto(D)', '', '2', 'eth', 'trunk', 'XCVR not inserted', '10', '']
['Eth1/6', '', 'down', '', 'auto(D)', '', '2', 'eth', 'trunk', 'XCVR not inserted', '11', '']
['Eth1/7', '', 'down', '', 'auto(D)', '', '2', 'eth', 'trunk', 'XCVR not inserted', '11', '']
['Eth1/8', '', 'down', '', 'auto(D)', '', '1', 'eth', 'access', 'XCVR not inserted', '--', '']
['Eth1/9', '', 'down', '', 'auto(D)', '', '1', 'eth', 'access', 'XCVR not inserted', '--', '']
['Eth1/10', '', 'down', '', 'auto(D)', '', '--', 'eth', 'routed', 'XCVR not inserted', '--', '']
['Eth2/1', '', 'down', '', 'auto(D)', '', '--', 'eth', 'routed', 'Link not connected', '--', '']
['Eth2/2', '', 'down', '', 'auto(D)', '', '--', 'eth', 'routed', 'Link not connected', '--', '']
['Eth2/3', '', 'down', '', 'auto(D)', '', '--', 'eth', 'routed', 'Link not connected', '--', '']
['Eth2/4', '', 'down', '', 'auto(D)', '', '--', 'eth', 'routed', 'Link not connected', '--', '']
['Eth2/5', '', 'down', '', 'auto(D)', '', '2', 'eth', 'trunk', 'XCVR not inserted', '12', '']
['Eth2/6', '', 'down', '', 'auto(D)', '', '2', 'eth', 'trunk', 'XCVR not inserted', '12', '']
['Eth2/7', '', 'down', '', 'auto(D)', '', '1', 'eth', 'access', 'XCVR not inserted', '--', '']
['Eth2/8', '', 'down', '', 'auto(D)', '', '1', 'eth', 'access', 'XCVR not inserted', '--', '']
['Po10', '', 'down', '', 'auto(D)', '', '1', 'eth', 'trunk', 'No operational members', 'lacp', '']
['Po11', '', 'down', '', 'auto(D)', '', '1', 'eth', 'trunk', 'No operational members', 'lacp', '']
['Po12', '', 'down', '', 'auto(D)', '', '1', 'eth', 'trunk', 'No operational members', 'lacp', '']
['Vlan1', '', 'down', '', '', '', '', '--', '', 'Administratively down', '', '']
['Vlan5', '', 'down', '', '', '', '', '--', '', 'VLAN/BD is down', '', '']
['Vlan10', '', 'down', '', '', '', '', '--', '', 'VLAN/BD is down', '', '']
['Vlan20', '', 'down', '', '', '', '', '--', '', 'VLAN/BD is down', '', '']
['Vlan66', '', 'down', '', '', '', '', '--', '', 'Administratively down', '', '']
['Vlan77', '', 'down', '', '', '', '', '--', '', 'Administratively down', '', '']
['Vlan146', '', 'down', '', '', '', '', '--', '', 'Administratively down', '', '']
Honestly, this is gonna blow my mind D:
I ran into a situation where a customer had this config
"aaa authentication enable default none"
The prompt starts at Priv Level 1, and enable mode does not require a password. They are using Radius, and I think Radius is granting them permission.
I had to modify it to get ntc_ansbile to apply config commands. Ntc_config_command module cannot handle this situation today.
I added an ansible parameter to ntc_config_command called "no_enable_password" - a boolean, including documentation note on it.
It uses the send_command_timing to ignore expect results and just type "enable" with no password for this use-case.
Once enabled, everything continues as normal. It's unusual, and NetMiko does not have a method for enabling without password at this time.
Would you be open to a PR for this setting? I realize it's a bit unusual, and up for debate on if this should be a workaround or something included in NetMiko.
Thanks,
I am at a lost on this but I am trying to write a playbook to test against my Nexus 9K swithces in my lab, but I keep getting this error "ERROR! 'nxos_command' is not a valid attribute for a Play". The back drop story on this is I did a update to Ansible from 2.2 to 2.3 using PIP and I can not seem to get past this syntax error. Can anyone look at my playbook and tell me what I am doing wrong? Here is my playbook.....
vars:
cli:
host: "{{ inventory_hostname }}"
username: admin
password: admin
transport: cli
name: run show version on remote devices
nxos_command:
commands: show version
provider: "{{ cli }}"
...
hey @jtdub, did you test ntc_show_command after you added delay_factor
? :)
I haven't used netmiko
too much but just checked out the code and it looks like delay_factor is a config command and shouldn't be used in the ConnectHandler...
tests from netimiko:
send_command_fast = net_connect.send_command(basic_command, delay_factor=.25)
failed: [spine2] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/home/cisco/.ansible/tmp/ansible-tmp-1446166372.68-170120052390508/ntc_show_command", line 1857, in <module>
main()
File "/home/cisco/.ansible/tmp/ansible-tmp-1446166372.68-170120052390508/ntc_show_command", line 223, in main
password=password
File "/usr/local/lib/python2.7/dist-packages/netmiko/ssh_dispatcher.py", line 54, in ConnectHandler
return ConnectionClass(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'delay_factor'
FATAL: all hosts have already failed -- aborting
I am geting an error during my playbook running .
i am using ntc-ansible and I want to send command from a text file in a Network for routing configuration
code is like this with ntc ansible
name: Inbound command modification
hosts: ciscors
strategy: debug
connection: local
gather_facts: no
vars:
ciscoios: 'ciscors'
ciscoiosssh: 'ciscors_ssh'
localfile: 'C:/Users/sg05477/GNS3/images/IOS.bin'
remotefile: 'c7200-advipservicesk9-mz.152-4.S5.bin'
tasks:
name: Send commands from file
ntc_config_command:
connection: ssh
platform: cisco_ios
commands_file: "send_commands.txt"
host: "{{ inventory_hostname }}"
username: "{{ user }}"
password: "{{ pass }}"
secret: "{{ secret }}"
debug: var=hostvars[inventory_hostname]
#- debug: var=hostvars[user]
#- debug: var=result.response
#- debug: var=result.response.stdout
During running playbook with ansible , i getting error like
PLAY [Inbound command modification] ************************************************************************************************************************************************************************
TASK [Send commands from file] *****************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'output' referenced before assignment
fatal: [192.168.1.11]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File "/tmp/ansible_bJ4FjY/ansible_module_ntc_config_command.py", line 256, in \n main()\n File "/tmp/ansible_bJ4FjY/ansible_module_ntc_config_command.py", line 244, in main\n if (error_params(platform, output)):\nUnboundLocalError: local variable 'output' referenced before assignment\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
Anyone have some solution , how i correct this error.
it will be very helpful.
I think this problem is in ntc_config_command.py file ....
if (error_params(platform, output)):
module.fail_json(msg="Error executing command:\
{}".format(output))
results = {}
results['response'] = output
module.exit_json(changed=True, **results)
Thanks
Samya Ghosh
I add some text in template "cisco_ios_show_version.template" to show RAM and FLASH but it's shown FLASH and can not shown RAM...
How to I fix it?
Value VERSION (.+?)
Value ROMMON (\S+)
Value HOSTNAME (\S+)
Value UPTIME (.+)
Value RUNNING_IMAGE (\S+)
Value List HARDWARE (\S+\d\S+)
Value List SERIAL (\S+)
Value CONFIG_REGISTER (\S+)
** Value FLASH_KB (\S+)
Value RAM_KB (\S+)**Start
^.Software\s.+),\sVersion\s${VERSION},\s+RELEASE.*
^ROM: ${ROMMON}
^\s*${HOSTNAME}\s+uptime\s+is\s+${UPTIME}
^[sS]ystem\s+image\s+file\s+is\s+"(.?):${RUNNING_IMAGE}"
^[Pp]rocessor\s+board\s+ID\s+${SERIAL}
^[Cc]isco\s+${HARDWARE}.+
^[Cc]onfiguration\s+register\s+is\s+${CONFIG_REGISTER}
** ^${FLASH_KB}\s+bytes\s+of\s+ATA
^[Cc]isco\s+.+)+\swith\s+${RAM_KB}***
^Switch Port -> StackStack
^[Ss]ystem [Ss]erial [Nn]umber\s+:\s+${SERIAL}
^[Mm]odel\s+[Nn]umber\s+:\s+${HARDWARE}\s*
^[Cc]onfiguration\s+register\s+is\s+${CONFIG_REGISTER}
And I execute:
haind@ansible:/etc/ansible$ ansible-playbook ntc_show_command.yml
PLAY [Test] ********************************************************************TASK [Test] ********************************************************************
ok: [rpgdGiangVo]TASK [debug] *******************************************************************
ok: [rpgdGiangVo] => {
"results": {
"changed": false,
"response": [
{
"config_register": "0x2102",
"flash_kb": "255744K",
"hardware": [
"CISCO1941/K9"
],
"hostname": "rpgdGiangVo",
"ram_kb": "",
"rommon": "System",
"running_image": "c1900-universalk9-mz.SPA.155-3.M4a.bin",
"serial": [
"FGL154922NZ"
],
"uptime": "16 weeks, 1 day, 3 hours, 51 minutes",
"version": "15.5(3)M4a,"
}
],
"response_list": []
}
}PLAY RECAP *********************************************************************
rpgdGiangVo : ok=2 changed=0 unreachable=0 failed=0
Hi, I am running into the above error with ansible in the virtualenv on CENT OS again.
Previous, I posted an issue with similar setting for ntc_show_command.py which got resolved by setting the python interpreter env variable in host file.
Playbook:
- name: PLAY - BACKUP
hosts: all
gather_facts: no
connection: local
tasks:
- name: SAVE AND BACKUP CONFIGS
ntc_save_config:
local_file={{ inventory_hostname }}.cfg
platform=cisco_ios_ssh
host={{ inventory_hostname }}
username={{ username }}
password={{ password }}
Here is the issue when i run this playbook:
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_t3FItw/ansible_module_ntc_save_config.py", line 230, in
main()
File "/tmp/ansible_t3FItw/ansible_module_ntc_save_config.py", line 217, in main
remote_save_successful = device.save()
File "/data/ansible/lib/python2.7/site-packages/pyntc-0.0.5-py2.7.egg/pyntc/devices/ios_device.py", line 127, in save
self.show('\n')
File "/data/ansible/lib/python2.7/site-packages/pyntc-0.0.5-py2.7.egg/pyntc/devices/ios_device.py", line 105, in show
return self._send_command(command, expect=expect, expect_string=expect_string)
File "/data/ansible/lib/python2.7/site-packages/pyntc-0.0.5-py2.7.egg/pyntc/devices/ios_device.py", line 79, in _send_command
response = self.native.send_command_timing(command)
AttributeError: 'CiscoIosSSH' object has no attribute 'send_command_timing'
fatal: [HOST]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "ntc_save_config"
Is this with pyntc module or netmiko CiscoIosSSH not able to find the attribute specified in the error.
Can you please help or guide how I can fix this.
Also ,would like to know whether ntc-ansible has been tested on CentOS, within virtualenv?.
Most testing seems to be with Ubuntu
Thanks.
I test ntc-ansible with module junos_get_config but when I execute, it's error:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/etc/ansible/junos_get_config.yml': line 12, column 7, but may
be elsewhere in the file depending on the exact syntax problem.The offending line appears to be:
- name: GET CONFIG ^ here
The error appears to have been in '/etc/ansible/junos_get_config.yml': line 12, column 7, but may
be elsewhere in the file depending on the exact syntax problem.The offending line appears to be:
- name: GET CONFIG ^ here
This is my playbook:
name: SHOW CONFIG
hosts: junos
connection: local
gather_facts: Falsetasks:
name: OBTAIN LOGIN CREDENTIALS
include_vars: secrets_tuantv.yamlname: GET CONFIG
junos_get_config:
host: "{{ ansible_host }}"
username: "{{ creds['username'] }}"
password: "{{ creds['password'] }}"
logfile: get_config.log
dest: "/home/haind4/junos/backup/{{ inventory_hostname }}.xml"
format: xml
#filter: "interfaces"
options: {inherit: inherit, groups: groups}
register: resultsdebug: var=results.response
How to fix it!
Hey @ubajze can you re-submit a PR for the show ip route command you did? I merged it, but then realized it had a few items that needed correction.
When installing ntc-ansible using sudo pip install ntc-ansible
the installation of lxml
was failing, causing the installation of ntc-ansible
to fail.
To fix this I had to install the following packages:
$ sudo apt-get -y install zlib1g-dev libxml2-dev libxslt-dev python-dev
This was in a new Ubuntu Trusty64 Vagrant machine.
What's the best approach for handling the results of say a show arp
command? The ansible playbook returns a list of dicts containing items like ip
, mac
, port
, etc. How do I pipe that result into another script?
The ansible community seems to have two approaches that are not ideal. Pass the object to a debug task and parse the output of that task. Or, dump the object as json into a text file. Are these really the only options available? Anyone have any luck using the python API?
Today vendor for TextFSM template and device_type are required as Ansible params. With a new naming convention for templates, we should not require vendor.
Based on issue #12 this may have to be swapped meaning remove device_type, but keep vendor.
While the module currently only supports netmiko device types (SSH), it should support other API types to gather ONLY raw text, i.e. CLI over NX-API, CLI over NETCONF, etc.
Is it intentional that this repository does not have a license?
I just installed ansible on a server in aws and then created a playbook to run the same but while running i am getting error as below :
ERROR! 'copy' is not a valid attribute for a Play
The error appears to have been in '/root/amritha/pega-cloud-infrastructure/ansible/roles/datadog-pegalogs-apptier/tasks/main.yml': line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
name: copy the pattern_search.txt file which has patterns to be grepped ^ here
And my playbook is as follows:
Also please note that i have a directory inside that i have files and tasks folder . and files folder have all mentioned files and tasks folder has the above playbook
Hi,
After cloning ntc-ansible, i tried to launch the following playbook using the example provided but I'm getting the following error. Can you help?
$ ansible-playbook get_vlan.yml
[WARNING]: provided hosts list is empty, only localhost is available
ERROR! 'ntc_show_command' is not a valid attribute for a Play
The error appears to have been in '/Users/SPirrello/Google Drive/Work/scripts/ntc-ansible/get_vlan.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
$ cat get_vlan.yml
Commands with large outputs can take a long time to create and iterate through. We need to utilize netmiko's delay_factor in the send_command function.
https://github.com/ktbyers/netmiko/blob/master/VENDOR.md
I'm planning on making this change and sending a PR when I get a chance.
I am able to use this module to copy a small file from the ansible server to a c6500.
However, when i use this module to copy a c6k image which is 140Mb, I am getting Socket error.
Is there a way to increase the time out for scp with this module.?
Here are the tracebacks
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ck74c2/ansible_module_ntc_file_copy.py", line 262, in
main()
File "/tmp/ansible_ck74c2/ansible_module_ntc_file_copy.py", line 254, in main
device.close()
File "/home/ansible/py27/python2.7/lib/python2.7/site-packages/pyntc-0.0.5-py2.7.egg/pyntc/devices/ios_device.py", line 60, in close
self.native.disconnect()
File "build/bdist.linux-x86_64/egg/netmiko/base_connection.py", line 885, in disconnect
File "build/bdist.linux-x86_64/egg/netmiko/cisco_base_connection.py", line 52, in cleanup
File "build/bdist.linux-x86_64/egg/netmiko/cisco_base_connection.py", line 48, in exit_config_mode
File "build/bdist.linux-x86_64/egg/netmiko/base_connection.py", line 777, in exit_config_mode
File "build/bdist.linux-x86_64/egg/netmiko/cisco_base_connection.py", line 30, in check_config_mode
File "build/bdist.linux-x86_64/egg/netmiko/base_connection.py", line 757, in check_config_mode
File "build/bdist.linux-x86_64/egg/netmiko/base_connection.py", line 99, in write_channel
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 761, in sendall
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 715, in send
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 1081, in _send
socket.error: Socket is closed
Hello,
I want to run this module inside another script.
In my script user provides, username/password/hostname and command line, my script determines which platform is it and then runs those show commands on that router.
Now i want to format return of those show commands, normally i am using netmiko to get the show commands.
my requirement is, i want to call this module directly inside my script and pass username/password/hostname/show command and want a return as json object.
can i call this module directly inside my script and get result as an object ? if i have to use ansible can i create playbook/inventory file dynamically and get the result.
also the script provided doesnt work on latest ansible 2.1. as ansible runner is not supported.
I have an Ansible Playbook that does a ntc_save_config on two test switches and using ntc_get_facts saves the date-stamped config files locally on my Ansible server. The playbook works with the the following AAA config on the switches (local auth):
aaa new-model
aaa authentication login default local
aaa authentication login admin group tacacs+ enable
aaa authorization exec default local none
!
line vty 0 4
privilege level 15
logging synchronous
length 0
login authentication default
transport input telnet ssh
But I need tacacs+, which the Playbook fails with the following AAA config (tacacs+ auth):
aaa new-model
aaa authentication login default local
aaa authentication login admin group tacacs+ enable
aaa authorization exec default local none
!
line vty 0 4
privilege level 15
logging synchronous
length 0
login authentication admin
transport input telnet ssh
Fails with "netmiko.ssh_exception.NetMikoAuthenticationException: Authentication failure: unable to connect cisco_ios "
To summarize: ntc-ansible works with a switch configured for local auth, but fails with a switch configured for tacacs+. I need it to work with tacacs+. thanks
Being new to Git
this is my first issue/question on Ansible. I have started learning & tried to create a play which installs a package on the host listed in the host file.
# ansible-playbook sam.yaml
ERROR! 'yum' is not a valid attribute for a Play
The error appears to have been in '/etc/ansible/sam.yaml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: install
^ here
sam.yml
file output There might be something here which I have missed.
---
- hosts: [mainserver]
remote_user: root
become: yes
tasks:
- name: install
yum: name=httpd state=present
Hi,
first off many thanks for this great module, it's super useful.
I've just followed the installation instructions, the module is installed in $ansible_root/library/ntc and it's correctly found by ansible. However when I test with a sample playbook I get the following error:
fatal: [sw-221]: FAILED! => {"changed": false, "failed": true, "msg": "could not find or read index file"}
looking at the code, that error seems to come from here:
https://github.com/networktocode/ntc-ansible/blob/master/library/ntc_show_command.py#L371 .
I added a module.log() right above to check what the dir evaluated to and I got back the default value, which exists, ie (ntc-templates/templates/index).
I noticed you can specify a path using template_dir so I tried that, using an absolute path, and it worked! This seems to suggest that somehow it's a problem with the relative path, but I'm not sure why, if it's coded this way it must be working for you/others, no clue what's up with my setup that breaks it.
In any case, I tried to log os.getcwd, and if isfile() tries to use a relative path to that, that will indeed not work as in my case that's the plays directory ($ansible_root/plays).
In case it helps here's my dir structure:
tree -L 2 -d
.
├── group_vars
├── host_vars
├── library
│ └── ntc <--- ntc-templates/templates/index exists
├── logs
├── plays
├── roles
...
│ ├── hp-procurve <--- module is used here
...
├── tmp
└── utils
thanks
Not sure if this is an issue with ntc or the core module. I've reinstalled a number of ways, with no luck. It's a simple test which isn't working:
tasks:
ntc_show_command:
ntc_hosts: test
connection=ssh
platform=cisco_ios_ssh
command=show ver
username=admin
password=XXXXXX
TASK [Gathering Facts] ******************************************************************************
fatal: [switch02.backvport.sv2.tellme.com]: FAILED! => {"failed": true, "msg": "module (setup) is missing interpreter line"}
Version info:
ca-cmacnevi-mac:ansible christian.macnevin$ ansible --version
ansible 2.3.0 (devel 65f019fe82) last updated 2016/11/09 09:58:07 (GMT -700)
lib/ansible/modules/core: (detached HEAD 2584fca0ae) last updated 2016/11/09 09:58:29 (GMT -700)
lib/ansible/modules/extras: (detached HEAD a1dcbf9ce5) last updated 2016/11/09 09:58:30 (GMT -700)
config file = /etc/ansible/ansible.cfg
configured module search path = ['/Users/christian.macnevin/ansible/library/']
Please add support for RSA key authentication to the other modules.
I am trying to create a simple file copy playbook however I am having some issues,
Here is the error:
ERROR! 'host' is not a valid attribute for a Play
The error appears to have been in '/var/lib/awx/projects/test/site.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
host: "xxx.xxx.xxx.xxx" (real IP is within the file)
^ here
Here is the playbook:
When using the -vvv debugging level passwords and secrets are visible in plain text
[root@monitornet61 ansible]# ansible-playbook ntc_show_command.yml
PLAY [SHOW CONFIG] *************************************************************
TASK [Show Config] *************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios rcnGiangVo:22
fatal: [rcnGiangVo]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File "/tmp/ansible_eW4Im8/ansible_module_ntc_show_command.py", line 470, in \n main()\n File "/tmp/ansible_eW4Im8/ansible_module_ntc_show_command.py", line 417, in main\n global_delay_factor=global_delay_factor\n File "/usr/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 120, in ConnectHandler\n return ConnectionClass(*args, **kwargs)\n File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 151, in init\n self.establish_connection()\n File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 505, in establish_connection\n raise NetMikoTimeoutException(msg)\nnetmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios rcnGiangVo:22\n", "module_stdout": "", "msg": "MODULE FAILURE"}
to retry, use: --limit @/etc/ansible/ntc_show_command.retryPLAY RECAP *********************************************************************
rcnGiangVo : ok=0 changed=0 unreachable=0 failed=1
I use ntc_show_command for test in my company but it's error!
I test netmiko with:
from netmiko import ConnectHandler
cisco_ios = {
... 'device_type': 'cisco_ios',
... 'ip': '10.0.255.26',
... 'username': 'username',
... 'password': 'password',
... }
And:
output = net_connect.send_command("show ip int brief")
print output
It's ok.
How to fix error with ntc-ansible?
Some information:
I can use command: ssh [email protected] for ssh to device
I can use python netmiko to print output
And my device behine Firewall, I have open rule (ssh port 22)
Hi Guys,
I just wanted to see if there has been any consideration for the same device types, but which return different output (and therefore the one template can't be used..??).
I'll explain where I've run in to this issue.
I am trying to get a structured response for "show mac address table".
On a 6500 chassis running 12.2(33)SXH5, on a WS-SUP720-3B the following is returned:
vlan mac address type learn age ports
------+----------------+--------+-----+----------+--------------------------
* 402 ac87.a30b.5bea dynamic Yes 15 Gi3/19
* --- 0000.0c9f.f92e static No - Router
* 2640 0040.8ce8.04b7 dynamic Yes 0 Po16
310 9890.96d8.3716 dynamic Yes 70 Te7/8
* 1441 0022.9091.54c2 dynamic Yes 0 Po8
* --- 0000.0c9f.f92e static No - Router
270 f8b1.569d.8aa4 dynamic Yes 0 Po17
* 2270 f01f.af14.a877 dynamic Yes 0 Po306
* 2441 0022.9091.49b6 dynamic Yes 5 Gi3/30
But on a WS-C3750G-24PS running 15.0(2)SE4 the following is returned:
All 0180.c200.000f STATIC CPU
All 0180.c200.0010 STATIC CPU
All ffff.ffff.ffff STATIC CPU
1 0024.50dd.9218 DYNAMIC Gi1/0/24
1 0025.8365.d019 DYNAMIC Gi1/0/26
1 0025.8367.4e99 DYNAMIC Gi1/0/27
1 2894.0faa.1806 DYNAMIC Gi1/0/25
270 0000.74cf.08c4 DYNAMIC Gi1/0/25
270 0000.859b.162d DYNAMIC Gi1/0/25
270 000c.293a.a353 DYNAMIC Gi1/0/25
270 000c.293c.b42a DYNAMIC Gi1/0/25
270 000c.2947.f994 DYNAMIC Gi1/0/25
270 000c.2957.1e6e DYNAMIC Gi1/0/25
270 000c.295f.596b DYNAMIC Gi1/0/25
270 000c.2969.161e DYNAMIC Gi1/0/25
270 000c.296c.8a7c DYNAMIC Gi1/0/25
270 000c.2978.f4b7 DYNAMIC Gi1/0/25
Has anyone considered / have a plan on how to get all of the data from both outputs?
'show ip route' template was not parsing correctly when I tested it on Cisco IOS.
Here is the output that it was failing to parse:
pynet-rtr1#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override
Gateway of last resort is 10.220.88.1 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 10.220.88.1
10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 10.220.88.0/24 is directly connected, FastEthernet4
L 10.220.88.20/32 is directly connected, FastEthernet4
I haven't looked at the template much. I wanted to submit this so I didn't forget about it later.
Looks like multiple people have reported this in the closed issue #94
I'm on Ubuntu 16.04.1 LTS. Python 2.7.12, Running in a virtualenv.
All packages present, can import all the modules into python. On running a play I see
FAILED!
=> {"changed": false, "failed": true, "msg": "This module requires TextFSM"}
issue exists with ansible 2.2 and 2.3 and with pip or manually installed gtextfsm
I use ntc-ansible but I can not how do I can hide my password in inventory file?
Because I have any other people to administrator network devices.
Ansible vault just creat .yml
Does anybody know how one would go about matching FSM list items that can, but may not span multiple columns and rows?
For example, each port-channel should have a list of physical interfaces:
Flags
------------------------ ---------------------------- -------------------------
a - LACP Active p - LACP Passive * - static fallback
F - Fallback enabled f - Fallback configured ^ - individual fallback
U - In Use D - Down
+ - In-Sync - - Out-of-Sync i - incompatible with agg
P - bundled in Po s - suspended G - Aggregable
I - Individual S - ShortTimeout w - wait for agg
Number of channels in use: 26
Number of aggregators:26
Port-Channel Protocol Ports
------------ --------- --------------------------------------------------------
Po1(U) LACP(a) Et3/36/1(PG+)
Po25(D) LACP(a) Et3/12/1(G-)
Po101(U) LACP(a) Et3/1/1(PSG+) Et3/1/2(PSG+) Et3/1/3(PSG+) Et3/1/4(PSG+)
Et3/3/1(PSG+) Et3/3/2(PSG+) Et3/3/3(PSG+) Et3/3/4(PSG+)
Po102(U) LACP(a) Et3/2/1(PSG+) Et3/2/2(PSG+) Et3/2/3(PSG+) Et3/2/4(PSG+)
Hi
Thank you for giving ntc-ansible. Will appreciate a little help here.
I have the latest Ansible 2.2 installed in a virtualenv with cent OS. With virtualenv ntc-ansible is not working properly. It gives an error "This module requires TextFSM") even when the gtextfsm modules are present.
The setup does work in a non virtualenv.
How can I make ntc-ansible work within a virtualenv. ??
What am I missing that the textfsm module is not detected properly.
(venv) [ansible@localhost project]$ ansible --version
ansible 2.2.0.0
config file = /home/ansible/project/ansible.cfg
configured module search path = ['/home/ansible/project']
(venv) [ansible@localhost project]$ uname -a
Linux localhost.localdomain 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
(venv) [ansible@localhost project]$
#########################################################################
Ansible/Python path
#########################################################################
(venv) [ansible@localhost project]$ which ansible
~/venv/bin/ansible
(venv) [ansible@localhost project]$ which python
~/venv/bin/python
(venv) [ansible@localhost project]$ more hosts
[cisco:vars]
username=cisco
password=cisco
[cisco]
192.168.56.51
#########################
Ansible Playbook:(venv) [ansible@localhost project]$ more site.yml
#########################
hosts: all
connection: local
gather_facts: False
tasks:
- ntc_show_command:
connection=ssh
platform=cisco_ios_ssh
command='show version'
host={{ inventory_hostname }}
username={{ username }}
password={{ password }}
######################################
Error Running Playbook
#####################################
(venv) [ansible@localhost project]$ pwd
/home/ansible/project
(venv) [ansible@localhost project]$ more site.yml
venv) [ansible@localhost project]$ ansible-playbook site.yml
PLAY [GET STRUCTURED DATA BACK FROM CLI DEVICES] *******************************
TASK [ntc_show_command] ********************************************************
fatal: [192.168.56.51]: FAILED! => {"changed": false, "failed": true, "msg": "This module requires TextFSM"}
to retry, use: --limit @/home/ansible/project/site.retry
PLAY RECAP *********************************************************************
192.168.56.51 : ok=0 changed=0 unreachable=0 failed=1
#########################################################################
PIP List
#########################################################################
(venv) [ansible@localhost project]$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
ansible (2.2.0.0)
cffi (1.9.1)
coverage (4.2)
cryptography (1.5.3)
enum34 (1.1.6)
funcsigs (1.0.2)
functools32 (3.2.3.post2)
future (0.16.0)
gtextfsm (0.2.1)
idna (2.1)
ipaddress (1.0.17)
Jinja2 (2.8)
jsonschema (2.5.1)
junos-eznc (2.0.1)
lxml (3.6.4)
MarkupSafe (0.23)
mock (2.0.0)
ncclient (0.5.2)
netaddr (0.7.18)
netmiko (1.1.0)
ntc-ansible (0.1.0)
paramiko (2.0.2)
pbr (1.10.0)
pip (9.0.1)
pyasn1 (0.1.9)
pycparser (2.17)
pycrypto (2.6.1)
pyeapi (0.7.0)
pyntc (0.0.5)
pynxos (0.0.3)
pyserial (3.2.1)
PyYAML (3.12)
requests (2.11.1)
scp (0.10.2)
setuptools (28.8.0)
six (1.10.0)
terminal (0.4.0)
wheel (0.30.0a0)
(venv) [ansible@localhost project]$
/home/ansible/venv/lib/python2.7/site-packages
(venv) [ansible@localhost site-packages]$ ls -l
total 1600
--snip--
-rw-rw-r--. 1 ansible ansible 52010 Nov 12 14:09 gtextfsm-0.2.1-py2.7.egg
-rw-rw-r--. 1 ansible ansible 533 Nov 14 21:36 gtextfsm-0.2.1-py2.7.egg-info
--snip--
drwxrwxr-x. 2 ansible ansible 4096 Nov 14 21:36 textfsm
--snip--
Is there a way to make some arguments to ntc_show_command module optional?
I ask because I am running playbooks from Rundeck with the plugin rundeck-ansible-plugin from Batix, and all connection/authentication parameters get fed from there.
So a entire playbook using the ios_command module looks like this:
name: Show VLAN
hosts: alltasks:
- name: Show VLAN
ios_command:
commands:
- show vlan
Using the ntc_show_command module the same playbook looks like this:
name: Show VLAN
hosts: alltasks:
- ntc_show_command:
host: "{{ inventory_hostname }}"
username: netadmin
password: supersecret
connection: ssh
platform: cisco_ios
command: 'show vlan'
template_dir: /etc/ansible/modules/ntc-ansible/ntc-templates/templates/
Looking to streamline/standardize how my jobs in Rundeck are defined, and leverage the password vault it has, but also looking to take advantage of the improved output parsing that NTC modules provide.
Thanks!
Hi, am new here. I was wondering if somebody could help me out. I am seeing the problem "msg": "could not find or read index file". Although I have tried to directly point the index file in the yaml file but to no avail. Below is my entire error message and yaml file.
Thanks in advance.
TASK [GET LLDP NEIGHBORS] ******************************************************
task path: /home/user/ansible-files/ntc-ansible/ntc-templates/templates/auto-config-port-descriptions.yaml:16
Using module file /home/user/ansible-files/ntc-ansible/library/ntc_show_command.py
ESTABLISH LOCAL CONNECTION FOR USER: root
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo $HOME/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550" && echo ansible-tmp-1480704963.75-150827960692550="echo $HOME/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550" ) && sleep 0'
PUT /tmp/tmpqGzeVA TO /home/user/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550/ntc_show_command.py
EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550/ /home/user/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550/ntc_show_command.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python /home/user/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550/ntc_show_command.py; rm -rf "/home/user/.ansible/tmp/ansible-tmp-1480704963.75-150827960692550/" > /dev/null 2>&1 && sleep 0'
fatal: [c3548]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"command": "show lldp neighbors",
"connection": "ssh",
"delay": "1",
"file": null,
"host": "c3548",
"index_file": "/home/user/ansible-files/ntc-ansible/ntc_templates/templates",
"key_file": null,
"local_file": null,
"optional_args": {},
"password": "xxxxxxxx",
"platform": "cisco_nxos",
"port": "22",
"secret": null,
"template_dir": "/home/user/ansible-files/ntc-ansible/ntc_templates/templates",
"trigger_device_list": null,
"use_keys": false,
"use_templates": true,
"username": "admin"
},
"module_name": "ntc_show_command"
},
"msg": "could not find or read index file"
}
to retry, use: --limit @/home/user/ansible-files/ntc-ansible/ntc-templates/templates/auto-config-port-descriptions.retry
PLAY RECAP *********************************************************************
c3548 : ok=1 changed=0 unreachable=0 failed=1
YAML FILE:
What are your thoughts on using the changed variable in ntc_show_command?
For example:
results = {}
results['response'] = structured_data
if not results['response']:
module.exit_json(changed=False)
else:
module.exit_json(changed=True, **results)
Some commands that I execute, don't have a matching output on all devices. I end up with output like:
ok: [router1] => {
"output.response": []
}
ok: [router2] => {
"output.response": "{{output.response}}"
}
ok: [router3] => {
"output.response": [
{
"key": "value"
}
]
}
In my use-case, I want to execute a task to build and push configurations to remediate devices, based on the results of the audit in Ansible.
For example, I'd like to do something like:
- name: build remediation
template:
src=templates/some_config.j2
dest=output/{{ inventory_hostname }}_some_config.conf
when: output.changed
Thoughts?
I have noticed that in the following situation the cisco_ios_show_interfaces_status.template will skip over the interface G1/3 because its in the err-disabled state. I believe the template needs to be updated to "Value STATUS ([\w-]+)"
#sh int statu
Port Name Status Vlan Duplex Speed Type
Gi1/1 connected 41 a-full a-1000 10/100/1000-TX
Gi1/2 connected 41 a-full a-1000 10/100/1000-TX
Gi1/3 err-disabled 41 auto auto 10/100/1000-TX
Gi1/4 connected 41 a-full a-1000 10/100/1000-TX
With ansible 2.0.0.2, ansible-playbook test-template.yml
fails for the task "extract command string from command_variable" with the following error:
TASK [extract command string from command_variable] ****************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! template error while templating string: unexpected 'end of template'"}
Is there a reason why two modules are missing their .py
extension?
I think the directory name changed from ntc_templates to ntc-templates.
Broke my code :-(
I know; tweaky change; but it could break lots of code.
That being said, really appreciate all the effort.
I am trying to use the show ip int brief command and then use a variable from it do a show run int {{ variable }} Below is my code. I am wanting to reference one key out the list of dictionaries but not able to get it to work.
name: COLLECT DATA TEST
hosts: iosrouters
gather_facts: no
connection: local
tasks:
name: GET INTERFACES
ntc_show_command:
connection=ssh
platform={{ vendor }}{{ os }}{{ api }}
index_file=index
template_dir=/usr/lib/python2.7/dist-packages/ansible/modules/ntc-ansible/ntc-templates/templates
command='show ip int brief'
host={{ inventory_hostname }}
username={{ un }}
password={{ pwd }}
tags: test
register: interfaces
name: SET FACT
set_fact:
interface: "{{ interfaces.response }}"
tags: test
name: GET INTERFACES
ntc_show_command:
connection=ssh
platform={{ vendor }}{{ os }}{{ api }}
index_file=interface.index
template_dir=/usr/lib/python2.7/dist-packages/ansible/modules/ntc-ansible/ntc-templates/templates
command="show run int {{ item.intf }}" <--- where I am having issues tried
host={{ inventory_hostname }}
username={{ un }}
password={{ pwd }}
tags: test
with_items: "{{ interface }}"
register: interfaceinfo
Hi,
I am working with Juniper Junos device (MX, EX). I want to send file from ansible server (or ftp/sftp/http server) to target host. I see that your module did not support Juniper junos. Have you planning to support Juniper Junos?
Running a playbook to download all of my configs for 2960's.
...
tasks:
When executed it's able to get to the device but all devices get back
'IOError: Search pattern never detected in send_command_expect: ATL1-OS3P-2960-11034-R1C5#'
Reviewing, I can see that it's not expecting a prompt to occur, and with IOS a prompt occurs.
I tried to tackle this but not sure if editing your code or netmiko was the way to go.
Or I can just run this command on everything
"(config)#file prompt quiet"
and call it a day.
regardless out of the box it doesn't work.
Hi,
I am trying to make connection with my hp/cisco switches by using ntc modules but always i get some kind of errors. I have no idea what am i doing wrong. Below i present my configurations and output of errors. I was testing this on ansible with version 2.3.0 and 1.9.4 and always i get an error.
testbook.yml:
- name: HP testing
hosts: hp
tasks:
- name: GET DATA
ntc_show_command:
connection: ssh
platform: "{{ platform }}"
command: show version
host: "{{ ansible_ssh_host }}"
username: "{{ ansible_ssh_user }}"
password: "{{ ansible_ssh_pass }}"
...
hosts:
[hp]
switch1
[hp:vars]
platform = hp_procurve
ansible_ssh_user=user
ansible_ssh_pass=pass
ansible_ssh_host=10.167.156.216
output after commands: ansible-playbook -vvvv -i hosts testbook.yml
PLAYBOOK: testbook.yml *********************************************************
1 plays in testbook.yml
PLAY [HP testing] **************************************************************
TASK [setup] *******************************************************************
Using module file /home/as/tmp/ansible/lib/ansible/modules/core/system/setup.py
<10.167.156.216> ESTABLISH CONNECTION FOR USER: user on PORT 22 TO 10.167.156.216
<10.167.156.216> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1476480494.44-205322436109200 `" && echo ansible-tmp-1476480494.44-205322436109200="` echo $HOME/.ansible/tmp/ansible-tmp-1476480494.44-205322436109200 `" ) && sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/home/as/tmp/ansible/lib/ansible/executor/task_executor.py", line 122, in run
res = self._execute()
File "/home/as/tmp/ansible/lib/ansible/executor/task_executor.py", line 488, in _execute
result = self._handler.run(task_vars=variables)
File "/home/as/tmp/ansible/lib/ansible/plugins/action/normal.py", line 33, in run
results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
File "/home/as/tmp/ansible/lib/ansible/plugins/action/__init__.py", line 573, in _execute_module
tmp = self._make_tmp_path(remote_user)
File "/home/as/tmp/ansible/lib/ansible/plugins/action/__init__.py", line 221, in _make_tmp_path
result = self._low_level_execute_command(cmd, sudoable=False)
File "/home/as/tmp/ansible/lib/ansible/plugins/action/__init__.py", line 727, in _low_level_execute_command
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
File "/home/as/tmp/ansible/lib/ansible/plugins/connection/paramiko_ssh.py", line 284, in exec_command
chan.exec_command(cmd)
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 60, in _check
return func(self, *args, **kwds)
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 234, in exec_command
self._wait_for_event()
File "build/bdist.linux-x86_64/egg/paramiko/channel.py", line 1109, in _wait_for_event
raise e
SSHException: Channel closed.
fatal: [switch1]: FAILED! => {
"failed": true,
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
to retry, use: --limit @/home/X/testbook.retry
PLAY RECAP *********************************************************************
switch1 : ok=0 changed=0 unreachable=0 failed=1
Thanks for any kind of help.
I'm trying to zeroize the crypto keys on IOS devices and recreate them. IOS prompts the below. At the prompt I want to enter "yes". At first glance I think I need to modify the base_connection.py script from netmiko, but maybe I'm wrong. Is the module able to handle prompts in an "expect" like manner?
% All keys will be removed.
% All router certs issued using these keys will also be removed.
Do you really want to remove these keys? [yes/no]:
Error - An exception occurred during task execution. To see the full traceback, use -vvv. The error was: netmiko.ssh_exception.NetMikoTimeoutException: Timed-out reading channel, data not available.
I'm getting a "pyntc Python library not found." error when I try to run the ntc_copy_file module (or any module that depends on pyntc). I already have pyntc installed and cannot figure out why I keep getting this error. Any insight would be great.
tasks:
Thanks,
Anas
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.