cannot login to cisco switch using ansible

test@TESTVM:/etc/ansible$ ansible-playbook ios_facts.yml
[WARNING] Ansible is in a world writable directory (/etc/ansible), ignoring it as an ansible.cfg source.

PLAY [Collect IOS Device Facts] ************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************
fatal: [10.208.0.17]: FAILED! => {“msg”: " [WARNING] Ansible is in a world writable directory (/etc/ansible), ignoring it as an ansible.cfg source.\n{"socket_path": "/home/test/.ansible/pc/12ac842f48", "exception": "Traceback (most recent call last):\n File \"/usr/bin/ansible-connection\", line 87, in start\n self.connection._connect()\n File \"/usr/lib/python2.7/dist-packages/ansible/plugins/connection/network_cli.py\", line 302, in _connect\n self._ssh_shell = ssh.ssh.invoke_shell()\nNameError: global name ‘ssh’ is not defined\n", "messages": ["local domain socket does not exist, starting it", "control socket path is /home/test/.ansible/pc/12ac842f48", ""], "error": "global name ‘ssh’ is not defined"}"}
to retry, use: --limit @/etc/ansible/ios_facts.retry

PLAY RECAP *********************************************************************************************************************************************************************************
10.208.0.17 : ok=0 changed=0 unreachable=0 failed=1

test@TESTVM:/etc/ansible$

This might solve your issue: https://medium.com/@andrewhowdencom/the-curious-case-of-sudden-ansible-build-failures-eef1cf9ad1d0

If it doesn’t, can you also post the file permissions and content of ansible.cfg and ios_facts.yml?

Regards,
Ajay

I cannot understand what to do from the link you sent me, I am still new in Ansible.

Here is the permission and content of ansible.cfg file

1.Permission:

First of all, try executing this command: “chmod 700 /etc/ansible” and run the playbook again (since you are using network_cli as connection type, I assume you also defined ansible_network_os as ios)

Suggestions:

  1. Don’t use the default ansible.cfg file, it’s too big to track all the changes we made
  2. https://docs.ansible.com/ansible/latest/network/index.html” is a good place to start if you haven’t checked already

“I think I have a problem with ssh but i do not understand how to fix it” - Can you directly ssh to the device from the VM you are using?

Let me know if that works.

Regards,
Ajay

Hi Ajay,

  • Tried to chmod 700, it gave me the following error

test@TESTVM:/etc$ sudo chmod 700 /etc/ansible

sudo: /etc/sudoers is world writable

sudo: no valid sudoers sources found, quitting

sudo: unable to initialize policy plugin

  • I think I have bigger issue than Ansible now, it is a permission issue on Ubuntu box, any suggestions?

Thanks,

Michael

I was able to fix the permission on Ubuntu, now back to the original error:

ansible all -i <switch_ip>, -c network_cli -u -m ios_command_1.yml

[WARNING] Ansible is in a world writable directory (/etc/ansible), ignoring it as an ansible.cfg source.

10.11.32.100 | FAILED! => {

“msg”: " [WARNING] Ansible is in a world writable directory (/etc/ansible), ignoring it as an ansible.cfg source.\n{"socket_path": "/home/test/.ansible/pc/c5b7c67eba", "exception": "Traceback (most recent call last):\n File \"/usr/bin/ansible-connection\", line 87, in start\n self.connection._connect()\n File \"/usr/lib/python2.7/dist-packages/ansible/plugins/connection/network_cli.py\", line 302, in _connect\n self._ssh_shell = ssh.ssh.invoke_shell()\nNameError: global name ‘ssh’ is not defined\n", "messages": ["local domain socket does not exist, starting it", "control socket path is /home/test/.ansible/pc/c5b7c67eba", ""], "error": "global name ‘ssh’ is not defined"}"

}

Do you know any straight forward fix?

Thanks,

Michael

Hi Michael,

I don’t know any straight forward fix.

So, did chmod 700 on /etc/ansible work? Is the playbook still giving the same error after the file permissions were changed?

Regards,
Ajay

Hi Ajay,

I was able to build a new machine, still having same issue ansible & ssh permission issue:

netadmin@netadmin-Virtual-Machine:/etc/ansible/myplatform$ ansible --version
ansible 2.5.7
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/home/netadmin/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
netadmin@netadmin-Virtual-Machine:/etc/ansible/myplatform$ ls
ios.retry ios.yml
netadmin@netadmin-Virtual-Machine:/etc/ansible/myplatform$ ansible --version
ansible 2.5.7
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/home/netadmin/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
netadmin@netadmin-Virtual-Machine:/etc/ansible/myplatform$ ansible-playbook ios.yml

PLAY [10.11.32.100] ***********************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
fatal: [10.11.32.100]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: 60081064@10.11.32.100: Permission denied (publickey,keyboard-interactive,password).\r\n”, “unreachable”: true}
[WARNING]: Could not create retry file ‘/etc/ansible/myplatform/ios.retry’. [Errno 13] Permission denied: u’/etc/ansible/myplatform/ios.retry’

PLAY RECAP ********************************************************************************************************************************************************************************************************
10.11.32.100 : ok=0 changed=0 unreachable=1 failed=0

netadmin@netadmin-Virtual-Machine:/etc/ansible/myplatform$ cat ios.yml

Hi Michael,

By looking at this error : “msg”: “Failed to connect to the host via ssh: 60081064@10.11.32.100: Permission denied (publickey,keyboard-interactive,password).\r\n”, “unreachable”: true it seems like your ansible VM can not SSH to the cisco switch in the first place.

Does normal SSH to the switch work? like if you do ssh username@10.11.32.100 . If it doesn’t work, you have to fix that first. Maybe the switch is allowing connections only from particular IP addresses.

Regards,
Ajay

Hi Ajay,

If username is 60081064, it works, if root, it does not.

Thanks,
Michael

Hi Michael,

“ansble all -m ping , it gives the same error Permission denied (publickey,keyboard-interactive,password)” doesn’t work because ansible ping module requires the remote node to run python. You can find more about it here: https://docs.ansible.com/ansible/latest/modules/ping_module.html#ping-module

So, it works for your username, and based on "Failed to connect to the host via ssh: 60081064@10.11.32.100: Permission denied (publickey,keyboard-interactive,password)" ansible is using the correct username. Where are you defining your password? In the hosts file? If that is the case, hash the password in the hosts file and use -k option instead ( ansible-playbook ios.yml -k ) and enter the password manually just to eliminate one source of the problem.

If that doesn’t work, revert the changes and get the output of "ansible-playbook ios.yml -vvvv " command. It could help us find the source of the issue.

Regards,
Ajay

Hi Ajay,

I tried with -k, it does not work:

netadmin@netadmin-Virtual-Machine:/etc/ansible$ ansible-playbook ios.yml -k

SSH password:

PLAY [10.11.32.100] ********************************************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************

[WARNING]: sftp transfer mechanism failed on [10.11.32.100]. Use ANSIBLE_DEBUG=1 to see detailed information

[WARNING]: scp transfer mechanism failed on [10.11.32.100]. Use ANSIBLE_DEBUG=1 to see detailed information

fatal: [10.11.32.100]: UNREACHABLE! => {“changed”: false, “msg”: “SSH Error: data could not be sent to remote host "10.11.32.100". Make sure this host can be reached over ssh”, “unreachable”: true}

[WARNING]: Could not create retry file ‘/etc/ansible/ios.retry’. [Errno 13] Permission denied: u’/etc/ansible/ios.retry’

PLAY RECAP *****************************************************************************************************************************************************************************************

10.11.32.100 : ok=0 changed=0 unreachable=1 failed=0

Here is the output of -vvv

Hi Ajay,

I tried with -k, it does not work

netadmin@netadmin-Virtual-Machine:/etc/ansible$ ansible-playbook ios.yml -k

SSH password:

PLAY [10.11.32.100] ********************************************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************

[WARNING]: sftp transfer mechanism failed on [10.11.32.100]. Use ANSIBLE_DEBUG=1 to see detailed information

[WARNING]: scp transfer mechanism failed on [10.11.32.100]. Use ANSIBLE_DEBUG=1 to see detailed information

fatal: [10.11.32.100]: UNREACHABLE! => {“changed”: false, “msg”: “SSH Error: data could not be sent to remote host "10.11.32.100". Make sure this host can be reached over ssh”, “unreachable”: true}

[WARNING]: Could not create retry file ‘/etc/ansible/ios.retry’. [Errno 13] Permission denied: u’/etc/ansible/ios.retry’

PLAY RECAP *****************************************************************************************************************************************************************************************

10.11.32.100 : ok=0 changed=0 unreachable=1 failed=0

Here is the output of -vvv

netadmin@netadmin-Virtual-Machine:/etc/ansible$ ansible-playbook ios.yml -vvv

ansible-playbook 2.5.7

config file = /etc/ansible/ansible.cfg

configured module search path = [u’/home/netadmin/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]

ansible python module location = /usr/lib/python2.7/dist-packages/ansible

executable location = /usr/bin/ansible-playbook

python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]

Using /etc/ansible/ansible.cfg as config file

Parsed /etc/ansible/hosts inventory source with ini plugin

PLAYBOOK: ios.yml **********************************************************************************************************************************************************************************

1 plays in ios.yml

PLAY [10.11.32.100] ********************************************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************

task path: /etc/ansible/ios.yml:2

Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/setup.py

<10.11.32.100> ESTABLISH SSH CONNECTION FOR USER: 60081064

<10.11.32.100> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=60081064 -o ConnectTimeout=10 -o ControlPath=/home/netadmin/.ansible/cp/e0e6fa081f 10.11.32.100 ‘/bin/sh -c ‘"’“‘echo ~60081064 && sleep 0’”’"‘’

<10.11.32.100> (255, ‘’, ‘60081064@10.11.32.100: Permission denied (publickey,keyboard-interactive,password).\r\n’)

fatal: [10.11.32.100]: UNREACHABLE! => {

“changed”: false,

“msg”: “Failed to connect to the host via ssh: 60081064@10.11.32.100: Permission denied (publickey,keyboard-interactive,password).\r\n”,

“unreachable”: true

}

[WARNING]: Could not create retry file ‘/etc/ansible/ios.retry’. [Errno 13] Permission denied: u’/etc/ansible/ios.retry’

PLAY RECAP *****************************************************************************************************************************************************************************************

10.11.32.100 : ok=0 changed=0 unreachable=1 failed=0

netadmin@netadmin-Virtual-Machine:/etc/ansible$

At this point, I am almost out of ideas. I am sorry, I couldn’t be of much help.

One last thing you might want to try is turning of “gathering facts”. Some devices have issues with that. You can do that by entering “gathering = explicit” in the ansible.cfg file.

Regards,
Ajay

Thanks Ajay very much.

I managed to get some logging , but still cannot find where the issue is:

root@netadmin-Virtual-Machine:/etc/ansible# ansible-playbook ios_command_1.yml -vvvv
1903 1533876596.09467: starting run
ansible-playbook 2.5.7
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
1903 1533876596.34001: Added group all to inventory
1903 1533876596.34044: Added group ungrouped to inventory
1903 1533876596.34086: Group all now contains ungrouped
setting up inventory plugins
1903 1533876596.34433: Loading InventoryModule ‘host_list’ from /usr/lib/python2.7/dist-packages/ansible/plugins/inventory/host_list.py
1903 1533876596.34638: assigned :doc
1903 1533876596.34679: assigned :plainexamples
1903 1533876596.34763: Loading InventoryModule ‘script’ from /usr/lib/python2.7/dist-packages/ansible/plugins/inventory/script.py
1903 1533876596.35214: assigned :doc
1903 1533876596.35278: Loaded config def from plugin (inventory/script)
1903 1533876596.35376: Loading InventoryModule ‘yaml’ from /usr/lib/python2.7/dist-packages/ansible/plugins/inventory/yaml.py
1903 1533876596.35778: assigned :doc
1903 1533876596.35834: assigned :plainexamples
1903 1533876596.35906: Loaded config def from plugin (inventory/yaml)
1903 1533876596.36043: Loading InventoryModule ‘ini’ from /usr/lib/python2.7/dist-packages/ansible/plugins/inventory/ini.py
1903 1533876596.36778: assigned :doc
1903 1533876596.36845: assigned :plainexamples
1903 1533876596.36982: Loading InventoryModule ‘auto’ from /usr/lib/python2.7/dist-packages/ansible/plugins/inventory/auto.py
1903 1533876596.37186: assigned :doc
1903 1533876596.37248: assigned :plainexamples
1903 1533876596.37323: Examining possible inventory source: /etc/ansible/hosts
1903 1533876596.37387: Attempting to use plugin host_list (/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/host_list.py)
1903 1533876596.37440: /etc/ansible/hosts did not meet host_list requirements
1903 1533876596.37488: Attempting to use plugin script (/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/script.py)
1903 1533876596.38834: /etc/ansible/hosts was not parsable by script
1903 1533876596.38956: Attempting to use plugin yaml (/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/yaml.py)
1903 1533876596.39089: Loading data from /etc/ansible/hosts
1903 1533876596.39455: /etc/ansible/hosts was not parsable by yaml
1903 1533876596.39525: Attempting to use plugin ini (/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/ini.py)
1903 1533876596.39988: Added group switches to inventory
1903 1533876596.40120: set inventory_file for 10.11.32.100
1903 1533876596.40190: set inventory_dir for 10.11.32.100
1903 1533876596.40245: Added host 10.11.32.100 to inventory
1903 1533876596.40307: Added host 10.11.32.100 to group switches
Parsed /etc/ansible/hosts inventory source with ini plugin
1903 1533876596.40417: Reconcile groups and hosts in inventory.
1903 1533876596.40485: Group all now contains switches
1903 1533876596.40814: Loading CacheModule ‘memory’ from /usr/lib/python2.7/dist-packages/ansible/plugins/cache/memory.py
1903 1533876596.41029: assigned :doc
1903 1533876596.43485: Loading data from /etc/ansible/ios_command_1.yml
1903 1533876596.74245: Loading CallbackModule ‘default’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.py
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc
1903 1533876596.81133: assigned :doc
1903 1533876596.81993: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py
1903 1533876596.82200: Loaded config def from plugin (callback/default)
1903 1533876596.82402: Loading CallbackModule ‘actionable’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/actionable.py (found_in_cache=False, class_only=True)
1903 1533876596.82606: assigned :doc
1903 1533876596.82684: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876596.82844: Loaded config def from plugin (callback/actionable)
1903 1533876596.82983: Loading CallbackModule ‘context_demo’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/context_demo.py (found_in_cache=False, class_only=True)
1903 1533876596.83226: assigned :doc
1903 1533876596.83367: Loading CallbackModule ‘debug’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/debug.py (found_in_cache=False, class_only=True)
1903 1533876596.83591: assigned :doc
1903 1533876596.83677: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876596.83953: Loaded config def from plugin (callback/debug)
1903 1533876596.84033: Loading CallbackModule ‘default’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.py (found_in_cache=False, class_only=True)
1903 1533876596.84737: assigned :doc
1903 1533876596.84830: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876596.84993: Loaded config def from plugin (callback/default)
1903 1533876596.85119: Loading CallbackModule ‘dense’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/dense.py (found_in_cache=False, class_only=True)
1903 1533876596.85846: assigned :doc
1903 1533876596.85944: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876596.86098: Loaded config def from plugin (callback/dense)
1903 1533876596.86257: Loading CallbackModule ‘foreman’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/foreman.py (found_in_cache=False, class_only=True)
1903 1533876596.86834: assigned :doc
1903 1533876596.87038: Loaded config def from plugin (callback/foreman)
1903 1533876596.87165: Loading CallbackModule ‘full_skip’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/full_skip.py (found_in_cache=False, class_only=True)
1903 1533876596.87347: assigned :doc
1903 1533876596.87411: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876596.87613: Loaded config def from plugin (callback/full_skip)
1903 1533876596.90800: Loading CallbackModule ‘hipchat’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/hipchat.py (found_in_cache=False, class_only=True)
1903 1533876596.91576: assigned :doc
1903 1533876596.91653: Loaded config def from plugin (callback/hipchat)
1903 1533876596.91788: Loading CallbackModule ‘jabber’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/jabber.py (found_in_cache=False, class_only=True)
1903 1533876596.92196: assigned :doc
1903 1533876596.92269: Loaded config def from plugin (callback/jabber)
1903 1533876596.92365: Loading CallbackModule ‘json’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/json.py (found_in_cache=False, class_only=True)
1903 1533876596.92580: assigned :doc
1903 1533876596.92747: Loading CallbackModule ‘junit’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/junit.py (found_in_cache=False, class_only=True)
1903 1533876596.93611: assigned :doc
1903 1533876596.93737: Loaded config def from plugin (callback/junit)
1903 1533876596.93852: Loading CallbackModule ‘log_plays’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/log_plays.py (found_in_cache=False, class_only=True)
1903 1533876596.94096: assigned :doc
1903 1533876596.94321: Loading CallbackModule ‘logentries’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/logentries.py (found_in_cache=False, class_only=True)
1903 1533876596.95452: assigned :doc
1903 1533876596.95525: assigned :plainexamples
1903 1533876596.95612: Loaded config def from plugin (callback/logentries)
1903 1533876596.95756: Loading CallbackModule ‘logstash’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/logstash.py (found_in_cache=False, class_only=True)
1903 1533876596.96249: assigned :doc
1903 1533876596.96328: Loaded config def from plugin (callback/logstash)
1903 1533876596.96579: Loading CallbackModule ‘mail’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/mail.py (found_in_cache=False, class_only=True)
1903 1533876596.97908: assigned :doc
1903 1533876596.98010: Loaded config def from plugin (callback/mail)
1903 1533876596.98116: Loading CallbackModule ‘minimal’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/minimal.py (found_in_cache=False, class_only=True)
1903 1533876596.98416: assigned :doc
1903 1533876596.98523: Loading CallbackModule ‘null’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/null.py (found_in_cache=False, class_only=True)
1903 1533876596.98733: assigned :doc
1903 1533876596.98890: Loading CallbackModule ‘oneline’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/oneline.py (found_in_cache=False, class_only=True)
1903 1533876596.99347: assigned :doc
1903 1533876596.99543: Loading CallbackModule ‘osx_say’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/osx_say.py (found_in_cache=False, class_only=True)
1903 1533876596.99927: assigned :doc
1903 1533876597.00057: Loading CallbackModule ‘profile_roles’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/profile_roles.py (found_in_cache=False, class_only=True)
1903 1533876597.00361: assigned :doc
1903 1533876597.00482: Loading CallbackModule ‘profile_tasks’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/profile_tasks.py (found_in_cache=False, class_only=True)
1903 1533876597.00966: assigned :doc
1903 1533876597.01023: assigned :plainexamples
1903 1533876597.01100: Loaded config def from plugin (callback/profile_tasks)
1903 1533876597.01210: Loading CallbackModule ‘selective’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/selective.py (found_in_cache=False, class_only=True)
1903 1533876597.01918: assigned :doc
1903 1533876597.01977: assigned :plainexamples
1903 1533876597.02068: Loaded config def from plugin (callback/selective)
1903 1533876597.02166: Loading CallbackModule ‘skippy’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/skippy.py (found_in_cache=False, class_only=True)
1903 1533876597.02314: assigned :doc
1903 1533876597.02377: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876597.02559: Loaded config def from plugin (callback/skippy)
1903 1533876597.02702: Loading CallbackModule ‘slack’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/slack.py (found_in_cache=False, class_only=True)
1903 1533876597.03272: assigned :doc
1903 1533876597.03358: Loaded config def from plugin (callback/slack)
1903 1533876597.03458: Loading CallbackModule ‘stderr’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/stderr.py (found_in_cache=False, class_only=True)
1903 1533876597.03686: assigned :doc
1903 1533876597.03760: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876597.03951: Loaded config def from plugin (callback/stderr)
1903 1533876597.04239: Loading CallbackModule ‘syslog_json’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/syslog_json.py (found_in_cache=False, class_only=True)
1903 1533876597.04659: assigned :doc
1903 1533876597.04818: Loaded config def from plugin (callback/syslog_json)
1903 1533876597.05027: Loading CallbackModule ‘timer’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/timer.py (found_in_cache=False, class_only=True)
1903 1533876597.05265: assigned :doc
1903 1533876597.05382: Loading CallbackModule ‘tree’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/tree.py (found_in_cache=False, class_only=True)
1903 1533876597.05585: assigned :doc
1903 1533876597.05705: Loading CallbackModule ‘unixy’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/unixy.py (found_in_cache=False, class_only=True)
1903 1533876597.06200: assigned :doc
1903 1533876597.06289: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876597.06470: Loaded config def from plugin (callback/unixy)
1903 1533876597.06615: Loading CallbackModule ‘yaml’ from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/yaml.py (found_in_cache=False, class_only=True)
1903 1533876597.06935: assigned :doc
1903 1533876597.07020: Loading ModuleDocFragment ‘default_callback’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/default_callback.py (found_in_cache=True, class_only=False)
1903 1533876597.07207: Loaded config def from plugin (callback/yaml)

PLAYBOOK: ios_command_1.yml ********************************************************************************************************************************************************************************************
1 plays in ios_command_1.yml
1903 1533876597.07395: in VariableManager get_vars()
1903 1533876597.08112: Loading FilterModule ‘core’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/core.py
1903 1533876597.08265: Loading FilterModule ‘ipaddr’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/ipaddr.py
1903 1533876597.08379: Loading FilterModule ‘json_query’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/json_query.py
1903 1533876597.08504: Loading FilterModule ‘mathstuff’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/mathstuff.py
1903 1533876597.09315: Loading FilterModule ‘network’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/network.py
1903 1533876597.09447: Loading FilterModule ‘urlsplit’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/urlsplit.py
1903 1533876597.09776: Loading TestModule ‘core’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/core.py
1903 1533876597.09881: Loading TestModule ‘files’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/files.py
1903 1533876597.09999: Loading TestModule ‘mathstuff’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/mathstuff.py
1903 1533876597.11120: done with get_vars()
1903 1533876597.11253: in VariableManager get_vars()
1903 1533876597.11375: Loading FilterModule ‘core’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/core.py (found_in_cache=True, class_only=False)
1903 1533876597.11440: Loading FilterModule ‘ipaddr’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/ipaddr.py (found_in_cache=True, class_only=False)
1903 1533876597.11498: Loading FilterModule ‘json_query’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/json_query.py (found_in_cache=True, class_only=False)
1903 1533876597.11552: Loading FilterModule ‘mathstuff’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/mathstuff.py (found_in_cache=True, class_only=False)
1903 1533876597.11607: Loading FilterModule ‘network’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/network.py (found_in_cache=True, class_only=False)
1903 1533876597.11664: Loading FilterModule ‘urlsplit’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/urlsplit.py (found_in_cache=True, class_only=False)
1903 1533876597.11761: Loading TestModule ‘core’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/core.py (found_in_cache=True, class_only=False)
1903 1533876597.11825: Loading TestModule ‘files’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/files.py (found_in_cache=True, class_only=False)
1903 1533876597.11882: Loading TestModule ‘mathstuff’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/mathstuff.py (found_in_cache=True, class_only=False)
1903 1533876597.12114: done with get_vars()

PLAY [Collect IOS Device Facts] ****************************************************************************************************************************************************************************************
1903 1533876597.14129: Loading StrategyModule ‘linear’ from /usr/lib/python2.7/dist-packages/ansible/plugins/strategy/linear.py
1903 1533876597.14376: getting the remaining hosts for this loop
1903 1533876597.14510: done getting the remaining hosts for this loop
1903 1533876597.14581: building list of next tasks for hosts
1903 1533876597.14633: getting the next task for host 10.11.32.100
1903 1533876597.14694: done getting next task for host 10.11.32.100
1903 1533876597.14751: ^ task is: TASK: meta (flush_handlers)
1903 1533876597.14810: ^ state is: HOST STATE: block=1, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
1903 1533876597.14878: done building task lists
1903 1533876597.14931: counting tasks in each state of execution
1903 1533876597.14991: done counting tasks in each state of execution:
num_setups: 0
num_tasks: 1
num_rescue: 0
num_always: 0
1903 1533876597.15160: advancing hosts in ITERATING_TASKS
1903 1533876597.15212: starting to advance hosts
1903 1533876597.15268: getting the next task for host 10.11.32.100
1903 1533876597.15338: done getting next task for host 10.11.32.100
1903 1533876597.15405: ^ task is: TASK: meta (flush_handlers)
1903 1533876597.15460: ^ state is: HOST STATE: block=1, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
1903 1533876597.15518: done advancing hosts to next task
META: ran handlers
1903 1533876597.15628: done queuing things up, now waiting for results queue to drain
1903 1533876597.15673: results queue empty
1903 1533876597.15718: checking for any_errors_fatal
1903 1533876597.15767: done checking for any_errors_fatal
1903 1533876597.15812: checking for max_fail_percentage
1903 1533876597.15854: done checking for max_fail_percentage
1903 1533876597.15893: checking to see if all hosts have failed and the running result is not ok
1903 1533876597.15939: done checking to see if all hosts have failed
1903 1533876597.15982: getting the remaining hosts for this loop
1903 1533876597.16031: done getting the remaining hosts for this loop
1903 1533876597.16083: building list of next tasks for hosts
1903 1533876597.16128: getting the next task for host 10.11.32.100
1903 1533876597.16181: done getting next task for host 10.11.32.100
1903 1533876597.16229: ^ task is: TASK: run show version on remote devices
1903 1533876597.16272: ^ state is: HOST STATE: block=2, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
1903 1533876597.16319: done building task lists
1903 1533876597.16365: counting tasks in each state of execution
1903 1533876597.16407: done counting tasks in each state of execution:
num_setups: 0
num_tasks: 1
num_rescue: 0
num_always: 0
1903 1533876597.16542: advancing hosts in ITERATING_TASKS
1903 1533876597.16592: starting to advance hosts
1903 1533876597.16638: getting the next task for host 10.11.32.100
1903 1533876597.16686: done getting next task for host 10.11.32.100
1903 1533876597.16733: ^ task is: TASK: run show version on remote devices
1903 1533876597.16779: ^ state is: HOST STATE: block=2, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
1903 1533876597.16823: done advancing hosts to next task
1903 1533876597.16887: getting variables
1903 1533876597.16956: in VariableManager get_vars()
1903 1533876597.17182: Loading FilterModule ‘core’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/core.py (found_in_cache=True, class_only=False)
1903 1533876597.17283: Loading FilterModule ‘ipaddr’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/ipaddr.py (found_in_cache=True, class_only=False)
1903 1533876597.17346: Loading FilterModule ‘json_query’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/json_query.py (found_in_cache=True, class_only=False)
1903 1533876597.17401: Loading FilterModule ‘mathstuff’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/mathstuff.py (found_in_cache=True, class_only=False)
1903 1533876597.17450: Loading FilterModule ‘network’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/network.py (found_in_cache=True, class_only=False)
1903 1533876597.17498: Loading FilterModule ‘urlsplit’ from /usr/lib/python2.7/dist-packages/ansible/plugins/filter/urlsplit.py (found_in_cache=True, class_only=False)
1903 1533876597.17590: Loading TestModule ‘core’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/core.py (found_in_cache=True, class_only=False)
1903 1533876597.17643: Loading TestModule ‘files’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/files.py (found_in_cache=True, class_only=False)
1903 1533876597.17693: Loading TestModule ‘mathstuff’ from /usr/lib/python2.7/dist-packages/ansible/plugins/test/mathstuff.py (found_in_cache=True, class_only=False)
1903 1533876597.17923: Calling all_inventory to load vars for 10.11.32.100
1903 1533876597.17975: Calling groups_inventory to load vars for 10.11.32.100
1903 1533876597.18025: Calling all_plugins_inventory to load vars for 10.11.32.100
1903 1533876597.18240: Loading VarsModule ‘host_group_vars’ from /usr/lib/python2.7/dist-packages/ansible/plugins/vars/host_group_vars.py
1903 1533876597.18313: Calling all_plugins_play to load vars for 10.11.32.100
1903 1533876597.18388: Loading VarsModule ‘host_group_vars’ from /usr/lib/python2.7/dist-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
1903 1533876597.18468: Calling groups_plugins_inventory to load vars for 10.11.32.100
1903 1533876597.18551: Loading VarsModule ‘host_group_vars’ from /usr/lib/python2.7/dist-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
1903 1533876597.18632: Calling groups_plugins_play to load vars for 10.11.32.100
1903 1533876597.18706: Loading VarsModule ‘host_group_vars’ from /usr/lib/python2.7/dist-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
1903 1533876597.18814: Loading VarsModule ‘host_group_vars’ from /usr/lib/python2.7/dist-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
1903 1533876597.18907: Loading VarsModule ‘host_group_vars’ from /usr/lib/python2.7/dist-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
1903 1533876597.19006: done with get_vars()
1903 1533876597.19076: done getting variables
1903 1533876597.19125: sending task start callback, copying the task so we can template it temporarily
1903 1533876597.19173: done copying, going to template now
1903 1533876597.19218: done templating
1903 1533876597.19260: here goes the callback…

TASK [run show version on remote devices] ******************************************************************************************************************************************************************************
task path: /etc/ansible/ios_command_1.yml:8
1903 1533876597.19443: sending task start callback
1903 1533876597.19526: entering _queue_task() for 10.11.32.100/ios_command
1903 1533876597.19599: Creating lock for ios_command
1903 1533876597.19923: worker is 1 (out of 1 available)
1903 1533876597.20192: exiting _queue_task() for 10.11.32.100/ios_command
1903 1533876597.20647: done queuing things up, now waiting for results queue to drain
1903 1533876597.20698: waiting for pending results…
1911 1533876597.21677: running TaskExecutor() for 10.11.32.100/TASK: run show version on remote devices
1911 1533876597.21866: in run() - task 00155d24-6f11-11bb-3aca-000000000008
1911 1533876597.22030: calling self._execute()
1911 1533876597.22999: Loading Connection ‘network_cli’ from /usr/lib/python2.7/dist-packages/ansible/plugins/connection/network_cli.py
1911 1533876597.23340: Loading ShellModule ‘sh’ from /usr/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py
1911 1533876597.23831: assigned :doc
1911 1533876597.23962: Loading ModuleDocFragment ‘shell_common’ from /usr/lib/python2.7/dist-packages/ansible/utils/module_docs_fragments/shell_common.py
1911 1533876597.24377: Loaded config def from plugin (shell/sh)
1911 1533876597.24431: Loading ShellModule ‘sh’ from /usr/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py (found_in_cache=True, class_only=False)
1911 1533876597.25023: Loading Connection ‘local’ from /usr/lib/python2.7/dist-packages/ansible/plugins/connection/local.py
1911 1533876597.25083: Loading ShellModule ‘sh’ from /usr/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py (found_in_cache=True, class_only=False)
1911 1533876597.25144: Loading ShellModule ‘sh’ from /usr/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py (found_in_cache=True, class_only=False)
1911 1533876597.25602: assigned :doc
1911 1533876597.25855: Loading Connection ‘ssh’ from /usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py (found_in_cache=False, class_only=True)
1911 1533876597.28924: assigned :doc
1911 1533876597.29123: Loaded config def from plugin (connection/ssh)
1911 1533876597.30727: assigned :doc
1911 1533876597.30861: Loaded config def from plugin (connection/network_cli)
<10.11.32.100> attempting to start connection
<10.11.32.100> using connection plugin network_cli
<10.11.32.100> local domain socket does not exist, starting it
<10.11.32.100> control socket path is /root/.ansible/pc/2e6a38f446
<10.11.32.100> 1912 1533876598.40468: Loading Connection ‘ssh’ from /usr/lib/python2.7/dist-packages/ansible/plugins/connection/ssh.py (found_in_cache=False, class_only=True)
1912 1533876598.43470: assigned :doc
1912 1533876598.43656: Loaded config def from plugin (connection/ssh)
The full traceback is:
Traceback (most recent call last):
File “/usr/bin/ansible-connection”, line 87, in start
self.connection._connect()
File “/usr/lib/python2.7/dist-packages/ansible/plugins/connection/network_cli.py”, line 292, in _connect
ssh = self.paramiko_conn._connect()
File “/usr/lib/python2.7/dist-packages/ansible/plugins/connection/paramiko_ssh.py”, line 240, in _connect
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
File “/usr/lib/python2.7/dist-packages/ansible/plugins/connection/paramiko_ssh.py”, line 348, in _connect_uncached
raise AnsibleConnectionFailure(msg)
AnsibleConnectionFailure: Authentication failed.
1911 1533876601.49185: done running TaskExecutor() for 10.11.32.100/TASK: run show version on remote devices [00155d24-6f11-11bb-3aca-000000000008]
1911 1533876601.49288: sending task result for task 00155d24-6f11-11bb-3aca-000000000008
1911 1533876601.49810: done sending task result for task 00155d24-6f11-11bb-3aca-000000000008
1911 1533876601.50225: WORKER PROCESS EXITING
1903 1533876601.50541: marking 10.11.32.100 as failed
1903 1533876601.51035: marking host 10.11.32.100 failed, current state: HOST STATE: block=2, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
1903 1533876601.51100: ^ failed state is now: HOST STATE: block=2, task=1, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_TASKS, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
1903 1533876601.51166: getting the next task for host 10.11.32.100
1903 1533876601.51220: host 10.11.32.100 is done iterating, returning
fatal: [10.11.32.100]: FAILED! => {
“msg”: “Authentication failed.”
}
1903 1533876601.52450: no more pending results, returning what we have
1903 1533876601.52513: results queue empty
1903 1533876601.52569: checking for any_errors_fatal
1903 1533876601.52625: done checking for any_errors_fatal
1903 1533876601.52682: checking for max_fail_percentage
1903 1533876601.52735: done checking for max_fail_percentage
1903 1533876601.52783: checking to see if all hosts have failed and the running result is not ok
1903 1533876601.52855: done checking to see if all hosts have failed
1903 1533876601.52907: getting the remaining hosts for this loop
1903 1533876601.53017: done getting the remaining hosts for this loop
1903 1533876601.53416: building list of next tasks for hosts
1903 1533876601.53470: getting the next task for host 10.11.32.100
1903 1533876601.53524: host 10.11.32.100 is done iterating, returning
1903 1533876601.53573: done building task lists
1903 1533876601.53626: counting tasks in each state of execution
1903 1533876601.53678: done counting tasks in each state of execution:
num_setups: 0
num_tasks: 0
num_rescue: 0
num_always: 0
1903 1533876601.53840: all hosts are done, so returning None’s for all hosts
1903 1533876601.53892: done queuing things up, now waiting for results queue to drain
1903 1533876601.53943: results queue empty
1903 1533876601.54608: checking for any_errors_fatal
1903 1533876601.54661: done checking for any_errors_fatal
1903 1533876601.54712: checking for max_fail_percentage
1903 1533876601.54763: done checking for max_fail_percentage
1903 1533876601.54817: checking to see if all hosts have failed and the running result is not ok
1903 1533876601.54872: done checking to see if all hosts have failed
1903 1533876601.54928: getting the next task for host 10.11.32.100
1903 1533876601.54987: host 10.11.32.100 is done iterating, returning
1903 1533876601.55042: running handlers
to retry, use: --limit @/etc/ansible/ios_command_1.retry

PLAY RECAP *************************************************************************************************************************************************************************************************************
10.11.32.100 : ok=0 changed=0 unreachable=0 failed=1

1903 1533876601.55926: RUNNING CLEANUP

Hi Ajay,

I managed to fix my script as below:

Hi Michael,

I am glad you found a solution. I see that you are only taking the output of stdout[0] under copy task. Since your config will have the output of multiple commands you might need config.stdout[1] and config.stdout[2] as well.

You can use something like the following to capture all your output in one file,

  • copy:
    content: “{{ config.stdout[0] }}”
    dest: “your destination
  • blockinfile: |
    dest: “your destination
    content= “{{ config.stdout[1] }}”
  • blockinfile: |
    dest: “your destination
    content=“{{ output.stdout[2] }}”

There might be a more efficient and better solution than this, but this is what I found so far.

Regards,
Ajay