mirror of https://github.com/ansible/ansible.git
sanitize path symbols in inventory_hostname on file cache plugins (#41420)
* File based cache plugins filenames fix File based cache plugins will now correctly handle inventory_hostnames with 'path symbols' in their names. This should allow those using chroot and jail connection plugins to use file based caches now.pull/86077/head
parent
7bd2475a70
commit
d9d11d6ff6
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- cache plugins based on the BaseFileCache class will now sanitize keys to avoid names that could cause issues with the storage path
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = """
|
||||||
|
name: dummy_file_cache
|
||||||
|
short_description: dummy file cache
|
||||||
|
description: see short
|
||||||
|
options:
|
||||||
|
_uri:
|
||||||
|
required: True
|
||||||
|
description:
|
||||||
|
- Path in which the cache plugin will save the files
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_CACHE_PLUGIN_CONNECTION
|
||||||
|
ini:
|
||||||
|
- key: fact_caching_connection
|
||||||
|
section: defaults
|
||||||
|
type: path
|
||||||
|
_prefix:
|
||||||
|
description: User defined prefix to use when creating the files
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_CACHE_PLUGIN_PREFIX
|
||||||
|
ini:
|
||||||
|
- key: fact_caching_prefix
|
||||||
|
section: defaults
|
||||||
|
_timeout:
|
||||||
|
default: 86400
|
||||||
|
description: Expiration timeout for the cache plugin data
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_CACHE_PLUGIN_TIMEOUT
|
||||||
|
ini:
|
||||||
|
- key: fact_caching_timeout
|
||||||
|
section: defaults
|
||||||
|
type: integer
|
||||||
|
"""
|
||||||
|
|
||||||
|
from ansible.plugins.cache import BaseFileCacheModule
|
||||||
|
|
||||||
|
|
||||||
|
class CacheModule(BaseFileCacheModule):
|
||||||
|
|
||||||
|
_persistent = False
|
||||||
|
|
||||||
|
def _load(self, filepath: str) -> object:
|
||||||
|
with open(filepath, 'r') as jfile:
|
||||||
|
return eval(filepath.read())
|
||||||
|
|
||||||
|
def _dump(self, value: object, filepath: str) -> None:
|
||||||
|
with open(filepath, 'w') as afile:
|
||||||
|
afile.write(str(value))
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = """
|
||||||
|
name: dummy_file_cache
|
||||||
|
short_description: dummy file cache
|
||||||
|
description: see short
|
||||||
|
options:
|
||||||
|
_uri:
|
||||||
|
required: True
|
||||||
|
description:
|
||||||
|
- Path in which the cache plugin will save the files
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_CACHE_PLUGIN_CONNECTION
|
||||||
|
ini:
|
||||||
|
- key: fact_caching_connection
|
||||||
|
section: defaults
|
||||||
|
type: path
|
||||||
|
_prefix:
|
||||||
|
description: User defined prefix to use when creating the files
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_CACHE_PLUGIN_PREFIX
|
||||||
|
ini:
|
||||||
|
- key: fact_caching_prefix
|
||||||
|
section: defaults
|
||||||
|
_timeout:
|
||||||
|
default: 86400
|
||||||
|
description: Expiration timeout for the cache plugin data
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_CACHE_PLUGIN_TIMEOUT
|
||||||
|
ini:
|
||||||
|
- key: fact_caching_timeout
|
||||||
|
section: defaults
|
||||||
|
type: integer
|
||||||
|
"""
|
||||||
|
|
||||||
|
from ansible.plugins.cache import BaseFileCacheModule
|
||||||
|
|
||||||
|
|
||||||
|
class CacheModule(BaseFileCacheModule):
|
||||||
|
|
||||||
|
def _load(self, filepath: str) -> object:
|
||||||
|
with open(filepath, 'r') as jfile:
|
||||||
|
return eval(filepath.read())
|
||||||
|
|
||||||
|
def _dump(self, value: object, filepath: str) -> None:
|
||||||
|
with open(filepath, 'w') as afile:
|
||||||
|
afile.write(str(value))
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
chroots:
|
||||||
|
hosts:
|
||||||
|
/my/chroot/host1:
|
||||||
|
bogusvar: foobarvalue
|
||||||
|
/my/chroot/host2:
|
||||||
|
traversal:
|
||||||
|
hosts:
|
||||||
|
..:
|
||||||
|
...:
|
||||||
|
|
||||||
|
all:
|
||||||
|
vars:
|
||||||
|
ansible_connection: local
|
||||||
|
ansible_python_interpreter: '{{ansible_playbook_python}}'
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
- hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: populate cache, will fail if invalid files are used
|
||||||
|
set_fact:
|
||||||
|
cacheable: true
|
||||||
|
testing: 123{{inventory_hostname}}
|
||||||
Loading…
Reference in New Issue