Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

ios_command

ANSIBLE VERSION

Both latest unstable versions:

ansible 2.3.2.0 (detached HEAD 7424e1c417) last updated 2017/06/28 14:37:25 (GMT +200)
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/actionmystique/Ansible/git-yang-networkop/ansible-101/library']
python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]

ansible 2.4.0 (devel a5b905c941) last updated 2017/06/28 15:03:00 (GMT +200)
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/actionmystique/Ansible/git-yang-networkop/ansible-101/library']
ansible python module location = /home/actionmystique/src/Ansible/git-ansible/lib/ansible
executable location = /home/actionmystique/src/Ansible/git-ansible/bin/ansible
python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]

CONFIGURATION

inventory = ./hosts

library = /home/actionmystique/Ansible/git-yang-networkop/ansible-101/library

forks = 1000

gathering = explicit

gather_timeout = 30

roles_path = /home/actionmystique/Ansible/Roles/roles

private_role_vars = yes

hash_behaviour = merge

log_path = /var/log/ansible.log

retry_files_enabled = False

show_custom_stats = True

timeout = 60

pipelining = True

connect_timeout = 60

connect_retries = 30

connect_interval = 1

OS / ENVIRONMENT

host: Ubuntu 17.04 4.10

target: IOS-XEv 16.5.1

paramiko: 2.0.6

SUMMARY

The generic {{ undefined_variable | default(defined_variable) }} does not work inside a dictionary, when the target hostnames are defined in /etc/hosts.

STEPS TO REPRODUCE

Hostnames statically defined in /etc/hosts:

172.21.100.111 XEv_Spine_11.actionmystique.net XEv_Spine_11
172.21.100.112 XEv_Spine_12.actionmystique.net XEv_Spine_12

Structure passed as "provider": connections.ssh (the arrow is absent from the original dictionary)

connections
...
ssh:
transport: cli
--------->host: "{{ ansible_host | default(inventory_hostname) }}"
# ansible_port
port: 22
# ansible_user
username: admin
# ansible_ssh_pass
password: xxxxxxxxxxx
authorize: yes
# enable_secret_password
auth_pass: xxxxxxxxxxx
# private_key_file
ssh_keyfile: "~/.ssh/id_rsa"
version: 2
timeout: 10

Role: ios_pull_config:

- include_vars: "../defaults/{{ os_family }}/connections.yml"
when: (connections is undefined)
...
- name: Fetching config from the remote node
ios_command:
provider: "{{ connections.ssh }}"
commands:
- "show {{ config }}"
register: configuration

Playbook:

- name: Pulling IOS/IOSv/IOSv-L2/IOS-XE/IOS-XEv (CSR-1000v) startup and running configs
hosts:
- iosv
- ios_xev
- iosv_l2
- ios_xev
gather_facts: no
roles:
- { role: ios_pull_config, config: startup-config, with_date_time: 'no' }
- { role: ios_pull_config, config: running-config, with_date_time: 'no' }

EXPECTED RESULTS

startup and running configurations should be pulled from the target nodes.

ACTUAL RESULTS: Log

...
2017-06-29 10:00:34,575 paramiko.transport starting thread (client mode): 0xf6b6c110L
2017-06-29 10:00:34,576 paramiko.transport Local version/idstring: SSH-2.0-paramiko_2.0.6
2017-06-29 10:00:34,577 paramiko.transport Remote version/idstring: SSH-2.0-Cisco-1.25
2017-06-29 10:00:34,577 paramiko.transport Connected (version 2.0, client Cisco-1.25)
2017-06-29 10:00:34,577 paramiko.transport kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr'] client mac:[u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False
2017-06-29 10:00:34,577 paramiko.transport Kex agreed: diffie-hellman-group14-sha1
2017-06-29 10:00:34,578 paramiko.transport Cipher agreed: aes128-ctr
2017-06-29 10:00:34,578 paramiko.transport MAC agreed: hmac-sha2-256
2017-06-29 10:00:34,578 paramiko.transport Compression agreed: none
2017-06-29 10:00:34,818 paramiko.transport kex engine KexGroup14 specified hash_algo <built-in function openssl_sha1>
2017-06-29 10:00:34,818 paramiko.transport Switch to new keys ...
2017-06-29 10:00:34,851 p=16072 u=root | connecting to host XEv_Spine_11 returned an error
2017-06-29 10:00:34,851 p=16072 u=root | (14, 'Bad address')
2017-06-29 10:00:34,919 paramiko.transport EOF in transport thread
2017-06-29 10:01:04,470 p=16072 u=root | number of connection attempts exceeded, unable to connect to control socket
2017-06-29 10:01:04,471 p=16072 u=root | persistent_connect_interval=1, persistent_connect_retries=30
2017-06-29 10:01:04,491 p=15970 u=root | open_shell() returned 255 failed to connect to control socket
2017-06-29 10:01:04,493 p=15970 u=root | fatal: [XEv_Spine_11]: FAILED! => {
"changed": false,
"failed": true,
"msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell",
"rc": 255
}
...

ACTUAL RESULTS: Successful Manual SSH with inventory_hostname content

# ssh admin@XEv_Spine_11
CC
**************************************************************************
* IOSv is strictly limited to use for evaluation, demonstration and IOS *
* education. IOSv is provided as-is and is not supported by Cisco's *
* Technical Advisory Center. Any use or disclosure, in whole or in part, *
* of the IOSv Software or Documentation to any third party for any *
* purposes is expressly prohibited except as otherwise authorized by *
* Cisco in writing. *
**************************************************************************CC
XEv_Spine_11# #sh ver
Cisco IOS XE Software, Version 16.05.01b
Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.5.1b, RELEASE SOFTWARE (fc1)
...

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

ios_command

ios_config

ANSIBLE VERSION

ansible 2.4.0.0
config file = /mnt/c/jv/Ansible/ansible.cfg
configured module search path = [u'/etc/ansible/library']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

CONFIGURATION

OS / ENVIRONMENT

Windows Subsystem Linux & Ubuntu 16.04.3

No LSB modules are available.

Distributor ID: Ubuntu

Description: Ubuntu 14.04.5 LTS

Release: 14.04

Codename: trusty

No LSB modules are available.

Distributor ID: Ubuntu

Description: Ubuntu 16.04.3 LTS

Release: 16.04

Codename: xenial

SUMMARY

In my inventory file I have the following:

[switches]

COMSW0001

comsw0002

ios_command & ios_config connect just fine when the characters are all lower case. When they are all upper case Ansible is unable to connect to host. If I swap the upper/lower case around, the issue follows the upper case host.

STEPS TO REPRODUCE

---
# Ansible playbook to copy and change the boot statement on a Cisco IOS switch
# Leverages NTC-Ansible: https://github.com/networktocode/ntc-ansible
# Requires Python PyNTC
- name: Copy code to machine and change boot statement
connection: local
hosts: switches
gather_facts: no
serial:
- 5%
- 10%
- 30%
vars_files:
- /path/to/cred/file
vars:
cli:
username: "{{ u }}"
password: "{{ p }}"

code_version:
WS-C3560CX-8PC-S: c3560cx-universalk9-mz.152-4.E4.bin
WS-C3560C-8PC-S: c3560c405-universalk9-mz.152-2.E7.bin
WS-C3560CG-8PC-S: c3560c405-universalk9-mz.152-2.E7.bin
WS-C3560C-12PC-S: c3560c405-universalk9-mz.152-2.E7.bin

tasks:
- name: Determine OS Version
ntc_show_command:
connection: ssh
platform: cisco_ios_ssh
command: show version
template_dir: "/etc/ansible/library/ntc-ansible/ntc-templates/templates"
host: "{{ inventory_hostname }}"
username: "{{ u }}"
password: "{{ p }}"
secret: "{{ p }}"
register: ntc_result

- name: Debug NTC
debug:
msg: "{{ ntc_result }}"

- name: Get SNMP information
ios_command:
provider: "{{ cli }}"
commands:
- show ip int brief
timeout: 40
register: run_config

- name: Get the details
set_fact:
output: "{{ run_config.stdout_lines[0] }}"

- name: Verify SCP is configured
ios_config:
provider: "{{ cli }}"
lines:
- ip scp server enable

- name: Copy File
ntc_file_copy:
local_file: images/{{ code_version[ntc_result['response'][0]['hardware'][0]] }}
platform: cisco_ios_ssh
username: "{{ u }}"
password: "{{ p }}"
host: "{{ inventory_hostname }}"
register: output

EXPECTED RESULTS

First task connects fine and works.

Tasks with ios_* fail to connect.

ACTUAL RESULTS

Failed to connect on the ios_* - I do have the log file. Looks to be an Invalid Argument

2017-11-02 16:03:24,692 p=7253 u=joshv | 7262 1509656604.69279: Loading ShellModule 'sh' from /usr/local/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py
7262 1509656604.69401: Loading ShellModule 'sh' from /usr/local/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py (found_in_cache=True, class_only=False)
2017-11-02 16:03:24,694 p=7253 u=joshv | 7262 1509656604.69401: Loading ShellModule 'sh' from /usr/local/lib/python2.7/dist-packages/ansible/plugins/shell/sh.py (found_in_cache=True, class_only=False)
7262 1509656604.69887: assigned :doc
2017-11-02 16:03:24,699 p=7253 u=joshv | 7262 1509656604.69887: assigned :doc
7262 1509656604.69952: Loaded config def from plugin (connection/network_cli)
2017-11-02 16:03:24,699 p=7253 u=joshv | 7262 1509656604.69952: Loaded config def from plugin (connection/network_cli)
2017-11-02 16:03:24,786 paramiko.transport starting thread (client mode): 0x742ed150L
2017-11-02 16:03:24,786 paramiko.transport Local version/idstring: SSH-2.0-paramiko_2.3.1
2017-11-02 16:03:24,787 paramiko.transport Remote version/idstring: SSH-2.0-Cisco-1.25
2017-11-02 16:03:24,787 paramiko.transport Connected (version 2.0, client Cisco-1.25)
2017-11-02 16:03:24,795 paramiko.transport kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False
2017-11-02 16:03:24,796 paramiko.transport Kex agreed: diffie-hellman-group-exchange-sha1
2017-11-02 16:03:24,796 paramiko.transport HostKey agreed: ssh-rsa
2017-11-02 16:03:24,796 paramiko.transport Cipher agreed: aes128-ctr
2017-11-02 16:03:24,796 paramiko.transport MAC agreed: hmac-sha1
2017-11-02 16:03:24,796 paramiko.transport Compression agreed: none
2017-11-02 16:03:24,807 paramiko.transport Got server p (2048 bits)
2017-11-02 16:03:25,075 paramiko.transport kex engine KexGex specified hash_algo <built-in function openssl_sha1>
2017-11-02 16:03:25,076 paramiko.transport Switch to new keys ...
2017-11-02 16:03:25,090 p=7253 u=joshv | connecting to host SYCOMSW0002 returned an error
2017-11-02 16:03:25,090 p=7253 u=joshv | (22, 'Invalid argument')
2017-11-02 16:03:25,177 paramiko.transport EOF in transport thread
2017-11-02 16:04:04,477 p=7211 u=joshv | 7252 1509656644.47682: handler run complete
2017-11-02 16:04:04,478 p=7211 u=joshv | 7252 1509656644.47803: attempt loop complete, returning result
2017-11-02 16:04:04,478 p=7211 u=joshv | 7252 1509656644.47853: _execute() done
2017-11-02 16:04:04,479 p=7211 u=joshv | 7252 1509656644.47894: dumping result to json
2017-11-02 16:04:04,479 p=7211 u=joshv | 7252 1509656644.47929: done dumping result, returning