Ansible SSH connection plugin not working

sumanth-lingappa
Sat, 20 Jan 2024 13:31:26 +0000
Get Help

I am the maintainer of citrix.adc ansible collection and we have a ssh_connection_plugin for the citrix.adc ansible collection.

When I run ansible-playbook using this connection plugin, I am facing some unknown error which is difficult to debug. Maybe because I do not know the nitty-gritty of the working of the shell module.

ansible-playbook command ran:

ansible-playbook nsver_info.yaml -i inventory.ini -l mpx --ask-pass -vvvvv

Below are the details

Thanks in advance

Playbook gist

To run show ns version on the NetScaler CLI prompt.

Manually SSH into the ADC and run the command which playbook runs

as soon as we SSH into the ADC, we will be in NSCLI prompt (not shell prompt). We need to type shell command to take us into shell prompt.

The intention of our connection plugin is to run tasks directly into shell prompt.

I believe, we are getting error before running any tasks!

Manual SSH

ssh nsroot@10.x.x.42
###############################################################################
#                                                                             #
#        WARNING: Access to this system is for authorized users only          #
#         Disconnect IMMEDIATELY if you are not an authorized user!           #
#                                                                             #
###############################################################################

(nsroot@10.x.x.42) Password:
Last login: xxx xxx xx xx:xx:xx xxxx from 10.x.x.x
Warning: You are connected to a secondary node; configuration changes made in this session will not be propagated to, or saved on, other nodes (Primary node is 10.x.x.43)
 Done
ABC>
ABC> shell
Copyright (c) 1992-2013 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
	The Regents of the University of California. All rights reserved.

root@ns#
root@ns# nscli -s -U :nsroot:xxxxxxx show version | grep -i 'NetScaler NS'
Warning: You are connected to a secondary node; configuration changes made in this session will not be propagated to, or saved on, other nodes (Primary node is 10.217.206.43)
	NetScaler NS12.1: Build 65.39.nc, Date: Dec 18 2023, 06:48:15   (64-bit)
root@ns#

nsver_info.yaml file

- name: Find NS version
  hosts: mpx
  remote_user: nsroot
  connection: citrix.adc.ssh_citrix_adc
  gather_facts: false

  vars:
    ansible_python_interpreter: '{{ netscaler_python_path | default("/var/python/bin/python") }}'

  tasks:
    - name: Finding the current version of the NetScaler
      shell:
        cmd: "nscli -s -U :nsroot:{{ nitro_pass }} show version | grep -i 'NetScaler NS'"
      register: version

    - name: NetScaler version
      debug:
        msg: "{{ version }}"
      register: present_version

inventory file

[mpx]
10.x.x.42 nsip=10.x.x.42  nitro_user=nsroot nitro_pass=xxxxxxx validate_certs=no ansible_host=10.x.x.42 ansible_user=nsroot

ansible.cfg

[defaults]
remote_tmp = /var/
pipelining = true


[ssh_connection]
scp_if_ssh = True
retries = 3

[connection]
retries = 3

Short error

fatal: [10.x.x.42]: FAILED! => {
    "changed": false,
    "module_stderr": "OpenSSH_8.9p1 Ubuntu-3ubuntu0.6, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/sumanthl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 10.x.x.42 is address\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/sumanthl/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/sumanthl/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 1041040\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\nERROR: Not logged in\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n",
    "module_stdout": "ERROR: Session expired or killed. Please login again\nERROR: Not logged in\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Long error is in the below gist

gist.github.com

https://gist.github.com/sumanth-lingappa/ab18739a5be5c718d3157d4faa94202e

ansible-ssh-connection-plugin-error.log

1041081 1705573397.75587: starting run
ansible-playbook [core 2.11.12]
  config file = /home/sumanthl/workspace/upgrade-netscalers/ansible.cfg
  configured module search path = ['/home/sumanthl/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/sumanthl/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/sumanthl/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/sumanthl/.local/bin//ansible-playbook
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
  jinja version = 3.0.3
  libyaml = True
This file has been truncated. show original

11 posts - 3 participants