So I use Ansible day-to-day to manage our AWS instances and now I'm testing out managing our network infrastructure (I'm a Network guy, who can do some system admin stuff) but have run into a problem that I can't seem to get around.
I have a Cisco 3750G here that I've enabled SSH on. I can ssh in with the specified user and run all the commands that are failing in my playbook.
I'm able to use the ping module successfully from Ansible to this switch but whenever I try to use the ios_commands
or ios_configs
modules it fails with the errorunable to open shell
.
I'm using Ansible v2.3.1.0 which has persistent connections as a new feature. Done some googling and I've found a few people who have had this issue and have fixed it in various ways (none of which worked for me).
Things I've tried:
- Specified the connection variables in a
secrets.yaml
file. Then specified theprovider
using my username, auth_pass, and password in the secrets file. - Changing the
ansible_connection
setting tolocal
andssh
(neither worked) - Disabled host_key_checking for now in my
ansible.cfg
file
After that didnt work I tried:
- Manually creating the provider connection variables in the playbook
itself.
- Used 2 different modules ios_commands
and ios_configs
(there's some
difference between the 2 modules but for my use both should act the same)
https://docs.ansible.com/ansible/network_debug_troubleshooting.html#category-unable-to-open-shell This doc states that the error I'm seeing is normally an authentication issue but that doesnt seem to be the case here.
Anyone else run into this or have any insight ? I have a log file with the debug output from my playbook run if anyone wants to view that. I've posted my sample playbook below for review.
hosts: switch gather_facts: no connection: local tasks:
- name: GATHER CREDENTIALS
include_vars: secrets.yaml
- name: DEFINE CONNECTION PROVIDER
set_fact:
provider:
username: "{{ creds['username'] }}"
password: " {{ creds['password'] }}"
auth_pass: "{{ creds['auth_pass'] }}"
- name: Show interfaces
ios_config:
provider: "{{ provider }}"
commands:
- show ip int br
register: cisco_int
- debug: var=cisco_int.stdout_lines