8

I am using an exec command to run a shell script which modifies certain configuration files of other packages. The exec command is triggered whenever input parameters such as ip addresses, ports or url change, or when the shell script itself has been changed.

I have to use a shell script because the configuration files of the software package differ slightly between releases. I think it is easier to update the configuration file per sed script instead of providing different puppet templates for each particular release.

But this configuration does not detect when any of the configuration files have been modified outside of puppet. Puppet does not know about the files which are been modified by the shell script.

What I am looking for is a way to make the exec command dependend on the checksums of arbitrary other files:

exec { "my_command.sh":
  only_if_file_has_changed => [ 
    "/etc/mysoftware/config.xml", 
    "/etc/othersoftware/defaults", 
  ]
}

Is this possible? Please advise.

3
  • Exactly what are you trying to do? There is probably a better way. Dec 25, 2014 at 13:49
  • I have updated the question with an explanation.
    – nn4l
    Dec 26, 2014 at 8:42
  • This is the problem that augeas solves. Dec 26, 2014 at 15:15

2 Answers 2

11

It would work like this:

exec { 'my_command.sh':
  command   => '/bin/my_command.sh',
  subscribe => [ 
    File['/etc/mysoftware/config.xml'], 
    File['/etc/othersoftware/defaults'], 
  ],
  refreshonly => true,
}

The obvious constraint here is, that the files /etc/mysoftware/config.xml and /etc/othersoftware/defaults must be changed via Puppet too.
If they are changed by something else (external to Puppet), see Felix' answer.
You can also subscribe to Package['xxx'] or any other more fitting dependency of course.

1
7

Puppet can solve this through its audit metaparameter.

file { [ "/etc/mysoftware/config.xml", 
         "/etc/othersoftware/defaults" ]:
    audit => 'content',
    notify => Exec['my_command'],
}
1
  • Server Error: Could not find resource 'Exec[...]' in parameter 'notify'
    – e-info128
    Oct 17, 2021 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .