Ask Your Question

How to run a command with every puppet run

asked 2016-01-05 10:18:34 -0500

dzolnai gravatar image

I need to regenerate a config file from data available on the puppet master with every run. What I want is that my exec {...} command would be executed on each puppet run. I've been trying something like this:

exec { 'delete-old-config':
    command => 'rm -f /etc/haproxy/haproxy.cfg',
    path    => '/usr/bin/',
    require => Package['haproxy'],
    notify  => File['/etc/haproxy/haproxy.cfg'],
    onlyif => 'test -d /nonexistent/file'

So because of the onlyif fails every time, it would run every time. But this just runs once too (which I understand). I've been looking into the documentations, but couldn't find a way or parameter which would result in what I want.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-05 17:11:20 -0500

GregLarkin gravatar image

Do you mind me asking why you need to regenerate the file on every Puppet run? What does your /etc/haproxy/haproxy.cfg file resource look like? Is there a way to generate it from a template and only do so when it's necessary instead of every run?

edit flag offensive delete link more


The servers HAProxy is proxying to are in a hostgroup. I can query the IP of the machines on the puppet master, and regenerate the configuration each run.

dzolnai gravatar imagedzolnai ( 2016-01-06 03:35:40 -0500 )edit

In this link you can find an example configuration, under the section Test the Load Balancer: Yes I can generate it from a template. I could generate it only when it is necessary, but then I would have to detect the changes between each run

dzolnai gravatar imagedzolnai ( 2016-01-06 03:37:04 -0500 )edit

Are you aware of the HAProxy Puppet Forge module? This module gives the ability to register your proxied servers, and it takes care of all of the configuration for you. It might be much easier and "Puppet-like" to use this module for your configuration

GregLarkin gravatar imageGregLarkin ( 2016-01-06 11:38:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-01-05 10:18:34 -0500

Seen: 196 times

Last updated: Jan 05 '16