#!/usr/bin/env bash
CONF_DIR="/var/mom_priv"
CPU_COUNT=`cat /proc/cpuinfo | grep siblings | uniq | cut -d\ -f2`
ideal_load_var=$(echo "scale=2; ${CPU_COUNT}+0.5" | bc)
max_load_var=$(echo "scale=2; ${CPU_COUNT}*1.2" | bc)
if [ -d "${CONF_DIR}" ]; then
cat << EOF > ${CONF_DIR}/config
\$ideal_load ${ideal_load_var}
\$max_load ${max_load_var}
EOF
fi
I have one that is as simple as ...
Facter.add("apde_available") do
setcode do
if File::directory?("/usr/local/APDE")
"true"
else
"false"
end
end
end
then in my manifest ...
if ($apde_available =~ /true/) {
...
}
Cheers
I use this pattern:
$_exists = inline_template("<%= File.exists?('$f') %>")
case $_exists {
"true": { ... }
"false": { ... }
}
I probably use it too much, in fact, but writing a custom fact for
every file I need to check becomes tedious and hard to maintain (we
do this in quite a few places).
For things like this, irb and inline_template are your friends.
--
It's not what you look at that matters, it's what you see.
-- Henry David Thoreau
This isn't a suggestion you will like, but: if it hurts when you do
that, don't do it™.
That sort of conditional action is the opposite of how Puppet is
designed to work. You can hack around it with custom facts, but you
are going to fight with the tool the whole time.
The "right" way to do this is that you include a class on all the
machines that *should* have that configuration directory, and file,
present. Inside the class, create the directory, put the config file
in place, and go from there. Puppet talks about the *desired* state
of the system, not the set of actions to take based on the current
state.
> I use this pattern:
>
> $_exists = inline_template("<%= File.exists?('$f') %>")
So, er, templates (including inline_template) run on the *master*
machine. Your example will test if the file exists on the master for
every client catalog compiled – so, in almost all cases, won't work.
The catalog is *static* when it hits the client.
You really need to use a custom fact to do this: only facts contain
information and context about the client machine you are compiling
for, not anything you evaluate on the server, templates included.
> I probably use it too much, in fact, but writing a custom fact for
> every file I need to check becomes tedious and hard to maintain (we
> do this in quite a few places).
It does have the advantage that it would work, though, where this
pattern totally *can't*. :)
Regards,
Daniel
--
⎋ Puppet Labs Developer – http://puppetlabs.com
✉ Daniel Pittman <dan...@puppetlabs.com>
✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775
♲ Made with 100 percent post-consumer electrons
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
--
> Well, the file I mention is actually one of the Torque (formerly PBS
> batch system) "config" file (location: /var/torque/mom_priv/config),
> which is auto generated by "yaim" but the thing is: if the file is
> already there "yaim" won't touch it. Let's just say that I don't want
> yaim to create this file (it messes it up very often and ended up with
> wrong value) but wanna make sure that the file is in correct shape,
> otherwise jobs won't run properly. On the other hand, that file
> doesn't mean anything at all, if Torque is not install in the first
> place. That's why I want to put that check in. Cheers!!
>
1) Why not use puppet to decide if Torque should be installed in the first place? Then you can use that logic to decide if the file should be created/put in place?
2) Does is matter if you create the file if the package isn't installed?
if File.exists?('/path/to/config')
end
I don’t usually install anything on a system without doing it in puppet, so
I don’t typically write facts to find out if something is installed or not.
-----Original Message-----
From: puppet...@googlegroups.com [mailto:puppet...@googlegroups.com]
On Behalf Of Sans
Sent: Tuesday, June 14, 2011 10:01 AM
To: Puppet Users
Subject: [Puppet Users] Re: how to do conditional check?
--
Though there is a Dir.exists that you could use.
-----Original Message-----
From: puppet...@googlegroups.com [mailto:puppet...@googlegroups.com]
On Behalf Of Sans
Sent: Tuesday, June 14, 2011 1:54 PM
To: Puppet Users
Subject: [Puppet Users] Re: how to do conditional check?
-San
--