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 exact
configuration names, defaults, or plugin APIs.
- Apply only guidance introduced at or below the project's version. If the
project is newer than the frontmatter version, treat this patch as
potentially stale.
- 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, collection loading, markers, builtin names, and module_utils packages |
| connections-and-privilege.md |
SSH agents and askpass, Paramiko removal, connection verbosity, local become, sudo_chdir, and Windows transports |
| 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.
- Compatibility mode for broken conditionals is temporary and should only
support a staged migration.
- 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, 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.
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.
Removed and deprecated transports
- Do not introduce a Paramiko dependency; migrate inventory and configuration
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-patch3description: 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 exact20 configuration names, defaults, or plugin APIs.214. Apply only guidance introduced at or below the project's version. If the22 project is newer than the frontmatter version, treat this patch as23 potentially stale.245. Prefer project tests and observed runtime behavior when a project carries25 compatibility shims or backports.2627## Reference Index2829| Reference | Topics |30| --- | --- |31| [templating.md](references/templating.md) | Trust, single-pass evaluation, native values, strict conditionals, lazy templating, `omit`, sandboxing, and JSON profiles |32| [plugins-and-extensions.md](references/plugins-and-extensions.md) | Controller-side I/O, callback and strategy migrations, Jinja plugins, collection loading, markers, builtin names, and `module_utils` packages |33| [connections-and-privilege.md](references/connections-and-privilege.md) | SSH agents and askpass, Paramiko removal, connection verbosity, local become, `sudo_chdir`, and Windows transports |34| [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 |35| [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 |36| [testing-runtime-and-security.md](references/testing-runtime-and-security.md) | `ansible-test` environments and timeout diagnostics, supported runtimes, maintenance dates, and security fixes |3738## Highest-Priority Migration Checks3940### Treat templating as trusted and single-pass4142- Jinja expressions in untrusted strings, including facts and module results,43 are not evaluated merely because the strings contain delimiters.44- Preserve trust when a plugin transforms a value that is intended to remain a45 template. Apply trust explicitly when a plugin creates such a value.46- Remove designs that depend on one template producing another template for a47 later pass.48- Do not wrap ordinary conditionals in `{{ ... }}`. A whole trusted string49 expression is the narrow exception.5051```yaml52# Preferred53when: service_enabled | bool5455# Avoid56when: "{{ service_enabled | bool }}"57```5859### Expect native values and boolean conditionals6061- Template results retain native types; do not assume automatic string62 conversion.63- Do not assume `None` becomes an empty string.64- `set_fact` preserves the literal strings `yes`, `no`, `true`, and `false`65 when they are supplied as strings.66- A conditional must produce a boolean. Use an explicit comparison or a67 suitable conversion instead of relying on truthiness.68- Compatibility mode for broken conditionals is temporary and should only69 support a staged migration.7071```yaml72- name: Use an explicit boolean conversion73 ansible.builtin.debug:74 msg: enabled75 when: feature_flag | bool76```7778### Audit lazy values and `omit`7980- Only accessed portions of a structure are templated, so errors may surface81 later than structure construction.82- `omit` is removed from its parent container during templating.83- In loops, use `default(omit)` on the value that should disappear from module84 arguments.85- Code calling `Templar.template()` must handle86 `AnsibleValueOmittedError` when the complete result is omitted.8788```yaml89- ansible.builtin.user:90 name: "{{ item.name }}"91 shell: "{{ item.shell | default(omit) }}"92 loop: "{{ users }}"93```9495## Plugin and Extension Quick Reference9697### Controller-side code9899- Task forks do not provide functional standard input, output, or error100 streams. Use `Display` for controller-side messages.101- Convert Ansible-provided subclasses of Python builtins to plain native types102 before passing them to strict third-party libraries.103- Builtin Jinja filters and tests may be addressed with the104 `ansible.builtin.<name>` form.105- Python packages below `module_utils` may contain `__init__.py`.106107### Callback, strategy, and Jinja migration108109- Callback plugins must derive from `CallbackBase`.110- Replace the v1 callback API and `v2_on_any` with the specific `v2_`111 callbacks.112- Third-party strategy plugins are deprecated without a planned replacement.113- Replace custom Jinja extensions with filter, test, or lookup plugins.114- A Jinja plugin must explicitly opt in before accepting an undefined115 top-level argument.116- Code using `environment.getitem` must handle `MarkerError` and return a117 marker, or explicitly opt in to marker values.118119## Connection and Privilege Quick Reference120121### SSH authentication122123- The SSH connection uses `SSH_ASKPASS` by default for password prompting.124- `ansible`, `ansible-playbook`, and `ansible-console` can create or reuse an125 SSH agent.126- `ansible_ssh_private_key` and127 `ansible_ssh_private_key_passphrase` can load a key from variables.128- Set `SSH_AGENT_EXECUTABLE` to choose the agent binary.129- Use `ANSIBLE_SSH_VERBOSITY` or `ansible_ssh_verbosity` for SSH-only130 verbosity.131132### Removed and deprecated transports133134- Do not introduce a Paramiko dependency; migrate inventory and configuration135 to the SSH connection.136- Remove `DEFAULT_TRANSPORT=smart`,137 `PARAMIKO_HOST_KEY_AUTO_ADD`, and `PARAMIKO_LOOK_FOR_KEYS`.138- For the local connection, account for `become_strip_preamble` defaulting to139 true and `become_success_timeout` defaulting to 10 seconds.140- `sudo_chdir` changes directory before invoking `sudo`.141142## Playbook, CLI, and Inventory Quick Reference143144- Use `--flush-cache` where cache invalidation is needed with `ansible`,145 `ansible-console`, or `ansible-pull`.146- Inventory files ending in `.ini` are parsed by default unless `ini` is put147 back into `INVENTORY_IGNORE_EXTS`.148- Use `DISPLAY_TRACEBACK` to control tracebacks; `-vvv` is not the traceback149 switch.150- Consume task-result `warnings` and `deprecations` when building diagnostic151 tooling.152- Prefer `--inventory` over the deprecated `--inventory-file` alias.153- Replace `play_hosts` with `ansible_play_batch`.154- Remove empty `args`, mapping-form `action`, and combinations of155 `key=value` arguments with `args`.156- Set `ansible_managed` as a regular variable instead of using157 `DEFAULT_MANAGED_STR`.158159### Validate play arguments160161Set `validate_argspec: true` to select the required play `name`, or use a162string to select another entry from `<playbook_name>.meta.yml`.163164```yaml165# deploy.yml166- name: deploy167 hosts: all168 validate_argspec: true169```170171```yaml172# deploy.meta.yml173argument_specs:174 deploy:175 options:176 environment:177 type: str178 required: true179```180181## Modules, Facts, and Results Quick Reference182183- Migrate injected top-level facts such as `ansible_os_distribution` to184 `ansible_facts['os_distribution']`.185- Prefer the `vars` and `varnames` lookups over the internal variable cache.186- Read per-volume-group logical volumes from each187 `ansible_facts['vgs']` entry's `lvs` subkey when completeness matters.188- `async_status.started` and `async_status.finished` are booleans, not integer189 flags.190- Pass lists to `include_vars.extensions` and `include_vars.ignore_files`.191- Use `encoding` with `blockinfile` and `lineinfile` for non-UTF-8 files.192- Expect `replace` to read, match, and write Unicode text.193- Review automatic dependency installation in `apt`, `dnf5`, and194 `deb822_repository` before relying on minimal target images.195- Treat non-UTF-8 module response strings as errors; disabling strict checking196 is a compatibility escape hatch.197198## Test and Upgrade Checklist199200- Exercise templates with facts and module-result strings containing literal201 Jinja delimiters.202- Test conditionals for genuine boolean results.203- Cover loop arguments that can resolve to `omit`.204- Run custom plugins without functional standard streams.205- Test SSH agent creation, key loading, and local become timeout behavior.206- Verify inventory discovery for `.ini` files.207- Assert boolean async-status fields in integrations.208- Run Windows automation under the intended PowerShell host and application209 control policy.210- Give `ansible-test` enough deadline headroom to emit pre-timeout thread211 diagnostics.212- Check the detailed references before removing compatibility workarounds.