Dear all, This is my script in the bash: how can I put it into puppet? #!/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 All I wann do is: Get the CPU_COUNT and then if CONF_DIR exists, make sure "$CONF_DIR/config" is present with the above lines. How should I write that for puppet? Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Uyz5hQSJX9AJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jun 10, 2011, at 4:10 PM, Sans wrote:> Dear all, > > This is my script in the bash: how can I put it into puppet? > > #!/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 > > All I wann do is: Get the CPU_COUNT and then if CONF_DIR exists, make sure "$CONF_DIR/config" is present with the above lines. How should I write that for puppet? Cheers!!I don''t have a lot of time, but I can get you started. Puppet way: 1) Create a File resource that creates the config directory. 2) Run "facter" at the command line and look for the name of the variable that tells how many processors the computer has. That variable will exist when the catalog is compiled as a variable. 3) Use a template with File to create your config file. Quicker way: (Not reccomended) 1) Copy that script to the computer using "File". 2) Run the script using Exec. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks kc! I probably didn''t myself clear. I don''t wanna create the "the config directory", in stead,* if it exists*, then make sure "config" file is present with those info. Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/FN4cuCrWX94J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Any suggestion from anyone else? Is there a way to check "if a directory (or file) already exists, then do something" in Puppet? Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Yes, Create a custom fact that checks for the existence of the directory. 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 On 13/06/11 7:21 PM, Sans wrote:> Any suggestion from anyone else? Is there a way to check "if a > directory (or file) already exists, then do something" in Puppet? > Cheers!! >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Darren Chamberlain
2011-Jun-13 16:49 UTC
Re: [Puppet Users] Re: how to do conditional check?
* Sans <r.santanu.das at gmail.com> [2011/06/13 02:21]:> Any suggestion from anyone else? Is there a way to check "if a > directory (or file) already exists, then do something" in Puppet? > 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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Mon, Jun 13, 2011 at 09:49, Darren Chamberlain <darren@boston.com> wrote:> * Sans <r.santanu.das at gmail.com> [2011/06/13 02:21]: > >> Any suggestion from anyone else? Is there a way to check "if a >> directory (or file) already exists, then do something" in Puppet? >> Cheers!!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 <daniel@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-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
After reading the other responses my question to you is what exactly are you attempting to do? -----Original Message----- From: puppet-users@googlegroups.com [mailto:puppet-users@googlegroups.com] On Behalf Of Sans Sent: Monday, June 13, 2011 5:22 AM To: Puppet Users Subject: [Puppet Users] Re: how to do conditional check? Any suggestion from anyone else? Is there a way to check "if a directory (or file) already exists, then do something" in Puppet? Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@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!! On Jun 13, 6:50 pm, "Matthew Black" <mjbl...@gmail.com> wrote:> After reading the other responses my question to you is what exactly are you > attempting to do?-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Sounds like what you want to do is to create a fact to find out that status of whether torque is installed or not. As for the configuration file, without better understanding the contents of the file, I would in conjunction with the fact do a file resource surrounded by an if statement that utilizes the fact. If its something that is pretty much the same across the board except for some values, like host names or what not, then you could use templates to create the file and keep it that way. so for example if $torque_installed == true { file { ''/var/torque/mom_priv/config'': ensure => present, content => template(...) } } On Mon, Jun 13, 2011 at 8:00 PM, Sans <r.santanu.das@gmail.com> wrote:> 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!! > > > > > On Jun 13, 6:50 pm, "Matthew Black" <mjbl...@gmail.com> wrote: > > After reading the other responses my question to you is what exactly are > you > > attempting to do? > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks Matthew! I think that way it''s better and simpler. But that makes me asking: How to check if Torque (or any package in question) is installed or not? Another question: How write the template file to multiply the no. of CPU-core by 1.2 (or whatever)? cheers!! On Jun 14, 4:28 am, Matthew Black <mjbl...@gmail.com> wrote:> Sounds like what you want to do is to create a fact to find out that status > of whether torque is installed or not. > > As for the configuration file, without better understanding the contents of > the file, I would in conjunction with the fact do a file resource surrounded > by an if statement that utilizes the fact. If its something that is pretty > much the same across the board except for some values, like host names or > what not, then you could use templates to create the file and keep it that > way. > > so for example > > if $torque_installed == true { > file { ''/var/torque/mom_priv/config'': > ensure => present, > content => template(...) > } > > > > > > > > } > On Mon, Jun 13, 2011 at 8:00 PM, Sans <r.santanu....@gmail.com> wrote: > > 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!! > > > On Jun 13, 6:50 pm, "Matthew Black" <mjbl...@gmail.com> wrote: > > > After reading the other responses my question to you is what exactly are > > you > > > attempting to do? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jun 13, 2011, at 5:00 PM, Sans wrote:> 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? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jun 14, 2:48 pm, Patrick <kc7...@gmail.com> wrote:> > 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?I can''t: "torque" is a vital part of the middleware, which needs to be installed and configured at the time of middleware installation. And n the other hand, I use Puppet to prepare the environment for the middleware to be installed (by yaim). After that installation (and initial configuration), I wanna make sure that "config" file is always there with correct values.> 2) Does is matter if you create the file if the package isn''t installed?As I explained above, if the I create the [especially] the directory- path, yaim will skip a things, thinking it''s an upgrade or re-install, even though installing for first time. Hope, I''ve made it a bit clearer now. Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
I haven’t used torque or yaim but what you want to do in a fact is something like this to determine installation. 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-users@googlegroups.com [mailto:puppet-users@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? On Jun 14, 2:48 pm, Patrick <kc7...@gmail.com> wrote:> > 1) Why not use puppet to decide if Torque should be installed in the firstplace? Then you can use that logic to decide if the file should be created/put in place? I can''t: "torque" is a vital part of the middleware, which needs to be installed and configured at the time of middleware installation. And n the other hand, I use Puppet to prepare the environment for the middleware to be installed (by yaim). After that installation (and initial configuration), I wanna make sure that "config" file is always there with correct values.> 2) Does is matter if you create the file if the package isn''t installed?As I explained above, if the I create the [especially] the directory- path, yaim will skip a things, thinking it''s an upgrade or re-install, even though installing for first time. Hope, I''ve made it a bit clearer now. Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jun 14, 6:12 pm, "Matthew Black" <mjbl...@gmail.com> wrote:> I haven’t used torque or yaim but what you want to do in a fact is something > like this to determine installation. > > if File.exists?(''/path/to/config'') >Does it work for directory as well? -San -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Not sure if it does, I''m going with the assumption it would not. Though there is a Dir.exists that you could use. -----Original Message----- From: puppet-users@googlegroups.com [mailto:puppet-users@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? On Jun 14, 6:12 pm, "Matthew Black" <mjbl...@gmail.com> wrote:> I haven’t used torque or yaim but what you want to do in a fact issomething> like this to determine installation. > > if File.exists?(''/path/to/config'') >Does it work for directory as well? -San -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Doesn''t look like there is a "Dir.exists" but "File.exists" appears to be working for directory as well. And there is a "File.directory", which works as well. Two ways of run a check for directories: if File.exists?(d_path) && File.directory?(d_path) or if File.directory?(d_path) One thing is: if the directory doesn''t exist, I se this error on the client: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template w_nodes/mom_priv-config.tpl: Could not find value for ''num_core'' at /etc/puppet/modules/w_nodes/manifests/ init.pp:42 on node myserv.ac.uk I do understand the meaning but is it normal? I thought if the above directory doesn''t exist, it''ll simple skip the rest. cheers!! On Jun 14, 8:59 pm, "Matthew Black" <mjbl...@gmail.com> wrote:> Not sure if it does, I''m going with the assumption it would not. > > Though there is a Dir.exists that you could use. > > -----Original Message----- > From: puppet-users@googlegroups.com [mailto:puppet-users@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? > > On Jun 14, 6:12 pm, "Matthew Black" <mjbl...@gmail.com> wrote: > > I haven’t used torque or yaim but what you want to do in a fact is > something > > like this to determine installation. > > > if File.exists?(''/path/to/config'') > > Does it work for directory as well? > > -San > > ---- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Have a look at has_variable? and test on that first then (see puppet template docs). On 15/06/2011, at 23:32, Sans <r.santanu.das@gmail.com> wrote:> Doesn''t look like there is a "Dir.exists" but "File.exists" appears to > be working for directory as well. And there is a "File.directory", > which works as well. > Two ways of run a check for directories: > > if File.exists?(d_path) && File.directory?(d_path) > or > if File.directory?(d_path) > > One thing is: if the directory doesn''t exist, I se this error on the > client: > > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Failed to parse template w_nodes/mom_priv-config.tpl: Could > not find value for ''num_core'' at /etc/puppet/modules/w_nodes/manifests/ > init.pp:42 on node myserv.ac.uk > > > I do understand the meaning but is it normal? I thought if the above > directory doesn''t exist, it''ll simple skip the rest. cheers!! > > > On Jun 14, 8:59 pm, "Matthew Black" <mjbl...@gmail.com> wrote: >> Not sure if it does, I''m going with the assumption it would not. >> >> Though there is a Dir.exists that you could use. >> >> -----Original Message----- >> From: puppet-users@googlegroups.com [mailto:puppet-users@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? >> >> On Jun 14, 6:12 pm, "Matthew Black" <mjbl...@gmail.com> wrote: >>> I haven’t used torque or yaim but what you want to do in a fact is >> something >>> like this to determine installation. >> >>> if File.exists?(''/path/to/config'') >> >> Does it work for directory as well? >> >> -San >> >> -- > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.