In a real-world scenario, if a newly deployed RPM does not behave as expected, doing a rollback, i.e., downgrading the RPM to its previously installed, older version, is a typical backoff procedure. It surprises me a lot that the Ansible yum module does not support this out of the box, at least not with version 1.9.4, which I tested. There is an open pull request for this feature on GitHub.
My solution is using a shell task to do the downgrade when a variable
rollback is explicitly set to true. The shell task calls “yum downgrade”. The
shell task co-exist with the normal yum task, side by side. Using conditionals,
these two tasks are made mutual exclusive, i.e., only one of the tasks gets
executed at any point in time. The effect is that either a downgrade or an
update of the RPM will be made (or nothing if the desired version is already
installed). The variable can be passed via the command-line like this:
The role can be included in a playbook or included as a dependency of another role. The code and usage examples are available here.
Update (14th Nov. 2018):
The feature has been available in Ansible since the version 2.4, provided via a
allow_downgrade. Setting this parameter to
True has the side effect
of making the
yum module behave in a non-idempotent way, according to the
The workaround described above has the same side effect.
The following is how I would use this feature:
By defaulting the parameter to
no, the feature is deactivated for a normal deployment. For a rollback, the feature can be activated by setting the
rollback parameter to