Ansible-core 2.20 Porting Guide
This section discusses the behavioral changes between ansible-core 2.19 and ansible-core 2.20.
It is intended to assist in updating your playbooks, plugins, and other parts of your Ansible infrastructure so they will work with this version of Ansible.
Review this page and the ansible-core Changelog for 2.20 to understand necessary changes.
This document is part of a collection on porting. The complete list of porting guides can be found at porting guides.
Introduction
No notable changes
Playbook
Removed quote stripping in PowerShell operations
The PowerShell module utilities no longer attempt to remove quotes from paths when performing Windows operations like copying and fetching files. This should not affect normal playbooks unless a value is quoted too many times. If you have playbooks that rely on this automatic quote removal, you will need to adjust your path formatting.
Engine
No notable changes
Plugin API
Removed Features
The following previously deprecated features have been removed:
The
DEFAULT_TRANSPORTconfiguration option no longer supports thesmartvalue that selected the default transport as eithersshorparamikobased on the underlying platform configuration.The
vaultandunvaultfilters no longer accept the deprecatedvaultidparameter.The
ansible-galaxycommand no longer supports the v2 Galaxy server API. Galaxy servers hosting collections must support v3.The
dnfanddnf5modules no longer support the deprecatedinstall_repoqueryoption.The
encryptmodule utility no longer includes the deprecatedpasslib_or_cryptAPI.The
paramikoconnection plugin no longer supports thePARAMIKO_HOST_KEY_AUTO_ADDandPARAMIKO_LOOK_FOR_KEYSconfiguration keys, which were previously deprecated.The
py3compat.environcall has been removed.Vars plugins that do not inherit from
BaseVarsPluginand define aget_varsmethod can no longer use the deprecatedget_host_varsorget_group_varsfallback.The
yum_repositorymodule no longer supports the deprecatedkeepcacheoption.
Behavioral Changes
The
DataLoader.get_basedirmethod now returns an absolute path instead of a relative path. Plugin code that relies on relative paths may need adjustment.Argument spec validation now treats
Nonevalues as empty strings for thestrtype for better consistency with pre-2.19 templating conversions.When using
failed_whento suppress an error, theexceptionkey in the result is now renamed tofailed_when_suppressed_exception. This prevents the error from being displayed by callbacks after being suppressed. If you have playbooks that check for the exception in the result, update them as follows:
# Before
- command: /bin/false
register: result
failed_when: false
- debug:
msg: "Exception was: {{ result.exception }}"
when: result.exception is defined
# After
- command: /bin/false
register: result
failed_when: false
- debug:
msg: "Exception was: {{ result.failed_when_suppressed_exception }}"
when: result.failed_when_suppressed_exception is defined
Command Line
Python 3.11 is no longer a supported control node version. Python 3.12+ is now required for running Ansible.
Python 3.8 is no longer a supported remote version. Python 3.9+ is now required for target execution.
Deprecated
INJECT_FACTS_AS_VARS
The INJECT_FACTS_AS_VARS configuration currently defaults to True, but this is now deprecated and it will switch to False in Ansible 2.24.
When enabled, facts are available both inside the ansible_facts dictionary and as individual variables in the main namespace. In the ansible_facts dictionary, the ansible_ prefix is removed from fact names.
You will receive deprecation warnings if you are accessing ‘injected’ facts. To prepare for the future default:
Update your playbooks to use the ansible_facts dictionary:
# Deprecated - will stop working in 2.24
- debug:
msg: "OS: {{ ansible_os_distribution }}"
# Recommended - works in all versions
- debug:
msg: "OS: {{ ansible_facts['distribution'] }}"
# Note: 'ansible_' prefix is removed inside ansible_facts
Or explicitly enable the current behavior in your configuration:
In your ansible.cfg file:
[defaults]
inject_facts_as_vars = True
By exporting an environment variable:
export ANSIBLE_INJECT_FACT_VARS=True
Other Deprecations
The
varsinternal variable cache will be removed in 2.24. This cache, once used internally, exposes variables in inconsistent states. Thevarsandvarnameslookups should be used instead.Specifying
ignore_filesas a string in theinclude_varsmodule is deprecated. Use a list instead:
# Deprecated
- include_vars:
dir: vars/
ignore_files: ".gitkeep"
# Correct
- include_vars:
dir: vars/
ignore_files: [".gitkeep"]
Modules
Modules removed
The following modules no longer exist:
No notable changes
Deprecation notices
No notable changes
Noteworthy module changes
The
include_varsmodule now raises an error if theextensionsparameter is not specified as a list. Previously, non-list values were silently accepted.The
include_varsmodule now raises an error if theignore_filesparameter is not specified as a list. Previously, string values were accepted but are now deprecated.The
replacemodule now reads and writes files in text-mode as unicode characters instead of as bytes, and switches regex matching to unicode characters instead of bytes. This may affect playbooks that rely on byte-level operations.
Plugins
Noteworthy plugin changes
No notable changes
Porting custom scripts
No notable changes
Networking
No notable changes