Closed Andyjb8 closed 4 months ago
Hey @Andyjb8, Retrieving facts from cache is not possible as we do not support caching of facts in collection level. If you have any further questions feel free to reach out!
Hmm, but it is caching the facts as it's creating the fact file for my test router in "/var/tmp/facts/" which is the path defined in my ansible.cfg. See below showing it is caching the facts. So I guess the module isn't able to retrieve the cached facts? Is this something that could be added in the future?
fact caching settings in ansible.cfg
fact_caching = jsonfile
fact_caching_connection= /var/tmp/facts/
fact_caching_prefix=ansible_facts
fact_caching_timeout=86400
Here is my playbook: gather_facts.yml
- name: Get Facts
hosts: all
gather_facts: False
tasks:
- name: Gather IOS facts
cisco.ios.ios_facts:
gather_subset: interfaces
Running the playbook:
admin@ansible:~$ ansible-playbook playbooks/gather_fact.yml --limit RT-02 -vvv
ansible-playbook [core 2.15.8]
config file = /home/admin/ansible.cfg
configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/admin/automation/collections/ansible_collections
executable location = /usr/bin/ansible-playbook
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
Using /home/admin/ansible.cfg as config file
ERROR! the playbook: playbooks/gather_fact.yml could not be found
admin@ansible:~$ ansible-playbook automation/playbooks/gather_fact.yml --limit RT-02 -vvv
ansible-playbook [core 2.15.8]
config file = /home/admin/ansible.cfg
configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/admin/automation/collections/ansible_collections
executable location = /usr/bin/ansible-playbook
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
Using /home/admin/ansible.cfg as config file
Parsed /home/admin/automation/inventory/hosts.ini inventory source with ini plugin
redirecting (type: action) cisco.ios.ios_facts to cisco.ios.ios
redirecting (type: callback) ansible.builtin.profile_tasks to ansible.posix.profile_tasks
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: gather_fact.yml ********************************************************************************
1 plays in automation/playbooks/gather_fact.yml
PLAY [Get Facts] *****************************************************************************************
redirecting (type: action) cisco.ios.ios_facts to cisco.ios.ios
TASK [Gather IOS facts] **********************************************************************************
task path: /home/admin/automation/playbooks/gather_fact.yml:6
Monday 08 January 2024 16:51:54 +0000 (0:00:00.083) 0:00:00.083 ********
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
redirecting (type: action) cisco.ios.ios_facts to cisco.ios.ios
redirecting (type: action) cisco.ios.ios_facts to cisco.ios.ios
...
<fact debug output ommitted>
....
PLAY RECAP ***********************************************************************************************
RT-02 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Monday 08 January 2024 16:52:41 +0000 (0:00:46.487) 0:00:46.570 ********
===============================================================================
Gather IOS facts --------------------------------------------------------------------------------- 46.49s
And it created the fact file:
admin@ansible:~$ ls -al /var/tmp/facts/ansible_factsRT-02
-rw------- 1 admin admin 7163 Jan 8 16:45 /var/tmp/facts/ansible_factsRT-02
admin@ansible:~$ more /var/tmp/facts/ansible_factsRT-02
{
"ansible_net_all_ipv4_addresses": [
"x.x.0.9",
"x.x.2.10",
"x.x.2.4",
"x.x.2.6",
"x.x.1.2",
"x.x.1.6",
"x.x.0.2",
"x.x.1.20",
"x.x.1.22"
],
"ansible_net_all_ipv6_addresses": [],
"ansible_net_api": "cliconf",
"ansible_net_gather_network_resources": [],
"ansible_net_gather_subset": [
"default",
"interfaces"
],
"ansible_net_hostname": "RT-02",
"ansible_net_image": "bootflash:packages.conf",
"ansible_net_interfaces": {
"GigabitEthernet1": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [
{
"address": "x.x.0.9",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": "5254.000d.941c",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet2": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [],
"lineprotocol": "up",
"macaddress": "5254.0005.3631",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet2.20": {
"bandwidth": 1000000,
"description": null,
"duplex": null,
"ipv4": [
{
"address": "x.x.2.10",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": "5254.0005.3631",
"mediatype": null,
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet3": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [],
"lineprotocol": "up",
"macaddress": "5254.0015.aeff",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet3.200": {
"bandwidth": 1000000,
"description": null,
"duplex": null,
"ipv4": [
{
"address": "x.x.2.4",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": "5254.0015.aeff",
"mediatype": null,
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet3.201": {
"bandwidth": 1000000,
"description": null,
"duplex": null,
"ipv4": [
{
"address": "x.x.2.6",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": "5254.0015.aeff",
"mediatype": null,
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet4": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [
{
"address": "x.x.1.2",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": "5254.0014.8d73",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet5": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [
{
"address": "x.x.1.6",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": "5254.0005.4947",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "up",
"type": "CSR vNIC"
},
"GigabitEthernet6": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [],
"lineprotocol": "down",
"macaddress": "5254.0005.69b9",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "administratively down",
"type": "CSR vNIC"
},
"GigabitEthernet7": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [],
"lineprotocol": "down",
"macaddress": "5254.0001.4e47",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "administratively down",
"type": "CSR vNIC"
},
"GigabitEthernet8": {
"bandwidth": 1000000,
"description": null,
"duplex": "Full",
"ipv4": [],
"lineprotocol": "down",
"macaddress": "5254.0001.4c0c",
"mediatype": "Virtual",
"mtu": 1500,
"operstatus": "administratively down",
"type": "CSR vNIC"
},
"Loopback0": {
"bandwidth": 8000000,
"description": null,
"duplex": null,
"ipv4": [
{
"address": "x.x.0.2",
"subnet": "32"
}
],
"lineprotocol": "up",
"macaddress": null,
"mediatype": null,
"mtu": 1514,
"operstatus": "up",
"type": null
},
"Tunnel20": {
"bandwidth": 100,
"description": "to -02",
"duplex": null,
"ipv4": [
{
"address": "x.x.1.20",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": null,
"mediatype": null,
"mtu": 9946,
"operstatus": "up",
"type": null
},
"Tunnel21": {
"bandwidth": 100,
"description": "to -01",
"duplex": null,
"ipv4": [
{
"address": "x.x.1.22",
"subnet": "31"
}
],
"lineprotocol": "up",
"macaddress": null,
"mediatype": null,
"mtu": 9946,
"operstatus": "up",
"type": null
}
},
"ansible_net_iostype": "IOS-XE",
"ansible_net_model": "CSR1000V",
"ansible_net_neighbors": {},
"ansible_net_operatingmode": "autonomous",
"ansible_net_python_version": "3.10.12",
"ansible_net_serialnum": "97YCT7LQSZG",
"ansible_net_system": "ios",
"ansible_net_version": "17.03.04a",
"ansible_network_resources": {}
}
@Andyjb8, while the module does create a cache file, it doesn't actively utilize the cache based on my current understanding. This isn't a priority for us at the moment, but it's certainly something we plan to explore in the future. Hope this helps. Thanks
SUMMARY
Fact caching does not seem to be working with cisco.ios.ios_facts
ISSUE TYPE
COMPONENT NAME
cisco.ios.ios_facts
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy
STEPS TO REPRODUCE
ansible-playbook test.yml --limit RT-01 -vvvvv
EXPECTED RESULTS
I expect it to retrieve facts from cache on subsequent runs, It is creating the ansible facts file as shown below, but it updates the fact file timestamp every time the playbook is run and it doesn't appear to run any faster on subsequent runs. I would think the debug would show the module retrieving facts from cache as well, but I am not seeing anything indicating that it is. It is taking about 33 seconds to gather facts in my lab and I feel it should be faster if using cached facts.
user@al-svr-ansb-01:~$ ls -al /var/tmp/facts/ansible_factsRT-01 -rw------- 1 user user 6829 Dec 28 15:51 /var/tmp/facts/ansible_factsRT-01
ACTUAL RESULTS