Need to force inventory cache usage past timeout

2 views
Skip to first unread message

Orion Poplawski

unread,
Jul 14, 2020, 7:21:17 PM7/14/20
to Ansible Development
I'm working on converting the old cobbler inventory script to an inventory plugin.  See https://github.com/ansible-collections/community.general/pull/627

The behavior that I last had with my last version of the inventory script was for it to fall back to the cached data regardless of the time since last update if it could not contact the cobbler server.  This allows for ansible-pull to work off of our internal network.  However, with the use of cache plugins (jsonfile in my case) I do not see a way to achieve this.  Any suggestions?

Orion Poplawski

unread,
Jul 15, 2020, 11:14:33 AM7/15/20
to Ansible Development
This is what I've come up with:

self._options['cache_timeout'] = 0
self.load_cache_plugin()
self._cache.get(self.cache_key, {})

seems to work.


--
Orion Poplawski
Manager of NWRA Technical Systems 720-772-5637
NWRA, Boulder/CoRA Office FAX: 303-415-9702
3380 Mitchell Lane or...@nwra.com
Boulder, CO 80301 https://www.nwra.com/

Orion Poplawski

unread,
Jul 16, 2020, 6:52:38 PM7/16/20
to Ansible Development
On 7/15/20 9:14 AM, Orion Poplawski wrote:
> On 7/14/20 5:21 PM, Orion Poplawski wrote:
>> I'm working on converting the old cobbler inventory script to an
>> inventory plugin.  See
>> https://github.com/ansible-collections/community.general/pull/627
>>
>> The behavior that I last had with my last version of the inventory
>> script was for it to fall back to the cached data regardless of the
>> time since last update if it could not contact the cobbler server.
>> This allows for ansible-pull to work off of our internal network.
>> However, with the use of cache plugins (jsonfile in my case) I do not
>> see a way to achieve this.  Any suggestions?
>
> This is what I've come up with:
>
>             self._options['cache_timeout'] = 0
>             self.load_cache_plugin()
>             self._cache.get(self.cache_key, {})
>
> seems to work.

Well, not quite. Due to the bug mentioned below I ended up with:

# Work around https://github.com/ansible/ansible/issues/70702
self._options['cache_timeout'] = sys.maxsize
Reply all
Reply to author
Forward
0 new messages