Modifying RPM configuration after installation

As part of my Ansible playbook I down and install an RPM from an internal repository. This RPM comes packaged with a bunch of configuration. For most of my machines I don’t need to change this configuration. However for a small subset, defined by an ansible group, I need to modify a few of the configuration fields.

I’m assuming I would need to do something like so:

  1. Wait till my RPM is installed and “running”

  2. Stop the service

  3. Modify the configuration file somehow? Use a when clause to limit it to the group I want to modify.

  4. Restart the service

Or possibly there is a better way to achieve to do this. Can anyone out there suggest how I could achieve my general goal?

1. RPM shouldn't start the service, ever. DEB packages usually do start them, but rpm has different policies and in any way, starting service immediately upon installation from packages is imho a bad practice.

So my first advice would be - don't start the service from RPM, start it from Ansible.

So, your playbook should look like:

- install package
- modify config file(s)
- start service(s)

To modify files only on a subset of servers, you can opt for two approaches:

1. deploy jinja2 templates to all servers, and address difs for subset through variables

2. deploy static files (or templates - doesn't matter) when some specific variable is set in your group.

I would prefer the 1st approach, but that really depends on the format of your config files and type of changes you need to make... Devil is in the details.

Thanks Jakov.

That worked well for me. It turns out my service was running because my init replacement, runit, automatically starts the service by default. Once I switched this off and leveraged the templates, this became easy.

Cheers,

JD