cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2754
Views
0
Helpful
5
Replies

Ansible - iosxe - modules failed to execute: ansible.legacy.ios_facts

Netmart
Level 1
Level 1

Hello,

When I am trying to run ansible on Cisco IOS XE cat4500, I am experiencing the following error:

"msg": "The following modules failed to execute: ansible.legacy.ios_facts\n"}

/etc/ansible$ ansible-playbook -i hosts site.yml -u cisco -k
SSH password:

PLAY [Test Ansible ios_command on Cisco IOS XE] ****************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************
fatal: [10.1.199.199]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.ios_facts": {"failed": true, "invocation": {"module_args": {"available_network_resources": false, "gather_network_resources": null, "gather_subset": ["min"]}}, "msg": "socket path /home/wolfm/.ansible/pc/cfb7b81b73 does not exist or cannot be found. See Troubleshooting socket path issues in the Network Debug and Troubleshooting Guide"}}, "msg": "The following modules failed to execute: ansible.legacy.ios_facts\n"}

PLAY RECAP *****************************************************************************************************************************************
10.1.199.199 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

 

 

 

$ tree
.
├── hosts
└── site.yml

 

 


:/etc/ansible$ cat hosts
[iosxe]
10.1.199.199

 

 

[iosxe:vars]
ansible_network_os=ios
ansible_connection=network_cli

 

 

 

/etc/ansible$ cat site.yml
---
- name: Test Ansible ios_command on Cisco IOS XE
hosts: iosxe

tasks:
- name: show version and ip interface brief
ios_command:
commands:
- show version
- show ip interface brief

 

1 Accepted Solution

Accepted Solutions

Try disabling host key checking. There are three options to do this.

1. in your inventory using the ansible_host_key_checking variable 
2. in your ansible.cfg config file:
[defaults]
host_key_checking = False
3. via an environment variable
export ANSIBLE_HOST_KEY_CHECKING=False

View solution in original post

5 Replies 5

The error message "socket path /home/wolfm/.ansible/pc/cfb7b81b73 does not exist or cannot be found" means that the Ansible control socket cannot be created or opened at the specified path.

Try running with -vvv for more verbose output.

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

Thank you.

I tried to run with -vvv

$ ansible-playbook -i hosts site.yml -u cisco -k -vvv
ansible-playbook [core 2.15.3]
config file = None
configured module search path = ['/home/cisco/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /home/cisco/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
No config file found; using defaults
SSH password:
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
redirecting (type: modules) ansible.builtin.ios_command to cisco.ios.ios_command
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

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

PLAY [Test Ansible ios_command on Cisco IOS XE] ****************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************
task path: /etc/ansible/site.yml:2
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
redirecting (type: modules) ansible.builtin.ios_facts to cisco.ios.ios_facts
<10.254.199.199> ESTABLISH LOCAL CONNECTION FOR USER: cisco
<10.254.199.199> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe `"&& mkdir "` echo /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174 `" && echo ansible-tmp-1692508229.287533-2758956-148054784301174="` echo /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.ios_facts to cisco.ios.ios_facts
Using module file /usr/local/lib/python3.10/dist-packages/ansible_collections/cisco/ios/plugins/modules/ios_facts.py
<10.254.199.199> PUT /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/tmpe7fl69j7 TO /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174/AnsiballZ_ios_facts.py
<10.254.199.199> EXEC /bin/sh -c 'chmod u+x /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174/ /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174/AnsiballZ_ios_facts.py && sleep 0'
<10.254.199.199> EXEC /bin/sh -c '/usr/bin/python3 /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174/AnsiballZ_ios_facts.py && sleep 0'
<10.254.199.199> EXEC /bin/sh -c 'rm -f -r /home/cisco/.ansible/tmp/ansible-local-27589347gwvaahe/ansible-tmp-1692508229.287533-2758956-148054784301174/ > /dev/null 2>&1 && sleep 0'
fatal: [10.254.199.199]: FAILED! => {
"ansible_facts": {},
"changed": false,
"failed_modules": {
"ansible.legacy.ios_facts": {
"exception": " File \"/tmp/ansible_ansible.legacy.ios_facts_payload_bpduxpy3/ansible_ansible.legacy.ios_facts_payload.zip/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/network.py\", line 215, in get_capabilities\n capabilities = Connection(module._socket_path).get_capabilities()\n File \"/tmp/ansible_ansible.legacy.ios_facts_payload_bpduxpy3/ansible_ansible.legacy.ios_facts_payload.zip/ansible/module_utils/connection.py\", line 194, in __rpc__\n response = self._exec_jsonrpc(name, *args, **kwargs)\n File \"/tmp/ansible_ansible.legacy.ios_facts_payload_bpduxpy3/ansible_ansible.legacy.ios_facts_payload.zip/ansible/module_utils/connection.py\", line 141, in _exec_jsonrpc\n raise ConnectionError(\n",
"failed": true,
"invocation": {
"module_args": {
"available_network_resources": false,
"gather_network_resources": null,
"gather_subset": [
"min"
]
}
},
"msg": "socket path /home/cisco/.ansible/pc/f056954806 does not exist or cannot be found. See Troubleshooting socket path issues in the Network Debug and Troubleshooting Guide"
}
},
"msg": "The following modules failed to execute: ansible.legacy.ios_facts\n"
}

PLAY RECAP *****************************************************************************************************************************************
10.254.199.199 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

 

I made same progress by raising the privileges sfor site.yml and hosts file and install paramariko:

 

$ sudo ansible-playbook -vvv -i hosts site.yml -u cisco -k
ansible-playbook [core 2.15.3]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
No config file found; using defaults
SSH password:
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
redirecting (type: modules) ansible.builtin.ios_command to cisco.ios.ios_command
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

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

PLAY [Test Ansible ios_command on Cisco IOS XE] ****************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************
task path: /etc/ansible/site.yml:2
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
redirecting (type: modules) ansible.builtin.ios_facts to cisco.ios.ios_facts
<10.254.199.199> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.254.199.199> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-2765610uledwhch `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949 `" && echo ansible-tmp-1692510303.0462918-2765633-98595561764949="` echo /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.ios_facts to cisco.ios.ios_facts
Using module file /usr/local/lib/python3.10/dist-packages/ansible_collections/cisco/ios/plugins/modules/ios_facts.py
<10.254.199.199> PUT /root/.ansible/tmp/ansible-local-2765610uledwhch/tmp4l42imnb TO /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949/AnsiballZ_ios_facts.py
<10.254.199.199> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949/ /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949/AnsiballZ_ios_facts.py && sleep 0'
<10.254.199.199> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949/AnsiballZ_ios_facts.py && sleep 0'
<10.254.199.199> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-2765610uledwhch/ansible-tmp-1692510303.0462918-2765633-98595561764949/ > /dev/null 2>&1 && sleep 0'
fatal: [10.254.199.199]: FAILED! => {
"ansible_facts": {},
"changed": false,
"failed_modules": {
"ansible.legacy.ios_facts": {
"exception": " File \"/tmp/ansible_ansible.legacy.ios_facts_payload_8wdczifu/ansible_ansible.legacy.ios_facts_payload.zip/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/network.py\", line 215, in get_capabilities\n capabilities = Connection(module._socket_path).get_capabilities()\n File \"/tmp/ansible_ansible.legacy.ios_facts_payload_8wdczifu/ansible_ansible.legacy.ios_facts_payload.zip/ansible/module_utils/connection.py\", line 200, in __rpc__\n raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\n",
"failed": true,
"invocation": {
"module_args": {
"available_network_resources": false,
"gather_network_resources": null,
"gather_subset": [
"min"
]
}
},
"msg": "paramiko: The authenticity of host '10.254.199.199' can't be established.\nThe ssh-rsa key fingerprint is b'506db790d7e4ea48c13946cb647c3d6c'."
}
},
"msg": "The following modules failed to execute: ansible.legacy.ios_facts\n"
}

PLAY RECAP *****************************************************************************************************************************************
10.254.199.199 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

Try disabling host key checking. There are three options to do this.

1. in your inventory using the ansible_host_key_checking variable 
2. in your ansible.cfg config file:
[defaults]
host_key_checking = False
3. via an environment variable
export ANSIBLE_HOST_KEY_CHECKING=False

Thank you Marcel.

I had to create the ansible.cfg under ansible directory first and then adding the suggesting parameter:

 

[defaults]

# some basic default values...

inventory      = $HOME/.ansible/hosts

remote_tmp     = $HOME/.ansible/tmp

forks          = 150

sudo_user      = root

transport      = smart

# plays will gather facts by default, which contain information about

# the remote system.

#

# smart - gather by default, but don't regather if already gathered

# implicit - gather by default, turn off with gather_facts: False

# explicit - do not gather by default, must say gather_facts: True

gathering = smart

# additional paths to search for roles in, colon separated

roles_path    = $HOME/.ansible/roles

# uncomment this to disable SSH key host checking

host_key_checking = False