Upgrading your Ansible Playbooks: Step by step guide
October 21, 2024 - Updated: November 30, 2026 - Words by Lucija Korbar - 9 min read
To upgrade Ansible Playbooks to a new version, you need to find every incompatibility with the target version, fix what can be fixed automatically, resolve the rest by hand, and test before you run anything in production.
Upgrading Ansible Playbooks and roles to the latest Ansible version can be quite a challenge, as a lot can change between versions (best practices alter, parameters and modules are moved or renamed, attributes are deprecated) … and the most challenging of all: you need to figure out what you were trying to accomplish with the playbook you wrote all those years ago. Or worse - you weren’t even the one who wrote it in the first place. And now you need to decide how to maintain the effect but upgrade the code.
Things that were excellently written years ago have now become errors. And if you’re upgrading from older versions when Ansible Collections weren’t even a thing, you’re in for some heavy lifting, if you approach this process manually. But luckily you don’t have to. While Ansible upgrades are a thing you can’t avoid forever they don’t have to be as daunting as they seem at first glance. Not when you have tools to make the job much easier for you.
In this blog post, we guide you through the process of upgrading your playbooks from Ansible 2.4 to ansible-core 2.20 step by step. We also show how, by using Steampunk Spotter the upgrade process can take minutes instead of hours, helping you ensure that nothing is overlooked - preventing issues from small errors to serious security hazards.
For the full planning and migration picture, see our complete guide to Ansible upgrade and migration.
Let’s dive in!

What changes between Ansible versions
How much work an upgrade takes depends on where you start. These are the changes most likely to break existing playbooks. The official porting guides list them all.
| Upgrading across | What typically breaks |
|---|---|
| 2.9 or older → 2.10+ | modules moved into collections. Short module names need fully qualified collection names (FQCNs), and the collections must be installed separately. |
| → 2.19 | The templating engine was rebuilt. Conditionals that don’t return true or false now fail, and templates nested inside expressions are rejected. |
| → 2.20 | Python 3.12+ is required on the control node and 3.9+ on managed nodes. |
| → 2.21 | password_hash produces different (still valid) hashes. Inferring task failure from a non-zero rc is deprecated. |
Check your current version with ansible --version. We upgrade to ansible-core 2.20 here, but the steps work the same for newer versions.
Choose powerful tools
We will be upgrading an Ansible Playbook and roles from Ansible 2.4 to ansible-core 2.20, which is a big leap since that’s eight years of dependency changes between versions.
The Ansible ecosystem has several tools that help with this, and we’ll use Steampunk Spotter, which is built for writing, maintaining and upgrading Ansible Playbooks. Spotter improves the quality of playbooks, helps keep them secure and compliant, and simplifies and speeds up Ansible upgrades as it:
- identifies all the issues you need to resolve when upgrading to a new Ansible version,
- fixes the issues it can for you automatically,
- helps you save time with convenience features such as generating a requirements file or by pointing you to the module documentation of a specific version.
You’ll see this in action later, and you’ll also see how Steampunk Spotter helps you achieve maximum results.
Step 1: Do a general scan
Start with a quick syntax check and lint:
ansible-playbook site.yml --syntax-check
ansible-lint
These catch YAML and structure errors, but not what changed between Ansible versions. For that, we use Spotter.
Run Spotter for your target version to see what compatibility issues it finds. In our case, that’s 2.20, so we run:
spotter scan --ansible-version 2.20 .
We get quite a few errors, but most are related to the use of FQCNs.
A great thing about Spotter is the fact that it can automatically fix some of the problems it finds. It may not be able to fix all of them, since some require you to explicitly decide what you want to do, but for the problems where such a decision is not required, it fixes them immediately. You simply add the optional --rewrite argument to the command.
Step 2: Scan with automatic rewrite function
So, we run Spotter again, and this time we turn on the rewrite flag:
spotter scan --ansible-version 2.20 . --rewrite
Spotter will magically fix FQCN-related issues for you.
For example, a task written for Ansible 2.4 gets its fully qualified collection name:
# Before
- name: Install nginx
apt:
name: nginx
state: present
# After
- name: Install nginx
ansible.builtin.apt:
name: nginx
state: present
Step 3: Run Spotter again
Below the rewritten items, Spotter lists the remaining check results. There are much fewer errors now that the FQCN-related ones are fixed.
However, there are still some other issues. These are the ones that Spotter could not fix with the rewrite function because they are not among the things that a tool can do for you 100% reliably. We have to decide specifically what to do for each error, hint or warning.
Some errors are minor fixes, like parameters being renamed or restructured. They do not take much time. Others are still simple, but require a decision to be made. For example: if a default value of a parameter changes, is the new default still what you want? If you did not specify a value explicitly before, Spotter now prompts you to decide on the desired behaviour as part of the upgrade.
But some errors require a little more work. For example, we encountered these errors for the community.docker.docker_image module: build is not a valid value for state, path should be specified inside the build parameter, and force is not a valid parameter.
What we have to do now is figure out what the valid parameters are in the latest version of the module. So how do you do that? Spending lots of time browsing again? This is another example of how Spotter helps you save time. It already provides you with the link to the documentation, where you can find all the information you need to fix this error. There, we can see that the module parameters have been fundamentally restructured, but without any changes to how they function.
Here’s the fix:
# Before
- docker_image:
name: myapp
path: ./app
force: yes
# After
- community.docker.docker_image:
name: myapp
source: build
build:
path: ./app
force_source: true
If you’re upgrading to 2.19 or later, you’ll probably also see the error “does not produce a boolean”. Older versions treated any non-empty value as true, while 2.19 and later require an explicit true or false:
# Fails on 2.19+
when: backup_targets
# Works on all versions
when: backup_targets | length > 0
Like that, we go through all these errors, and fix them.
Another thing you might notice is that when running with --rewrite, Spotter generated a requirements.yml file for you automatically, based on the latest versions of the collections the modules are located in.
Step 4: Run Spotter again, again
After automatically fixing FQCNs and manually fixing remaining mistakes, it’s time to run spotter scan --ansible-version 2.20 once again, to catch any potential errors that may have remained.
In our case, Spotter has found two remaining issues. We forgot to fix an error and instead skipped over an error line. Oops. You see, it’s good to run these tools several times to really spot things we may have missed.
The remaining mistake (valid_in is not a valid parameter in module community.crypto.x509_certificate) is the hardest part of our upgrade. The module used to be called openssl_certificate. It was then moved into a collection and subsequently renamed. There are two migrations, and it becomes really hard to parse them because if you search for openssl_certificate, you will not find the new module. This is where Spotter really helps you out. It keeps track of all the migrations the module has gone through between collections and renames and does everything for you by generating a requirements file, rewriting to the current newest FQCN and pointing you to the correct documentation page.
There is another issue in our demo that we have yet to solve, but since this is a very complicated upgrade, it’s difficult to show how it’s done in a blog post. But don’t worry, in this free webinar, where we go over everything shown in this post and more you can see how it’s done step by step.
Step 5: Run checks one last time
To make sure you have done everything necessary for a successful upgrade, run Spotter one last time after you have fixed the remaining problems. If Spotter finds no errors, you are done with the upgrade. If not, just fix the remaining issues and repeat the process, and you’re done.
Well, almost, there is just one thing left to do.
Step 6: Install Ansible Collections with the automatically generated requirements file
Now that you have fixed the remaining issues, you have one more thing to do: Install Ansible Collections. Otherwise, you will not have the content to run your playbooks and roles. As mentioned earlier, Spotter has generated a requirements file, which again comes in very handy because now all we have to do is run ansible-galaxy collection install -r requirements.yml and wait for collections to be installed.
If older versions of these collections are already installed, add --upgrade to update them:
ansible-galaxy collection install -r requirements.yml --upgrade
The grand finale: run your playbook
Then we run the playbook again (in check mode first!), and if everything works (and it should now), the upgrade is complete.
ansible-playbook site.yml --check --diff
That’s it! Waay faster than figuring out the checks and fixes yourself, right? For a rough idea, our team did some testing. They took this playbook and fixed everything manually, which took 2 hours (and remember they knew exactly where to look for the documentation they needed, otherwise it would have taken even longer), but with Spotter it took 20 minutes! (This test was done on the 2.4 -> 2.17 upgrade.)
As mentioned earlier, it’s difficult to show all the steps we took to upgrade this playbook in one blog post. Therefore, we have also created a detailed video walkthrough of this upgrade. In this free webinar, we walk you through the entire process step by step.
Frequently Asked Questions
How do I update Ansible and my playbooks to a new version?
Check your current version with ansible --version. Then install the target version in a separate virtual environment with pip install --upgrade ansible-core, and check your playbooks against it. Fix fully qualified collection names and renamed modules first, since tools can do this automatically. Then resolve the remaining issues by hand, install the required collections and test in check mode before you roll out.
Can I upgrade directly from Ansible 2.9 to 2.21?
Yes. You don’t need to install every version in between, but your playbooks must account for every change in between. Read each porting guide from 2.10 to 2.21, or use a tool that checks your code against the target version and reports all issues at once.
Why do my playbooks fail with “Conditionals must have a boolean result”?
ansible-core 2.19 introduced a stricter templating engine. Conditions in when:, that: and failed_when: must now return true or false. Older versions treated any non-empty value as true. Make the condition explicit, for example my_list | length > 0 instead of my_list.
What if my managed nodes run an older Python version?
ansible-core 2.20 and 2.21 need Python 3.9 or newer on managed nodes. If some hosts can’t be upgraded, you can install a newer Python on them and point ansible_python_interpreter to it. The other option is to keep a separate environment with an older ansible-core for those hosts.
How long does an Ansible upgrade take?
It depends on the version gap and the amount of code. In our test, upgrading one playbook with roles took two hours by hand and 20 minutes with Spotter’s automatic checks and fixes.
