0

I'm not able to run ios_command module in Ansible 2.1 for executing commands on my cisco routers.

I've written a playbook for testing ios_command module on cisco routers.

Following is the playbook I wrote

---
  - hosts: router2

   tasks:

     - ios_command:

        username: cisco

        password: cisco

#         host: router2.3node.example.com

        commands:

          - show version

        register: output

     - debug: msg="Hello World! {{ output.stdout }}"

But the playbook fails with the following message :

fatal: [router2.3node.example.com]: UNREACHABLE! => {"changed": false, 
"msg": "Failed to connect to the host via ssh.", "unreachable": true}

and value unreachable=1

Also find the output while run on debug mode:

TASK [setup] 
*******************************************************************

Using module file /home/cisco/ansible_dev/ansible/lib/ansible/modules
/core/system/setup.py

<router2.3node.example.com> ESTABLISH SSH CONNECTION FOR USER: None

<router2.3node.example.com> SSH: EXEC ssh -C -q -o ControlMaster=auto 
-o ControlPersist=60s -o KbdInteractiveAuthentication=no -o 
PreferredAuthentications=gssapi-with-mic,gssapi-
keyex,hostbased,publickey -o PasswordAuthentication=no -o 
ConnectTimeout=10 -o ControlPath=/home/cisco/.ansible/cp/ansible-
ssh-%h-%p-%r router2.3node.example.com '/bin/sh -c '"'"'( umask 77 && 
mkdir -p "` echo $HOME/.ansible/tmp/ansible-
tmp-1464109982.9-18150317646623 `" && echo ansible-
tmp-1464109982.9-18150317646623="` echo $HOME/.ansible/tmp/ansible-
tmp-1464109982.9-18150317646623 `" ) && sleep 0'"'"''



fatal: [router2.3node.example.com]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}

Please let me know if someone has tried the same and solved this problem.

fernandezcuesta
  • 2,390
  • 1
  • 15
  • 32
mattdave
  • 37
  • 9

1 Answers1

3

please try add following two lines in your playbook:

  gather_facts: no
  connection: local
wanglf
  • 63
  • 5