cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4038
Views
10
Helpful
3
Replies

Unable to run Ansible Tasks nxos_facts

soccermoy92
Level 1
Level 1

Hello, I am wondering if we should be able to use Ansible to connect to the Open NXOS Sandbox. Ive tried multiple things but dont seem to be getting anywhere. Or does this necessarily need to be done using one of the reserved ones.

I am following the Using Ansible with NXOS Devices Learning Lab

And using a host running PoPOS! 20.4 LTS

 

Here is the configs of my files

 

Play: DevNetwork.yml

---
- name: Get 9K Facts
hosts: DevNexus
connection: local
tasks:
- name: Get Nexus9K Facts
nxos_facts:
host: "{{inventory_hostname}}"
transport: nxapi
use_ssl: yes
validate_certs: no
register: nxos_data
- name: Print name to Console
debug: msg="{{nxos_data}}"

 

 

hosts file

[DevNexus]
sbx-nxos-mgmt.cisco.com ansible_python_interpreter="/usr/bin/env python3"

 

 

.ansible_env

export ANSIBLE_NET_USERNAME=XXXXX
export ANSIBLE_NET_PASSWORD=XXXXX
export ANSIBLE_CONNECTION=local

 

 

Below is the output from running my playbook, does anyone see anything that I am missing here ?Thanks in advance!

centinal@cential-desktop:~/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking$ ansible-playbook DevNetwork.yml -vvv
ansible-playbook 2.9.6
config file = /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/ansible.cfg
configured module search path = ['/home/centinal/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
Using /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/ansible.cfg as config file
host_list declined parsing /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/hosts as it did not pass its verify_file() method
script declined parsing /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/hosts as it did not pass its verify_file() method
auto declined parsing /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/hosts as it did not pass its verify_file() method
Parsed /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/hosts inventory source with ini plugin

PLAYBOOK: DevNetwork.yml ****************************************************************************************************************************************************************
1 plays in DevNetwork.yml

PLAY [Get 9K Facts] *********************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
task path: /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/DevNetwork.yml:2
<sbx-nxos-mgmt.cisco.com> ESTABLISH LOCAL CONNECTION FOR USER: centinal
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c 'echo ~centinal && sleep 0'
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828 `" && echo ansible-tmp-1590700247.5525086-234989752281828="` echo /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828 `" ) && sleep 0'
Using module file /usr/lib/python3/dist-packages/ansible/modules/system/setup.py
<sbx-nxos-mgmt.cisco.com> PUT /home/centinal/.ansible/tmp/ansible-local-406738lhgaidp/tmpt4bzvccg TO /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828/AnsiballZ_setup.py
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c 'chmod u+x /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828/ /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828/AnsiballZ_setup.py && sleep 0'
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c '/usr/bin/env python3 /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828/AnsiballZ_setup.py && sleep 0'
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c 'rm -f -r /home/centinal/.ansible/tmp/ansible-tmp-1590700247.5525086-234989752281828/ > /dev/null 2>&1 && sleep 0'
ok: [sbx-nxos-mgmt.cisco.com]
META: ran handlers

TASK [Get Nexus9K Facts] ****************************************************************************************************************************************************************
task path: /home/centinal/Documents/200-901DevAsc/CBT_Nuggets/CodeSamples-master/Ansible/networking/DevNetwork.yml:6
<sbx-nxos-mgmt.cisco.com> ESTABLISH LOCAL CONNECTION FOR USER: centinal
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c 'echo ~centinal && sleep 0'
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189 `" && echo ansible-tmp-1590700248.4386744-5275697939189="` echo /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189 `" ) && sleep 0'
Using module file /usr/lib/python3/dist-packages/ansible/modules/network/nxos/nxos_facts.py
<sbx-nxos-mgmt.cisco.com> PUT /home/centinal/.ansible/tmp/ansible-local-406738lhgaidp/tmp3vkeuzme TO /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c 'chmod u+x /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/ /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py && sleep 0'
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c '/usr/bin/env python3 /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py && sleep 0'
<sbx-nxos-mgmt.cisco.com> EXEC /bin/sh -c 'rm -f -r /home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py", line 102, in <module>
_ansiballz_main()
File "/home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.network.nxos.nxos_facts', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib/python3.8/runpy.py", line 206, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/modules/network/nxos/nxos_facts.py", line 239, in <module>
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/modules/network/nxos/nxos_facts.py", line 230, in main
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/nxos/facts/facts.py", line 57, in __init__
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/common/facts/facts.py", line 23, in __init__
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/common/network.py", line 213, in get_resource_connection
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/common/network.py", line 229, in get_capabilities
File "/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/connection.py", line 121, in __init__
AssertionError: socket_path must be a value
fatal: [sbx-nxos-mgmt.cisco.com]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File \"/home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py\", line 102, in <module>\n _ansiballz_main()\n File \"/home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/centinal/.ansible/tmp/ansible-tmp-1590700248.4386744-5275697939189/AnsiballZ_nxos_facts.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.network.nxos.nxos_facts', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/lib/python3.8/runpy.py\", line 206, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib/python3.8/runpy.py\", line 96, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib/python3.8/runpy.py\", line 86, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/modules/network/nxos/nxos_facts.py\", line 239, in <module>\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/modules/network/nxos/nxos_facts.py\", line 230, in main\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/nxos/facts/facts.py\", line 57, in __init__\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/common/facts/facts.py\", line 23, in __init__\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/common/network.py\", line 213, in get_resource_connection\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/network/common/network.py\", line 229, in get_capabilities\n File \"/tmp/ansible_nxos_facts_payload_e8j05em4/ansible_nxos_facts_payload.zip/ansible/module_utils/connection.py\", line 121, in __init__\nAssertionError: socket_path must be a value\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

PLAY RECAP ******************************************************************************************************************************************************************************
sbx-nxos-mgmt.cisco.com : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

1 Accepted Solution

Accepted Solutions

Hey there, Could you share the link/url as to how you found that learning lab please, as I checked and it was disabled in 2018.

I tested some code against that device.

 

- name: NXOS Query
  hosts: nxos
  connection: local

  tasks:
  - name: Enable NX-API
    vars:
      ansible_connection: network_cli
      ansible_network_os: nxos
      ansible_user: admin
      ansible_password: Admin_1234!
      ansible_port: 8181
    nxos_nxapi:
        enable_http: yes
        enable_https: yes
[nxos]
sbx-nxos-mgmt.cisco.com ansible_python_interpreter="/usr/bin/env python3"

The result is below, this confirms there are no issues with the NXOS device.

 

(venv) STUACLAR-M-R6EU:nxos_test stuaclar$ ansible-playbook -i ansible-hosts nxos_facts.yml

PLAY [NXOS Query] ********************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************
ok: [sbx-nxos-mgmt.cisco.com]

TASK [Enable NX-API] *****************************************************************************************************************************************************************
ok: [sbx-nxos-mgmt.cisco.com]

PLAY RECAP ***************************************************************************************************************************************************************************
sbx-nxos-mgmt.cisco.com    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Based on your output, it looks like there is an issue on your local machine. It does not look like you are using a `venv`. I run all my code in `venv` if you are using a Mac you can make one (choose your Python version as you wish)

 

virtualenv venv --python=python3.6
source venv/bin/activate

Hope this helps.

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

3 Replies 3

Hey there, Could you share the link/url as to how you found that learning lab please, as I checked and it was disabled in 2018.

I tested some code against that device.

 

- name: NXOS Query
  hosts: nxos
  connection: local

  tasks:
  - name: Enable NX-API
    vars:
      ansible_connection: network_cli
      ansible_network_os: nxos
      ansible_user: admin
      ansible_password: Admin_1234!
      ansible_port: 8181
    nxos_nxapi:
        enable_http: yes
        enable_https: yes
[nxos]
sbx-nxos-mgmt.cisco.com ansible_python_interpreter="/usr/bin/env python3"

The result is below, this confirms there are no issues with the NXOS device.

 

(venv) STUACLAR-M-R6EU:nxos_test stuaclar$ ansible-playbook -i ansible-hosts nxos_facts.yml

PLAY [NXOS Query] ********************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************
ok: [sbx-nxos-mgmt.cisco.com]

TASK [Enable NX-API] *****************************************************************************************************************************************************************
ok: [sbx-nxos-mgmt.cisco.com]

PLAY RECAP ***************************************************************************************************************************************************************************
sbx-nxos-mgmt.cisco.com    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Based on your output, it looks like there is an issue on your local machine. It does not look like you are using a `venv`. I run all my code in `venv` if you are using a Mac you can make one (choose your Python version as you wish)

 

virtualenv venv --python=python3.6
source venv/bin/activate

Hope this helps.

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Thanks, Ill take another look at tmy machine,

I dont know how I found that learning lab, Im not seeing it anymore.

were you able to find a way around ? I found the similar error