I want to add a file with puppet that should only exist while puppet runs.
The file should be there to prevent apt from starting any services (which fails) during my puppet run.
This is the class I have so far that doesn't work since there is a duplicate declaration of the same file:
# Opensips package install
class opensips::package {
case $::osfamily {
'Debian' : {
file { 'opensips-enable-apt-policy':
ensure => 'present',
path => '/usr/sbin/policy-rc.d',
mode => '0755',
content => "#!/bin/sh
echo \"All runlevel operations denied by puppet module ${module_name}\" >&2
exit 101
",
} ->
package { $opensips::opensips_debs: ensure => $opensips::package_ensure, } ->
file { 'opensips-disable-apt-policy':
ensure => 'absent',
path => '/usr/sbin/policy-rc.d',
}
}
default : {
fail("Unsupported OS: ${::osfamily}")
}
}
}
This should give an idea of the desired end-state, but to sum it up:
- Create the file
/usr/sbin/policy-rc.d
with the content above - Run the package install
- Remove the file
How would I do this the best/easiest way?
The agent is Debian Jessie and runs puppet version 3.8.1
I have tried to put the alias
metaparameter on the file declaration success.
Unfortunately this is not how Puppet is designed to work - Puppet will enforce a known system state, rather than being an interactively running script.
One way of doing what you want is to use
exec
resources to add/remove the file, and using a locally-deployed 'source'.Example (not complete, may not work):