Cannot reach device using ansible
Hello,
I have been trying to use dev environment recently for an internal project unsuccessfully.
Looks like despite my ansible.cfg and inventory file, I’ve still got the same result with the following message :
[Errno -2] Name or service not known
From a specific device, I am using the following command :
ansible-playbook playbooks/business.yml -i inventories/dev -t telemetry -l switch-mpls-1-tco --check --diff
and getting the following output :
fatal: [switch-mpls-1-tco]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.nxos_facts": {"failed": true, "invocation": {"module_args": {"available_network_resources": false, "gather_network_resources": null, "gather_subset": ["min"]}}, "msg": "[Errno -2] Name or service not known"}}, "msg": "The following modules failed to execute: ansible.legacy.nxos_facts\n"}
However, from the same device, I succeed to connect to device using ssh
ssh switch-mpls-preprod-1-tco
switch-mpls-preprod-1-tco#
In my inventory file, I have an alias for switch-mpls-1-tco
[switches]
switch-mpls-1-tco ansible_host=switch-mpls-preprod-1-tco
and in my playbook, I activated gather_facts to check if connection failed before any other thing
- name: TELEMETRY
hosts: mpls
gather_facts: true
roles:
- role: telemetry
tags:
- telemetry
In my environment, I use following version :
- ansible [core 2.18.6]
- python 3.11 (pipenv)
and I have a ssh/config file with User and ProxyJump for my host, works fine for a classic ssh connection.
Any ideas ? How can I troubleshoot this ?
Thanks in advance,
EDIT :
After update /etc/resolv.conf, switch-mpls-preprod-1-tco is resolved on the same device I use to deploy configuration via ansible. And output changed, now I’ve got :
Could not open socket to switch-mpls-preprod-1-tco:830
Netconf is already enabled on switch-mpls-preprod-1-tco using command feature netconf, so port 830 should be open. SSH access on port 830 works :
ssh gsicard@switch-mpls-preprod-1-tco -p 830 netconf
EDIT 2 :
Turns out it was a ssh config issue. Using a proxyjump, Cisco NXOS module (netconf here) needs to open a socket on port 830 : this request/command was not forward in the ssh connection via ansible. Below the line I add in my ssh config :
proxycommand ssh -W %h:%p root@my-jump-server
issue solved