CentOS and Fedora both use yum as their package manager. This gives you the benefit of using RPMs which come with options built in for actions such as pre and post package installation hooks. But what if you want to trigger actions on any package or a certain type of package regardless of the RPM ? What if you want yum after every package install, to run a script or command ? If you are also using RPMs not under your control, you don't want to be tearing apart those RPMs either to add your own functionality. Some RPMs when they install have also post actions configured and these can cause issues if your server is dealing with compliance or just general state consistency.

This is when you need the yum-plugin-post-transaction-actions plugin. This plugin adds the ability for you to execute scripts and commands after a certain yum action and also trigger only when certain packages are touched, or all packages. In this example we will configure a post action to run a script after every time yum install <package> is run. The use case of this example is in a situation of compliance when the state of the server needs to be checked for any issues that may have been caused by the installed package. The installed package we can assume could be anything from an upgrade to a dev debugging tool.

Install The Plugin

Install the plugin with the following command:

sudo yum -y install yum-plugin-post-transaction-actions  

This will install the yum-plugin-post-transaction-actions plugin and configure its default configuration. Within the /etc/yum/pluginconf.d/post-transaction-actions.conf file the following will have been automatically configured with the install:

enabled = 1  
actiondir = /etc/yum/post-actions/  

This simply specifies whether the plugin is to be enabled and the location of our post-action scripts. Post-action scripts are the configuration files telling the plugin what to look for when a yum action occurs and what script or command to execute when it finds a match.

Configure A Post-Action Every Time Yum Install Is Called

Within the /etc/yum/post-actions/ folder create a file named install.actions and add the following:

*:install:sh /tmp/

The above configuration can be interpreted as follows:


The above configuration specifies to match any application (*) during a yum install call (install) and then to execute with shell the script /tmp/ (sh /tmp/ Now we simply fill in /tmp/ with our shell script to automate the process we want. This note is not limited to just shell. As we could alternatively make this a python script and execute as such with the following post actions configuration in the install.actions file as follows:

*:install:python /tmp/

Note that in this case we have a python script instead of a shell script being called

For more examples of configurations see the sources for this post. Specifically the fedora documentation explains more variables that can be used for more dynamic configuration within .actions configurations files and other configurations for tailoring specifically to certain yum actions or certain applications only