Sans
2011-Aug-18 11:49 UTC
[Puppet Users] how to create directory recursively (if parents not present)?
Dear all,
As said in the subject line, is there a "nice" way of creating
directory tree if parent is not already there, like using "mkdir -p"?
I tried this:
class install_certs {
$cert_dir = ''globus/cert''
exec {
''create_cert'':
command => "/bin/mkdir -p /opt/$cert_dir",
refreshonly => true,
}
file {
"${hostname}-cert.pem":
name => "/opt/$cert_dir/${hostname}-cert.pem",
mode => ''0444'', owner =>
''root'', group => ''root'',
source =>
"puppet:///modules/p_nodes/${hostname}-cert.pem";
}
}
which is not working at all. Any suggestion from anyone? 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.
Gary Larizza
2011-Aug-18 15:22 UTC
Re: [Puppet Users] how to create directory recursively (if parents not present)?
---------- Forwarded message ----------
From: Sans <r.santanu.das@gmail.com>
Date: Thu, Aug 18, 2011 at 4:49 AM
Subject: [Puppet Users] how to create directory recursively (if parents not
present)?
To: Puppet Users <puppet-users@googlegroups.com>
Dear all,
As said in the subject line, is there a "nice" way of creating
directory tree if parent is not already there, like using "mkdir -p"?
I tried this:
class install_certs {
$cert_dir = ''globus/cert''
exec {
''create_cert'':
command => "/bin/mkdir -p /opt/$cert_dir",
refreshonly => true,
}
file {
"${hostname}-cert.pem":
name => "/opt/$cert_dir/${hostname}-cert.pem",
mode => ''0444'', owner =>
''root'', group => ''root'',
source => "puppet:///modules/p_nodes/${hostname}-cert.pem";
}
}
which is not working at all. Any suggestion from anyone? 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.
The following will do what you want:
file { [''/opt'', ''/opt/globus'',
''/opt/globus/cert'']:
ensure => directory,
}
Because of the implicit dependencies that exist between directories and
their parents that are managed by puppet, you do not need to specify any
ordering - puppet will set it up for you.
You can write a defined resource type to do this for you if you''d like,
or
you can use the Ruby DSL to create a mkdir_p function.
--
Gary Larizza
Professional Services Engineer
Puppet Labs
Join us for PuppetConf <http://bit.ly/puppetconfsig>, September 22nd and
23rd in Portland, OR!
--
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.
Matthias Saou
2011-Aug-18 17:58 UTC
Re: [Puppet Users] how to create directory recursively (if parents not present)?
Sans wrote :> As said in the subject line, is there a "nice" way of creating > directory tree if parent is not already there, like using "mkdir -p"?This will do exactly what you want : $cert_dir = ''globus/cert'' exec { ''mkdir_cert_dir'': path => [ ''/bin'', ''/usr/bin'' ], command => "mkdir -p /opt/${cert_dir}", unless => "test -d /opt/${cert_dir}", } file { "/opt/${cert_dir}/${::hostname}-cert.pem": mode => ''0444'', owner => ''root'', group => ''root'', source => "puppet:///modules/p_nodes/${::hostname}-cert.pem"; require => Exec[''mkdir_cert_dir''], } HTH :-) Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 14 (Laughlin) - Linux kernel 2.6.35.13-91.fc14.x86_64 Load : 0.01 0.04 0.13 -- 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.
Matthias Saou
2011-Aug-18 18:04 UTC
Re: [Puppet Users] how to create directory recursively (if parents not present)?
Matthias Saou wrote :> file { "/opt/${cert_dir}/${::hostname}-cert.pem": > mode => ''0444'', owner => ''root'', group => ''root'', > source => "puppet:///modules/p_nodes/${::hostname}-cert.pem"; > require => Exec[''mkdir_cert_dir''], > }I just noticed that I copy/pasted your original "source" line, and it has an incorrect trailing semicolon. That needs to be a comma, of course. Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 14 (Laughlin) - Linux kernel 2.6.35.13-91.fc14.x86_64 Load : 0.07 0.06 0.09 -- 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.
Sans
2011-Aug-18 20:34 UTC
[Puppet Users] Re: how to create directory recursively (if parents not present)?
Thanks Matthias! I noticed the semicolon typo.
What does ${::hostname}-cert.pem implicate (as opposed to ${hostname}-
cert.pem)?
Cheers,
San
On Aug 18, 7:04 pm, Matthias Saou
<th...@spam.spam.spam.spam.spam.spam.spam.egg.and.spam.freshrpms.net>
wrote:> Matthias Saou wrote :
>
> > file { "/opt/${cert_dir}/${::hostname}-cert.pem":
> > mode => ''0444'', owner =>
''root'', group => ''root'',
> > source =>
"puppet:///modules/p_nodes/${::hostname}-cert.pem";
> > require => Exec[''mkdir_cert_dir''],
> > }
>
> I just noticed that I copy/pasted your original "source" line,
and it
> has an incorrect trailing semicolon. That needs to be a comma, of
> course.
>
> Matthias
>
> --
> Clean custom Red Hat Linux rpm packages :http://freshrpms.net/
> Fedora release 14 (Laughlin) - Linux kernel 2.6.35.13-91.fc14.x86_64
> Load : 0.07 0.06 0.09
--
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.
Sans
2011-Aug-18 20:40 UTC
[Puppet Users] Re: how to create directory recursively (if parents not present)?
Do I have to start from ''/opt'', as ''/opt'' already exists? Is Ruby DSL (use/how-to etc.) documented anywhere? Cheers, San On Aug 18, 4:22 pm, Gary Larizza <g...@puppetlabs.com> wrote:> ---------- Forwarded message ---------- > > The following will do what you want: > > file { [''/opt'', ''/opt/globus'', ''/opt/globus/cert'']: > ensure => directory, > } > > Because of the implicit dependencies that exist between directories and > their parents that are managed by puppet, you do not need to specify any > ordering - puppet will set it up for you. > > You can write a defined resource type to do this for you if you''d like, or > you can use the Ruby DSL to create a mkdir_p function. > > -- > > Gary Larizza > Professional Services Engineer > Puppet Labs > > Join us for PuppetConf <http://bit.ly/puppetconfsig>, September 22nd and > 23rd in Portland, OR!-- 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.
Matthias Saou
2011-Aug-21 11:57 UTC
Re: [Puppet Users] Re: how to create directory recursively (if parents not present)?
Sans <r.santanu.das@gmail.com> wrote:> Thanks Matthias! I noticed the semicolon typo. > What does ${::hostname}-cert.pem implicate (as opposed to ${hostname}- > cert.pem)?It just makes explicit that it''s a variable from the global scope (as it''s a fact) and not from the current local scope. Check out recent puppet docs related to the changes going into 2.7 and soon 2.8. Matthias -- 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.