cannot login to cisco switch using ansible

2,085 views
Skip to first unread message

Michael Sawires

unread,
Aug 8, 2018, 11:32:19 AM8/8/18
to Ansible Project
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$

Ajay

unread,
Aug 8, 2018, 3:35:22 PM8/8/18
to Ansible Project
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

Michael Sawires

unread,
Aug 8, 2018, 6:24:21 PM8/8/18
to ansible...@googlegroups.com
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:
==========
-r-xrwxrwx 1 root root 19573 Aug  9 00:52 ansible.cfg
-r-xrwxrwx 1 root root   251 Aug  8 12:15 ios_facts.yml


2.Content
========
2.1. ansible.cfg
============
test@TESTVM:/etc/ansible$ cat ansible.cfg
# config file for ansible -- https://ansible.com/
# ===============================================

# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first

[defaults]
host_key_checking = false

# some basic default values...

#inventory      = /etc/ansible/hosts
#library        = /usr/share/my_modules/
#module_utils   = /usr/share/my_module_utils/
#remote_tmp     = ~/.ansible/tmp
#local_tmp      = ~/.ansible/tmp
#plugin_filters_cfg = /etc/ansible/plugin_filters.yml
#forks          = 5
#poll_interval  = 15
#sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = True
#transport      = smart
#remote_port    = 22
#module_lang    = C
#module_set_locale = False

# plays will gather facts by default, which contain information about
# the remote system.
#
# smart - gather by default, but don't regather if already gathered
# implicit - gather by default, turn off with gather_facts: False
# explicit - do not gather by default, must say gather_facts: True
#gathering = implicit

# This only affects the gathering done by a play's gather_facts directive,
# by default gathering retrieves all facts subsets
# all - gather all subsets
# network - gather min and network facts
# hardware - gather hardware facts (longest facts to retrieve)
# virtual - gather min and virtual facts
# facter - import facts from facter
# ohai - import facts from ohai
# You can combine them using comma (ex: network,virtual)
# You can negate them using ! (ex: !hardware,!facter,!ohai)
# A minimal set of facts is always gathered.
#gather_subset = all

# some hardware related facts are collected
# with a maximum timeout of 10 seconds. This
# option lets you increase or decrease that
# timeout to something more suitable for the
# environment.
# gather_timeout = 10

# additional paths to search for roles in, colon separated
#roles_path    = /etc/ansible/roles

# uncomment this to disable SSH key host checking
#host_key_checking = False

# change the default callback, you can only have one 'stdout' type  enabled at a time.
#stdout_callback = skippy


## Ansible ships with some plugins that require whitelisting,
## this is done to avoid running all of a type by default.
## These setting lists those that you want enabled for your system.
## Custom plugins should not need this unless plugin author specifies it.

# enable callback plugins, they can output to stdout but cannot be 'stdout' type.
#callback_whitelist = timer, mail

# Determine whether includes in tasks and handlers are "static" by
# default. As of 2.0, includes are dynamic by default. Setting these
# values to True will make includes behave more like they did in the
# 1.x versions.
#task_includes_static = False
#handler_includes_static = False

# Controls if a missing handler for a notification event is an error or a warning
#error_on_missing_handler = True

# change this for alternative sudo implementations
#sudo_exe = sudo

# What flags to pass to sudo
# WARNING: leaving out the defaults might create unexpected behaviours
#sudo_flags = -H -S -n

# SSH timeout
#timeout = 10

# default user to use for playbooks if user is not specified
# (/usr/bin/ansible will use current user as default)
#remote_user = root

# logging is off by default unless this path is defined
# if so defined, consider logrotate
#log_path = /var/log/ansible.log

# default module name for /usr/bin/ansible
#module_name = command

# use this shell for commands executed under sudo
# you may need to change this to bin/bash in rare instances
# if sudo is constrained
#executable = /bin/sh

# if inventory variables overlap, does the higher precedence one win
# or are hash values merged together?  The default is 'replace' but
# this can also be set to 'merge'.
#hash_behaviour = replace

# by default, variables from roles will be visible in the global variable
# scope. To prevent this, the following option can be enabled, and only
# tasks and handlers within the role will see the variables there
#private_role_vars = yes

# list any Jinja2 extensions to enable here:
#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n

# if set, always use this private key file for authentication, same as
# if passing --private-key to ansible or ansible-playbook
#private_key_file = /path/to/file

# If set, configures the path to the Vault password file as an alternative to
# specifying --vault-password-file on the command line.
#vault_password_file = /path/to/vault_password_file

# format of string {{ ansible_managed }} available within Jinja2
# templates indicates to users editing templates files will be replaced.
# replacing {file}, {host} and {uid} and strftime codes with proper values.
#ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
# {file}, {host}, {uid}, and the timestamp can all interfere with idempotence
# in some situations so the default is a static string:
#ansible_managed = Ansible managed

# by default, ansible-playbook will display "Skipping [host]" if it determines a task
# should not be run on a host.  Set this to "False" if you don't want to see these "Skipping"
# messages. NOTE: the task header will still be shown regardless of whether or not the
# task is skipped.
#display_skipped_hosts = True

# by default, if a task in a playbook does not include a name: field then
# ansible-playbook will construct a header that includes the task's action but
# not the task's args.  This is a security feature because ansible cannot know
# if the *module* considers an argument to be no_log at the time that the
# header is printed.  If your environment doesn't have a problem securing
# stdout from ansible-playbook (or you have manually specified no_log in your
# playbook on all of the tasks where you have secret information) then you can
# safely set this to True to get more informative messages.
#display_args_to_stdout = False

# by default (as of 1.3), Ansible will raise errors when attempting to dereference
# Jinja2 variables that are not set in templates or action lines. Uncomment this line
# to revert the behavior to pre-1.3.
#error_on_undefined_vars = False

# by default (as of 1.6), Ansible may display warnings based on the configuration of the
# system running ansible itself. This may include warnings about 3rd party packages or
# other conditions that should be resolved if possible.
# to disable these warnings, set the following value to False:
#system_warnings = True

# by default (as of 1.4), Ansible may display deprecation warnings for language
# features that should no longer be used and will be removed in future versions.
# to disable these warnings, set the following value to False:
#deprecation_warnings = True

# (as of 1.8), Ansible can optionally warn when usage of the shell and
# command module appear to be simplified by using a default Ansible module
# instead.  These warnings can be silenced by adjusting the following
# setting or adding warn=yes or warn=no to the end of the command line
# parameter string.  This will for example suggest using the git module
# instead of shelling out to the git command.
# command_warnings = False


# set plugin path directories here, separate with colons
#action_plugins     = /usr/share/ansible/plugins/action
#cache_plugins      = /usr/share/ansible/plugins/cache
#callback_plugins   = /usr/share/ansible/plugins/callback
#connection_plugins = /usr/share/ansible/plugins/connection
#lookup_plugins     = /usr/share/ansible/plugins/lookup
#inventory_plugins  = /usr/share/ansible/plugins/inventory
#vars_plugins       = /usr/share/ansible/plugins/vars
#filter_plugins     = /usr/share/ansible/plugins/filter
#test_plugins       = /usr/share/ansible/plugins/test
#terminal_plugins   = /usr/share/ansible/plugins/terminal
#strategy_plugins   = /usr/share/ansible/plugins/strategy


# by default, ansible will use the 'linear' strategy but you may want to try
# another one
#strategy = free

# by default callbacks are not loaded for /bin/ansible, enable this if you
# want, for example, a notification or logging callback to also apply to
# /bin/ansible runs
#bin_ansible_callbacks = False


# don't like cows?  that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
#nocows = 1

# set which cowsay stencil you'd like to use by default. When set to 'random',
# a random stencil will be selected for each task. The selection will be filtered
# against the `cow_whitelist` option below.
#cow_selection = default
#cow_selection = random

# when using the 'random' option for cowsay, stencils will be restricted to this list.
# it should be formatted as a comma-separated list with no spaces between names.
# NOTE: line continuations here are for formatting purposes only, as the INI parser
#       in python does not support them.
#cow_whitelist=bud-frogs,bunny,cheese,daemon,default,dragon,elephant-in-snake,elephant,eyes,\
#              hellokitty,kitty,luke-koala,meow,milk,moofasa,moose,ren,sheep,small,stegosaurus,\
#              stimpy,supermilker,three-eyes,turkey,turtle,tux,udder,vader-koala,vader,www

# don't like colors either?
# set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1
#nocolor = 1

# if set to a persistent type (not 'memory', for example 'redis') fact values
# from previous runs in Ansible will be stored.  This may be useful when
# wanting to use, for example, IP information from one group of servers
# without having to talk to them in the same playbook run to get their
# current IP information.
#fact_caching = memory


# retry files
# When a playbook fails by default a .retry file will be created in ~/
# You can disable this feature by setting retry_files_enabled to False
# and you can change the location of the files by setting retry_files_save_path

#retry_files_enabled = False
#retry_files_save_path = ~/.ansible-retry

# squash actions
# Ansible can optimise actions that call modules with list parameters
# when looping. Instead of calling the module once per with_ item, the
# module is called once with all items at once. Currently this only works
# under limited circumstances, and only with parameters named 'name'.
#squash_actions = apk,apt,dnf,homebrew,pacman,pkgng,yum,zypper

# prevents logging of task data, off by default
#no_log = False

# prevents logging of tasks, but only on the targets, data is still logged on the master/controller
#no_target_syslog = False

# controls whether Ansible will raise an error or warning if a task has no
# choice but to create world readable temporary files to execute a module on
# the remote machine.  This option is False by default for security.  Users may
# turn this on to have behaviour more like Ansible prior to 2.1.x.  See
# for more secure ways to fix this than enabling this option.
#allow_world_readable_tmpfiles = False

# controls the compression level of variables sent to
# worker processes. At the default of 0, no compression
# is used. This value must be an integer from 0 to 9.
#var_compression_level = 9

# controls what compression method is used for new-style ansible modules when
# they are sent to the remote system.  The compression types depend on having
# support compiled into both the controller's python and the client's python.
# The names should match with the python Zipfile compression types:
# * ZIP_STORED (no compression. available everywhere)
# * ZIP_DEFLATED (uses zlib, the default)
# These values may be set per host via the ansible_module_compression inventory
# variable
#module_compression = 'ZIP_DEFLATED'

# This controls the cutoff point (in bytes) on --diff for files
# set to 0 for unlimited (RAM may suffer!).
#max_diff_size = 1048576

# This controls how ansible handles multiple --tags and --skip-tags arguments
# on the CLI.  If this is True then multiple arguments are merged together.  If
# it is False, then the last specified argument is used and the others are ignored.
# This option will be removed in 2.8.
#merge_multiple_cli_flags = True

# Controls showing custom stats at the end, off by default
#show_custom_stats = True

# Controls which files to ignore when using a directory as inventory with
# possibly multiple sources (both static and dynamic)
#inventory_ignore_extensions = ~, .orig, .bak, .ini, .cfg, .retry, .pyc, .pyo

# This family of modules use an alternative execution path optimized for network appliances
# only update this setting if you know how this works, otherwise it can break module execution
#network_group_modules=eos, nxos, ios, iosxr, junos, vyos

# When enabled, this option allows lookups (via variables like {{lookup('foo')}} or when used as
# a loop with `with_foo`) to return data that is not marked "unsafe". This means the data may contain
# jinja2 templating language which will be run through the templating engine.
# ENABLING THIS COULD BE A SECURITY RISK
#allow_unsafe_lookups = False

# set default errors for all plays
#any_errors_fatal = False

[inventory]
# enable inventory plugins, default: 'host_list', 'script', 'yaml', 'ini'
#enable_plugins = host_list, virtualbox, yaml, constructed

# ignore these extensions when parsing a directory as inventory source
#ignore_extensions = .pyc, .pyo, .swp, .bak, ~, .rpm, .md, .txt, ~, .orig, .ini, .cfg, .retry

# ignore files matching these patterns when parsing a directory as inventory source
#ignore_patterns=

# If 'true' unparsed inventory sources become fatal errors, they are warnings otherwise.
#unparsed_is_failed=False

[privilege_escalation]
#become=True
#become_method=sudo
#become_user=root
#become_ask_pass=False

[paramiko_connection]

# uncomment this line to cause the paramiko connection plugin to not record new host
# keys encountered.  Increases performance on new host additions.  Setting works independently of the
# host key checking setting above.
#record_host_keys=False

# by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this
# line to disable this behaviour.
#pty=False

# paramiko will default to looking for SSH keys initially when trying to
# authenticate to remote devices.  This is a problem for some network devices
# that close the connection after a key failure.  Uncomment this line to
# disable the Paramiko look for keys function
#look_for_keys = False

# When using persistent connections with Paramiko, the connection runs in a
# background process.  If the host doesn't already have a valid SSH key, by
# default Ansible will prompt to add the host key.  This will cause connections
# running in background processes to fail.  Uncomment this line to have
# Paramiko automatically add host keys.
host_key_auto_add = True

[ssh_connection]

# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use
# paramiko on older platforms rather than removing it, -C controls compression use
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s

# The base directory for the ControlPath sockets.
# This is the "%(directory)s" in the control_path option
#
# Example:
# control_path_dir = /tmp/.ansible/cp
#control_path_dir = ~/.ansible/cp

# The path to use for the ControlPath sockets. This defaults to a hashed string of the hostname,
# port and username (empty string in the config). The hash mitigates a common problem users
# found with long hostames and the conventional %(directory)s/ansible-ssh-%%h-%%p-%%r format.
# In those cases, a "too long for Unix domain socket" ssh error would occur.
#
# Example:
# control_path = %(directory)s/%%h-%%r
#control_path =

# Enabling pipelining reduces the number of SSH operations required to
# execute a module on the remote server. This can result in a significant
# performance improvement when enabled, however when using "sudo:" you must
# first disable 'requiretty' in /etc/sudoers
#
# By default, this option is disabled to preserve compatibility with
# sudoers configurations that have requiretty (the default on many distros).
#
#pipelining = False

# Control the mechanism for transferring files (old)
#   * smart = try sftp and then try scp [default]
#   * True = use scp only
#   * False = use sftp only
#scp_if_ssh = smart

# Control the mechanism for transferring files (new)
# If set, this will override the scp_if_ssh option
#   * sftp  = use sftp to transfer files
#   * scp   = use scp to transfer files
#   * piped = use 'dd' over SSH to transfer files
#   * smart = try sftp, scp, and piped, in that order [default]
#transfer_method = smart

# if False, sftp will not use batch mode to transfer files. This may cause some
# types of file transfer failures impossible to catch however, and should
# only be disabled if your sftp version has problems with batch mode
#sftp_batch_mode = False

# The -tt argument is passed to ssh when pipelining is not enabled because sudo 
# requires a tty by default. 
#use_tty = True

# Number of times to retry an SSH connection to a host, in case of UNREACHABLE.
# For each retry attempt, there is an exponential backoff,
# so after the first attempt there is 1s wait, then 2s, 4s etc. up to 30s (max).
#retries = 3

[persistent_connection]

# Configures the persistent connection timeout value in seconds.  This value is
# how long the persistent connection will remain idle before it is destroyed.
# If the connection doesn't receive a request before the timeout value
# expires, the connection is shutdown. The default value is 30 seconds.
#connect_timeout = 30

# Configures the persistent connection retry timeout.  This value configures the
# the retry timeout that ansible-connection will wait to connect
# to the local domain socket. This value must be larger than the
# ssh timeout (timeout) and less than persistent connection idle timeout (connect_timeout).
# The default value is 15 seconds.
#connect_retry_timeout = 15

# The command timeout value defines the amount of time to wait for a command
# or RPC call before timing out. The value for the command timeout must
# be less than the value of the persistent connection idle timeout (connect_timeout)
# The default value is 10 second.
#command_timeout = 10

[accelerate]
#accelerate_port = 5099
#accelerate_timeout = 30
#accelerate_connect_timeout = 5.0

# The daemon timeout is measured in minutes. This time is measured
# from the last activity to the accelerate daemon.
#accelerate_daemon_timeout = 30

# If set to yes, accelerate_multi_key will allow multiple
# private keys to be uploaded to it, though each user must
# have access to the system via SSH to add a new key. The default
# is "no".
#accelerate_multi_key = yes

[selinux]
# file systems that require special treatment when dealing with security context
# the default behaviour that copies the existing context or uses the user default
# needs to be changed to use the file system dependent context.
#special_context_filesystems=nfs,vboxsf,fuse,ramfs,9p

# Set this to yes to allow libvirt_lxc connections to work without SELinux.
#libvirt_lxc_noseclabel = yes

[colors]
#highlight = white
#verbose = blue
#warn = bright purple
#error = red
#debug = dark gray
#deprecate = purple
#skip = cyan
#unreachable = red
#ok = green
#changed = yellow
#diff_add = green
#diff_remove = red
#diff_lines = cyan


[diff]
# Always print diff when running ( same as always running with -D/--diff )
# always = no

# Set how many context lines to show in diff
# context = 3

==============================================================================================================================
2.2. ios_facts.yml

test@TESTVM:/etc/ansible$ cat ios_facts.yml
---
- name: Collect IOS Device Facts
  connection: network_cli
  hosts: distswitches 
  tasks:
    - name: collect facts
      ios_facts:
        gather_subset: all
...


I think I have a problem with ssh but i do not understand how to fix it.





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/460f28a4-dcca-448e-9036-a550ccae46c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
-----------------------
Michael Sawires

Ajay

unread,
Aug 8, 2018, 8:13:22 PM8/8/18
to Ansible Project
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

Michael Ikram

unread,
Aug 8, 2018, 8:24:35 PM8/8/18
to ansible...@googlegroups.com

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

Michael Ikram

unread,
Aug 8, 2018, 11:48:44 PM8/8/18
to ansible...@googlegroups.com

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

 

ansible all -i <switch_ip>, -c network_cli -u <username>-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

Ajay Kumar Manukonda

unread,
Aug 9, 2018, 10:44:45 AM8/9/18
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/QaZFGSaMNpk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Michael Sawires

unread,
Aug 9, 2018, 11:02:09 AM8/9/18
to ansible...@googlegroups.com
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: 6008...@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 
---
- hosts: 10.11.32.100
  user: 60081064

  tasks:
    - name: show version
      ios_command:
        commands: show version
...

also when I try: ansble all -m ping , it gives the same error  Permission denied (publickey,keyboard-interactive,password).\

You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
-----------------------
Michael Sawires

Ajay Kumar Manukonda

unread,
Aug 9, 2018, 2:41:07 PM8/9/18
to ansible...@googlegroups.com
Hi Michael,

By looking at this error : "msg": "Failed to connect to the host via ssh: 6008...@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 user...@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



Michael Sawires

unread,
Aug 9, 2018, 4:35:15 PM8/9/18
to ansible...@googlegroups.com
Hi Ajay,

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

Thanks,
Michael 


For more options, visit https://groups.google.com/d/optout.
--
Sent from Gmail Mobile

Ajay Kumar Manukonda

unread,
Aug 9, 2018, 7:59:09 PM8/9/18
to ansible...@googlegroups.com
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: 6008...@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

Michael Ikram

unread,
Aug 9, 2018, 8:03:53 PM8/9/18
to ansible...@googlegroups.com

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

 

 

 

Sent from Mail for Windows 10

Michael Ikram

unread,
Aug 9, 2018, 8:04:35 PM8/9/18
to ansible...@googlegroups.com

 

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, '', '6008...@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: 6008...@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$

 

Sent from Mail for Windows 10

 

From: Ajay Kumar Manukonda
Sent: Friday, 10 August 2018 9:59 AM
To: ansible...@googlegroups.com

Ajay Kumar Manukonda

unread,
Aug 9, 2018, 8:23:45 PM8/9/18
to ansible...@googlegroups.com
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

Michael Sawires

unread,
Aug 10, 2018, 1:21:23 AM8/10/18
to ansible...@googlegroups.com
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


For more options, visit https://groups.google.com/d/optout.


--
-----------------------
Michael Sawires

Michael Ikram

unread,
Aug 14, 2018, 10:13:18 PM8/14/18
to ansible...@googlegroups.com

Hi Ajay,

 

I managed to fix my script as below:

---

- name: show version

  hosts: "switches"

  gather_facts: false

  connection: local

 

  vars:

    backup_root: /etc/ansible/backups

    cli:

      host: "{{ inventory_hostname }}"

      username: msawires

      password: Irukandji.=

 

  tasks:

    - name: GATHERING INFO

      ios_command:

        commands:

         - command: sh run | i hostname

         - command: sh ip int brief | i 10.11.64

         - command: sh ver | i Model Number|System Serial

        provider: "{{ cli }}"

      register: config

 

    - copy:

        content: "{{ config.stdout[0] }}"

        dest: "{{ backup_root }}/{{ inventory_hostname }}/running-config_{{ timestamp.stdout }}"

...

 

My problem now is I can save only first command, cannot save the other two in file, do you have any suggestion how to save all commands output in one file?

 

Thank you,

Michael

Ajay Kumar Manukonda

unread,
Aug 16, 2018, 1:43:58 PM8/16/18
to ansible...@googlegroups.com
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


Reply all
Reply to author
Forward
0 new messages