Add toggle

pull/82224/head
Matt Martz 2 years ago
parent 3044f49e3b
commit dca37091a3
No known key found for this signature in database
GPG Key ID: 40832D88E9FC91D8

@ -764,6 +764,20 @@ DEFAULT_JINJA2_NATIVE:
type: boolean
yaml: {key: jinja2_native}
version_added: 2.7
JINJA2_BYTECODE_CACHE:
name: Cache the jinja2 bytecode for compiled templates
description:
- This option, which is enabled by default, will cache the jinja2 generated
bytecode for templates reducing execution time, specifically for template
heavy playbooks. Disabling this will prevent the bytecode cache from
being used.
env:
- {name: ANSIBLE_JINJA2_BYTECODE_CACHE}
ini:
- {key: jinja2_bytecode_cache, section: defaults}
type: boolean
default: True
version_added: '2.17'
DEFAULT_KEEP_REMOTE_FILES:
name: Keep remote files
default: False

@ -583,6 +583,9 @@ class AnsibleEnvironment(NativeEnvironment):
template_class: t.Type[Template] | None = None,
) -> Template:
if not C.JINJA2_BYTECODE_CACHE:
return super().from_string(source, globals=globals, template_class=template_class)
cache_dir = os.path.join(C.DEFAULT_LOCAL_TMP, 'j2cache')
if not os.path.isdir(cache_dir):
os.makedirs(cache_dir, mode=0o700, exist_ok=True)

Loading…
Cancel
Save