Reputation: 18427
How would you use puppet to change the permissions of a file which does not have a consistent name?
My task is to manage a binary that has the date appended to the end of it like so:
lrwxrwxrwx 1 root root 18 Oct 25 18:46 apbridge -> ./apbridge20131025
lrwxrwxrwx 1 root root 18 Oct 25 18:46 apbridge1025 -> ./apbridge20131025
-rwxr-xr-x 1 root root 2914 Oct 25 18:46 apbridge20131025
apbridge20131025 has the wrong permissions. Normally the following would change it:
file {'/root/alpsSim/alps_simulator_r7537/tester/apbridge20131025':
owner => 'root',
group => 'root',
ensure => file,
mode => '0755',
}
However because I can not predict what numbers apbridge will end in, this will be very likely to break.
I don't have control over the name of apbridgexxxxx as it is installed by a 3rd party script. The numbers at the end represent the day it was installed.
Is there a way to use a wildcard in a puppet file resource declaration?
Upvotes: 3
Views: 5669
Reputation: 2781
Normally I would recommend against using exec
in Puppet in general, but in this case, chmod
is idempotent - you will get the same results however you run it. There's also the slight benefit of Puppet not having to calculate a md5 hash for each file that it tries to change the permission for.
That said, a more elegant way to ensure permissions would be to set them on the directory containing the files recursively - assuming only the apbridge*
files are present.
file {'/root/alpsSim/alps_simulator_r7537/tester':
owner => 'root',
group => 'root',
ensure => directory,
recurse => true,
mode => '0755',
}
Upvotes: 1
Reputation: 2634
I suggest you make use of exec:
exec { 'apbridge':
command => 'find /root/alpsSim/alps_simulator_r7537/tester/ -maxdepth 1 -type f -iname "apbridge*" -exec chmod 755 {} \;',
path => '/bin:/sbin:/usr/bin:/usr/sbin',
}
Upvotes: 3