Yum Pending Transaction

I need to clean yum pending or unfinished transactions before our installer start to work, otherwise the yum update or yum install may fail. But where are these pending transactions from? Sometimes the machine is down or unexpected thing happens, the yum installation process failed.

Problem

you may see error like this:

1
2
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.

Solution

According to the prompt, we need first install yum-utils

1
yum install -y yum-utils

yum-complete-transaction is a program which finds incomplete or aborted yum transactions on a system and attempts to complete them. It looks at the transaction-all* and transaction-done* files which can normally be found in /var/lib/yum if a yum transaction aborted in the middle of execution.

If it finds more than one unfinished transaction it will attempt to complete the most recent one first. You can run it more than once to clean up all unfinished transactions.

Then just issue the following command to do a cleanup:

1
yum-complete-transaction --cleanup-only

You can also check how many pending transactions exist:

1
find /var/lib/yum -maxdepth 1 -type f -name 'transaction-all*' -not -name '*disabled' -printf . | wc -c

In Ansible playbookk add task:

1
2
3
4
5
6
# ensure existence of yum-utils first
- name: clean yum pending transactions
command: yum-complete-transaction --cleanup-only
become: true
args:
warn: no
0%