Ansible Core Knowledge Patch
Use this skill when changing Ansible playbooks, inventories, controller plugins,
connection settings, test targets, or modules that depend on current
ansible-core behavior.
Working Method
- Determine the installed or pinned
ansible-core version from dependency
manifests, execution-environment definitions, or lockfiles.
- Inspect the affected playbooks and plugins for the migration points below.
- Open the topic reference before changing behavior that depends on an exact
configuration name, default, result type, or plugin API.
- Prefer project tests and observed runtime behavior when a project carries
compatibility shims or backports.
Reference Index
| Reference |
Topics |
| templating.md |
Trust, single-pass evaluation, native values, strict conditionals, lazy templating, omit, sandboxing, and JSON profiles |
| plugins-and-extensions.md |
Controller-side I/O, callback and strategy migrations, Jinja plugins, markers, builtin names, vars plugins, and collection packages |
| connections-and-privilege.md |
SSH agents and askpass, Paramiko migration, connection verbosity, local become, and sudo_chdir |
| playbooks-cli-and-inventory.md |
CLI flags, inventory parsing, diagnostics, deprecated play syntax, argument-spec validation, and Galaxy behavior |
| modules-facts-and-windows.md |
Fact access, file and package modules, result types, UTF-8 enforcement, Windows execution, and module patch behavior |
| testing-runtime-and-security.md |
ansible-test environments and timeout diagnostics, supported runtimes, maintenance dates, and security fixes |
Highest-Priority Migration Checks
Treat templating as trusted and single-pass
- Jinja expressions in untrusted strings, including facts and module results,
are not evaluated merely because the strings contain delimiters.
- Preserve trust when a plugin transforms a value that is intended to remain a
template. Apply trust explicitly when a plugin creates such a value.
- Remove designs that depend on one template producing another template for a
later pass.
- Do not wrap ordinary conditionals in
{{ ... }}. A whole trusted string
expression is the narrow exception.
# Preferred
when: service_enabled | bool
# Avoid
when: "{{ service_enabled | bool }}"
Expect native values and boolean conditionals
- Template results retain native types; do not assume automatic string
conversion.
- Do not assume
None becomes an empty string.
set_fact preserves the literal strings yes, no, true, and false
when they are supplied as strings.
- A conditional must produce a boolean. Use an explicit comparison or a
suitable conversion instead of relying on truthiness.
- Treat
ALLOW_BROKEN_CONDITIONALS as a short-lived migration aid, not a
permanent compatibility mode.
- name: Use an explicit boolean conversion
ansible.builtin.debug:
msg: enabled
when: feature_flag | bool
Audit lazy values and omit
- Only accessed portions of a structure are templated, so errors may surface
later than structure construction.
omit is removed from its parent container during templating.
- In loops, use
default(omit) on the value that should disappear from module
arguments.
- Code calling
Templar.template() must handle
AnsibleValueOmittedError when the complete result is omitted.
- ansible.builtin.user:
name: "{{ item.name }}"
shell: "{{ item.shell | default(omit) }}"
loop: "{{ users }}"
Plugin and Extension Quick Reference
Controller-side code
- Task forks do not provide functional standard input, output, or error
streams. Use
Display for controller-side messages.
- Convert Ansible-provided subclasses of Python builtins to plain native types
before passing them to strict third-party libraries.
- Builtin Jinja filters and tests may be addressed with the
ansible.builtin.<name> form.
- Python packages below
module_utils may contain __init__.py.
Callback, strategy, vars, and Jinja migration
- Callback plugins must derive from
CallbackBase.
- Replace the v1 callback API and
v2_on_any with the specific v2_
callbacks.
- Third-party strategy plugins are deprecated without a planned replacement.
- Replace custom Jinja extensions with filter, test, or lookup plugins.
- A Jinja plugin must explicitly opt in before accepting an undefined
top-level argument.
- Code using
environment.getitem must handle MarkerError and return a
marker, or explicitly opt in to marker values.
- Vars plugins must inherit
BaseVarsPlugin and implement get_vars.
Connection and Privilege Quick Reference
SSH authentication
- The SSH connection uses
SSH_ASKPASS by default for password prompting.
ansible, ansible-playbook, and ansible-console can create or reuse an
SSH agent.
ansible_ssh_private_key and
ansible_ssh_private_key_passphrase can load a key from variables.
- Set
SSH_AGENT_EXECUTABLE to choose the agent binary.
- Use
ANSIBLE_SSH_VERBOSITY or ansible_ssh_verbosity for SSH-only
verbosity.
Deprecated transports and removed settings
- Migrate Paramiko connection use to the SSH connection.
- Remove
DEFAULT_TRANSPORT=smart, PARAMIKO_HOST_KEY_AUTO_ADD, and
PARAMIKO_LOOK_FOR_KEYS.
- For the local connection, account for
become_strip_preamble defaulting to
true and become_success_timeout defaulting to 10 seconds.
sudo_chdir changes directory before invoking sudo.
Playbook, CLI, and Inventory Quick Reference
- Use
--flush-cache where cache invalidation is needed with ansible,
ansible-console, or ansible-pull.
- Inventory files ending in
.ini are parsed by default unless ini is put
back into INVENTORY_IGNORE_EXTS.
- Use
DISPLAY_TRACEBACK to control tracebacks; -vvv is not the traceback
switch.
- Consume task-result
warnings and deprecations when building diagnostic
tooling.
- Prefer
--inventory over the deprecated --inventory-file alias.
- Replace
play_hosts with ansible_play_batch.
- Remove empty
args, mapping-form action, and combinations of
key=value arguments with args.
- Set
ansible_managed as a regular variable instead of using
DEFAULT_MANAGED_STR.
Validate play arguments
Set validate_argspec: true to select the required play name, or use a
string to select another entry from <playbook_name>.meta.yml.
# deploy.yml
- name: deploy
hosts: all
validate_argspec: true
# deploy.meta.yml
argument_specs:
deploy:
options:
environment:
type: str
required: true
Modules, Facts, and Results Quick Reference
- Migrate injected top-level facts such as
ansible_os_distribution to
ansible_facts['os_distribution'].
- Prefer the
vars and varnames lookups over the internal variable cache.
- Read per-volume-group logical volumes from each
ansible_facts['vgs'] entry's lvs subkey when completeness matters.
async_status.started and async_status.finished are booleans, not integer
flags.
- Pass lists to
include_vars.extensions and include_vars.ignore_files.
- Use
encoding with blockinfile and lineinfile for non-UTF-8 files.
- Expect
replace to read, match, and write Unicode text.
- Review automatic dependency installation in
apt, dnf5, and
deb822_repository before relying on minimal target images.
- Treat non-UTF-8 module response strings as errors; disabling strict checking
is a compatibility escape hatch.
Test and Upgrade Checklist
- Exercise templates with facts and module-result strings containing literal
Jinja delimiters.
- Test conditionals for genuine boolean results.
- Cover loop arguments that can resolve to
omit.
- Run custom plugins without functional standard streams.
- Test SSH agent creation, key loading, and local become timeout behavior.
- Verify inventory discovery for
.ini files.
- Assert boolean async-status fields in integrations.
- Run Windows automation under the intended PowerShell host and application
control policy.
- Give
ansible-test enough deadline headroom to emit pre-timeout thread
diagnostics.
- Check the detailed references before removing compatibility workarounds.
1---2name: ansible-knowledge-patch-23description: Ansible Core4license: MIT5---678# Ansible Core Knowledge Patch910Use this skill when changing Ansible playbooks, inventories, controller plugins,11connection settings, test targets, or modules that depend on current12`ansible-core` behavior.1314## Working Method15161. Determine the installed or pinned `ansible-core` version from dependency17 manifests, execution-environment definitions, or lockfiles.182. Inspect the affected playbooks and plugins for the migration points below.193. Open the topic reference before changing behavior that depends on an exact20 configuration name, default, result type, or plugin API.214. Prefer project tests and observed runtime behavior when a project carries22 compatibility shims or backports.2324## Reference Index2526| Reference | Topics |27| --- | --- |28| [templating.md](references/templating.md) | Trust, single-pass evaluation, native values, strict conditionals, lazy templating, `omit`, sandboxing, and JSON profiles |29| [plugins-and-extensions.md](references/plugins-and-extensions.md) | Controller-side I/O, callback and strategy migrations, Jinja plugins, markers, builtin names, vars plugins, and collection packages |30| [connections-and-privilege.md](references/connections-and-privilege.md) | SSH agents and askpass, Paramiko migration, connection verbosity, local become, and `sudo_chdir` |31| [playbooks-cli-and-inventory.md](references/playbooks-cli-and-inventory.md) | CLI flags, inventory parsing, diagnostics, deprecated play syntax, argument-spec validation, and Galaxy behavior |32| [modules-facts-and-windows.md](references/modules-facts-and-windows.md) | Fact access, file and package modules, result types, UTF-8 enforcement, Windows execution, and module patch behavior |33| [testing-runtime-and-security.md](references/testing-runtime-and-security.md) | `ansible-test` environments and timeout diagnostics, supported runtimes, maintenance dates, and security fixes |3435## Highest-Priority Migration Checks3637### Treat templating as trusted and single-pass3839- Jinja expressions in untrusted strings, including facts and module results,40 are not evaluated merely because the strings contain delimiters.41- Preserve trust when a plugin transforms a value that is intended to remain a42 template. Apply trust explicitly when a plugin creates such a value.43- Remove designs that depend on one template producing another template for a44 later pass.45- Do not wrap ordinary conditionals in `{{ ... }}`. A whole trusted string46 expression is the narrow exception.4748```yaml49# Preferred50when: service_enabled | bool5152# Avoid53when: "{{ service_enabled | bool }}"54```5556### Expect native values and boolean conditionals5758- Template results retain native types; do not assume automatic string59 conversion.60- Do not assume `None` becomes an empty string.61- `set_fact` preserves the literal strings `yes`, `no`, `true`, and `false`62 when they are supplied as strings.63- A conditional must produce a boolean. Use an explicit comparison or a64 suitable conversion instead of relying on truthiness.65- Treat `ALLOW_BROKEN_CONDITIONALS` as a short-lived migration aid, not a66 permanent compatibility mode.6768```yaml69- name: Use an explicit boolean conversion70 ansible.builtin.debug:71 msg: enabled72 when: feature_flag | bool73```7475### Audit lazy values and `omit`7677- Only accessed portions of a structure are templated, so errors may surface78 later than structure construction.79- `omit` is removed from its parent container during templating.80- In loops, use `default(omit)` on the value that should disappear from module81 arguments.82- Code calling `Templar.template()` must handle83 `AnsibleValueOmittedError` when the complete result is omitted.8485```yaml86- ansible.builtin.user:87 name: "{{ item.name }}"88 shell: "{{ item.shell | default(omit) }}"89 loop: "{{ users }}"90```9192## Plugin and Extension Quick Reference9394### Controller-side code9596- Task forks do not provide functional standard input, output, or error97 streams. Use `Display` for controller-side messages.98- Convert Ansible-provided subclasses of Python builtins to plain native types99 before passing them to strict third-party libraries.100- Builtin Jinja filters and tests may be addressed with the101 `ansible.builtin.<name>` form.102- Python packages below `module_utils` may contain `__init__.py`.103104### Callback, strategy, vars, and Jinja migration105106- Callback plugins must derive from `CallbackBase`.107- Replace the v1 callback API and `v2_on_any` with the specific `v2_`108 callbacks.109- Third-party strategy plugins are deprecated without a planned replacement.110- Replace custom Jinja extensions with filter, test, or lookup plugins.111- A Jinja plugin must explicitly opt in before accepting an undefined112 top-level argument.113- Code using `environment.getitem` must handle `MarkerError` and return a114 marker, or explicitly opt in to marker values.115- Vars plugins must inherit `BaseVarsPlugin` and implement `get_vars`.116117## Connection and Privilege Quick Reference118119### SSH authentication120121- The SSH connection uses `SSH_ASKPASS` by default for password prompting.122- `ansible`, `ansible-playbook`, and `ansible-console` can create or reuse an123 SSH agent.124- `ansible_ssh_private_key` and125 `ansible_ssh_private_key_passphrase` can load a key from variables.126- Set `SSH_AGENT_EXECUTABLE` to choose the agent binary.127- Use `ANSIBLE_SSH_VERBOSITY` or `ansible_ssh_verbosity` for SSH-only128 verbosity.129130### Deprecated transports and removed settings131132- Migrate Paramiko connection use to the SSH connection.133- Remove `DEFAULT_TRANSPORT=smart`, `PARAMIKO_HOST_KEY_AUTO_ADD`, and134 `PARAMIKO_LOOK_FOR_KEYS`.135- For the local connection, account for `become_strip_preamble` defaulting to136 true and `become_success_timeout` defaulting to 10 seconds.137- `sudo_chdir` changes directory before invoking `sudo`.138139## Playbook, CLI, and Inventory Quick Reference140141- Use `--flush-cache` where cache invalidation is needed with `ansible`,142 `ansible-console`, or `ansible-pull`.143- Inventory files ending in `.ini` are parsed by default unless `ini` is put144 back into `INVENTORY_IGNORE_EXTS`.145- Use `DISPLAY_TRACEBACK` to control tracebacks; `-vvv` is not the traceback146 switch.147- Consume task-result `warnings` and `deprecations` when building diagnostic148 tooling.149- Prefer `--inventory` over the deprecated `--inventory-file` alias.150- Replace `play_hosts` with `ansible_play_batch`.151- Remove empty `args`, mapping-form `action`, and combinations of152 `key=value` arguments with `args`.153- Set `ansible_managed` as a regular variable instead of using154 `DEFAULT_MANAGED_STR`.155156### Validate play arguments157158Set `validate_argspec: true` to select the required play `name`, or use a159string to select another entry from `<playbook_name>.meta.yml`.160161```yaml162# deploy.yml163- name: deploy164 hosts: all165 validate_argspec: true166```167168```yaml169# deploy.meta.yml170argument_specs:171 deploy:172 options:173 environment:174 type: str175 required: true176```177178## Modules, Facts, and Results Quick Reference179180- Migrate injected top-level facts such as `ansible_os_distribution` to181 `ansible_facts['os_distribution']`.182- Prefer the `vars` and `varnames` lookups over the internal variable cache.183- Read per-volume-group logical volumes from each184 `ansible_facts['vgs']` entry's `lvs` subkey when completeness matters.185- `async_status.started` and `async_status.finished` are booleans, not integer186 flags.187- Pass lists to `include_vars.extensions` and `include_vars.ignore_files`.188- Use `encoding` with `blockinfile` and `lineinfile` for non-UTF-8 files.189- Expect `replace` to read, match, and write Unicode text.190- Review automatic dependency installation in `apt`, `dnf5`, and191 `deb822_repository` before relying on minimal target images.192- Treat non-UTF-8 module response strings as errors; disabling strict checking193 is a compatibility escape hatch.194195## Test and Upgrade Checklist196197- Exercise templates with facts and module-result strings containing literal198 Jinja delimiters.199- Test conditionals for genuine boolean results.200- Cover loop arguments that can resolve to `omit`.201- Run custom plugins without functional standard streams.202- Test SSH agent creation, key loading, and local become timeout behavior.203- Verify inventory discovery for `.ini` files.204- Assert boolean async-status fields in integrations.205- Run Windows automation under the intended PowerShell host and application206 control policy.207- Give `ansible-test` enough deadline headroom to emit pre-timeout thread208 diagnostics.209- Check the detailed references before removing compatibility workarounds.