-1

I am trying to using the ntc-ansible module with Ansible running on Ubuntu (WSL). I have ssh connectivity to my remote device (Cisco 2960X) and I can run ansible playbooks to the same remote switch using the built in Ansible networking modules (ios_command) and it works fine.

Issue:

When I try to run any of the ntc-ansible modules, it fails, unable to connect to the device. Probably something simple, but I have hit a wall. There is something I am missing about how to use ntc-ansible modules. Ansible is seeing the modules as I can look at the docs as was suggested as a test in the readme.

I have ntc-ansible module installed here: /home/melshman/.ansible/plugins/modules/ntc-ansible I am running my playbooks from here: ~/projects/ansible/ The first time I ran the playbook with the ntc-ansible modules it failed and based on error message and some research I installed sshpass (sudo apt-get install sshpass). But still having ssh problems using ntc-ansible… (playbook and traceback below)

I hear folks taking about an index file, but I can’t find that file? Where does it live and what do I need to do with it?

What is my connection supposed to be setup to be? Local? SSH? Netmiko_ssh?

What should I be using for platform? Cisco_ios? cisco_ios_ssh?

Appreciate any help I can get. I have been running in circles for hours and hours.


Ansible Version Info:

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]

Working playbook (ios_command:) note: ansible_ssh_pass and ansible_user in group var:

- 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"

Playbook (not working) using ntc-ansible module (Note: username and password are defined in Group 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

Here is the traceback I get when the error occurs:

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 VTgroup_SW:22 fatal: [VTgroup_SW]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_RJRY9m/ansible_module_ntc_save_config.py\", line 279, in \n main()\n File \"/tmp/ansible_RJRY9m/ansible_module_ntc_save_config.py\", line 251, in main\n device = ntc_device(device_type, host, username, password, **kwargs)\n File \"/usr/local/lib/python2.7/dist-packages/pyntc-0.0.6-py2.7.egg/pyntc/__init__.py\", line 35, in ntc_device\n return device_class(*args, **kwargs)\n File \"/usr/local/lib/python2.7/dist-packages/pyntc-0.0.6-py2.7.egg/pyntc/devices/ios_device.py\", line 39, in __init__\n self.open()\n File \"/usr/local/lib/python2.7/dist-packages/pyntc-0.0.6-py2.7.egg/pyntc/devices/ios_device.py\", line 55, in open\n verbose=False)\n File \"build/bdist.linux-x86_64/egg/netmiko/ssh_dispatcher.py\", line 178, in ConnectHandler\n File \"build/bdist.linux-x86_64/egg/netmiko/base_connection.py\", line 207, in __init__\n File \"build/bdist.linux-x86_64/egg/netmiko/base_connection.py\", line 693, in establish_connection\nnetmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios VTgroup_SW:22\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}

techraf
  • 64,883
  • 27
  • 193
  • 198
  • Are you sure that is the output you get from that playbook? I say this as the exception output refers to 'ansible_module_ntc_save_config.py'? – Kirk Byers Jul 20 '18 at 17:18
  • You will also probably need to post your inventory file (you can just obscure IP addresses, usernames, passwords). – Kirk Byers Jul 20 '18 at 17:26
  • You are right about the traceback i provided... i think i cut/paste it at one point and then updated the playbook and they got mismatched. Sorry about that if it caused any confusion. – Tim Armstrong Jul 23 '18 at 22:23

1 Answers1

0

Here is a working solution using ntc_show_command to a Cisco IOS device.

- 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'

If you are going to use ntc-templates, I probably would not have the '| include uptime' in the 'show version'. In other words, let TextFSM convert the output to structured data first and then grab the uptime from that structured data.

I modified inventory_hostname to ansible_host to be consistent with my inventory format (my inventory_hostname doesn't actually resolve in DNS).

I modified username and password to 'ansible_user' and 'ansible_ssh_pass' to be consistent with my inventory and also to be more consistent with Ansible 2.5/2.6 variable naming.

On your above issue, your exception message does not match your playbook (i.e. are you sure that is the exception you get for that playbook).

Here is my inventory file (I simplified this to remove some unnecessary devices and to hide confidential information)

[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
Kirk Byers
  • 499
  • 3
  • 7
  • I was able to get everything (ntc_file_copy, ntc_show_command, ntc_config_command, ntc_save_config, ntc_install_os, ntc_reboot) to work as a result of your response. Very much appreciate it! – Tim Armstrong Jul 23 '18 at 22:24
  • Follow up questions: How do I get a access the "module_args" and the "response" from the show_command, ie. if i use "show ip int brief" and i want to know the status of int gi1/0/5. How can I access that? Also, after a device reboot, how can you make the playbook check back in with the device automatically after the lose of connection without manual intervention to verify? Any pointers or suggestions would be great. Thanks Again. – Tim Armstrong Jul 23 '18 at 22:36
  • since these additional questions are off the original subject, I created a new issue here: https://stackoverflow.com/questions/51489156/ntc-ansible-response-and-module-args-how-access – Tim Armstrong Jul 24 '18 at 01:59
  • and also this one regarding the device reboot verification: https://stackoverflow.com/questions/51489915/verify-cisco-ios-switch-after-reboot-ntc-ansible-ntc-reboot – Tim Armstrong Jul 24 '18 at 03:10