ios_command failed to connect Cisco SF300

30 views
Skip to first unread message

Romain CYRILLE

unread,
Mar 31, 2017, 6:44:50 AM3/31/17
to Ansible Project
Hello,

I am trying to use Ansible with Cisco SF300 switches. I use a basic playbook that retrieve the version : 


---
- hosts: ios_devices
  gather_facts
: no
  connection
: local
     


  vars_prompt
:
 
- name: "mgmt_username"
    prompt
: "Username"
   
private: no
 
- name: "mgmt_password"
    prompt
: "Password"


  tasks
:
 
- name: SYS | Define provider
    set_fact
:
      provider
:
        host
: "{{ inventory_hostname }}"
        username
: "{{ mgmt_username }}"
        password
: "{{ mgmt_password }}"


 
- name: IOS | Show clock
    ios_command
:
      provider
: "{{ provider }}"
      commands
:
       
- show version
   
register: version


 
- debug: msg="{{ version.stdout }}"

I have the following error : 
fatal: [hostname]: FAILED! => {"changed": false, "failed": true, "msg": "failed to connect to hostname"}

I found why : if I had the following configuration ip ssh password-auth to the switch, it is working.

From the cisco guide : Use the ip ssh password-auth Global Configuration mode command to enable password authentication of incoming SSH sessions.


The thing is normally when I connect to a switch by ssh, I am still asked for a user name and password after being connected before entering commands. 

I tried the option authorize of the ios_command module but it's not working.

I could manually add this configuration of the ssh server on every switch but it is a long job to do. 

Do you have any other solutions ?

Have a nice day !

Romain



Reply all
Reply to author
Forward
0 new messages