Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty connecting via nxapi #861

Open
cardosocristian opened this issue May 24, 2024 · 1 comment
Open

Difficulty connecting via nxapi #861

cardosocristian opened this issue May 24, 2024 · 1 comment

Comments

@cardosocristian
Copy link

SUMMARY

I'm trying to use the connection method on Nexus switches with Ansible with Nxapi and there is no way to connect to Nexus

ISSUE TYPE
  • Bug Report
COMPONENT NAME

I am using the following connection variables:
ansible_connection: ansible.netcommon.httpapi
ansible_network_os: cisco.nxos.nxos

I tested several modules from the Nxos collection
I tested several modules from the Nxos collection, but here is an example of my last test:
cisco.nxos.nxos_interfaces:

ANSIBLE VERSION
ansible [core 2.14.9]
  config file = /home/cristian_cardoso/ansible-cisco/ansible.cfg
  configured module search path = ['/home/cristian_cardoso/ansible-cisco/my_modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/cristian_cardoso/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Jan  4 2024, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
$ ansible-galaxy collection list cisco.nxos

# /home/cristian_cardoso/.ansible/collections/ansible_collections
Collection Version
---------- -------
cisco.nxos 8.1.0

CONFIGURATION
$ ansible-config dump --only-changed
CONFIG_FILE() = /home/cristian_cardoso/ansible-cisco/ansible.cfg
DEFAULT_ASK_PASS(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = False
DEFAULT_EXECUTABLE(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = /usr/bin/bash
DEFAULT_FORKS(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = 5
DEFAULT_HOST_LIST(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = ['/home/cristian_cardoso/ansible-cisco/hosts']
DEFAULT_LOCAL_TMP(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = /home/cristian_cardoso/ansible-cisco/.ansible/tmp/ansible-local-2096_1mv6eja
DEFAULT_LOG_PATH(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = /home/cristian_cardoso/ansible-cisco/ansible.log
DEFAULT_MANAGED_STR(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = Ansible managed
DEFAULT_MODULE_NAME(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = command
DEFAULT_MODULE_PATH(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = ['/home/cristian_cardoso/ansible-cisco/my_modules']
DEFAULT_PRIVATE_KEY_FILE(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = /home/cristian_cardoso/.ssh/id_rsa
DEFAULT_REMOTE_PORT(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = 22
DEFAULT_REMOTE_USER(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = ansible-cisco
DEFAULT_ROLES_PATH(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = ['/home/cristian_cardoso/ansible-cisco/roles']
DEFAULT_TIMEOUT(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = 10
HOST_KEY_CHECKING(/home/cristian_cardoso/ansible-cisco/ansible.cfg) = False
OS / ENVIRONMENT

Rocky Linux 9.3
Cisco Nexus 9300v nxos 9.3.4

STEPS TO REPRODUCE
- collections:
  - cisco.nxos

  gather_facts: no
  hosts: nxos

  vars:
    ansible_connection: ansible.netcommon.httpapi
    ansible_network_os: cisco.nxos.nxos
    ansible_user: ansible-cisco
    password: test123

  tasks:
  - name: Change interface from L2 to L3
    cisco.nxos.nxos_interfaces:
      config:
      - name: Ethernet1/6
        description: "##Config from ansible"
        enabled: true
        mtu: 9216
        mode: layer3


EXPECTED RESULTS

What is expected is that Ansible connects to the Cisco Nexus switch and performs configuration on the interface

ACTUAL RESULTS

In the current result I always receive this SSH error, even using nxapi as the connection method.

TASK [Change interface from L2 to L3] **********************************************************************************************************************************************************************************
task path: /home/cristian_cardoso/ansible-cisco/roles/nxos/interfaces/interfaces.yml:28
The full traceback is:
  File "/home/cristian_cardoso/.ansible/collections/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/network.py", line 218, in get_capabilities
    capabilities = Connection(module._socket_path).get_capabilities()
  File "/usr/lib/python3.9/site-packages/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [sw-nxos-ansible-2]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "config": [
                {
                    "description": "##Config from ansible",
                    "duplex": null,
                    "enabled": true,
                    "fabric_forwarding_anycast_gateway": null,
                    "ip_forward": null,
                    "mode": "layer3",
                    "mtu": "9216",
                    "name": "Ethernet1/6",
                    "speed": null
                }
            ],
            "running_config": null,
            "state": "merged"
        }
    },
    "msg": "SSH-2.0-OpenSSH_7.5 PKIX[10.1]\n"
}

@jcremp77
Copy link

jcremp77 commented Sep 3, 2024

Here is what I have in the 'all' file under the '/group_vars' directory.

ansible_connection: httpapi
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: no
ansible_network_os: nxos
ansible_user: admin
ansible_httpapi_pass: somepassword

In my lab I am running 9.3(9).bin, and this works with no issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants