Skip to content

Pickle inventory cache always result in cache misses #11365

@marcinwidm

Description

@marcinwidm

Summary

Using pickle inventory cache always result in cache misses (KeyError), causing inventory plugins to fetch data on every call.

Workaround: adding self._cache.load_whole_cache() in inventory plugin seems to fix constant cache misses for singular keys with pickle.

Issue Type

Bug Report

Component Name

pickle

Ansible Version

$ ansible --version
ansible [core 2.20.1]
  config file = None
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.14/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/.local/bin/ansible
  python version = 3.14.2 (main, Dec  6 2025, 08:54:59) [GCC 13.3.0] (/usr/bin/python3.14)
  jinja version = 3.1.2
  pyyaml version = 6.0.1 (without libyaml)

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 12.2.0

Configuration

$ ansible-config dump --only-changed
CACHE_PLUGIN_CONNECTION(env: ANSIBLE_CACHE_PLUGIN_CONNECTION) = ./cache_dir
CONFIG_FILE() = None

GALAXY_SERVERS:

OS / Environment

Ubuntu

Steps to Reproduce

Use any inventory plugin with pickle cache enabled e.g. nmap_inventory.yaml (issue occurs also with different inventory plugins e.g. netbox nb_inventory).

plugin: community.general.nmap
strict: false
address: 127.0.0.1
use_extra_vars: true
cache: true
cache_plugin: community.general.pickle
cache_connection: cache_dir

Run ansible-inventory -i nmap_inventory.yaml --list

Run command again (optionally chaning address to e.g. 127.0.0.1/24 to get visible pause)

Expected Results

On second run, pickle cache should be used - not calling nmap again

Actual Results

Nmap runs scan again as inventory plugin gets KeyError when checking cached data

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bugcachecache pluginhas_prpluginsplugin (any type)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions