Julia Smith
2012-Aug-14 12:05 UTC
[Puppet Users] Passing special characters to exec''s command - syntax help!!
Hi I want to use exec to create a recursive directory (I know I can use file but for another reason I don''t want to) So as a variable I get passed in $home and it may be for example /first/second/userdirectory where first and second may not exist. Puppet''s user wraps useradd so it won''t recursively create my directory so I want to use exec to create the directory /first/second before the user is created. If I allow puppet to recursively create /first/second/userdirectory in it''s entirety with file.....when the user is created it doesn''t contain the .bashrc and .profile files which I want. So I wanted to do a simple exec command which does the following if I were to do it at the command line: mkdir -p ${home%/*} ...this would make /first/second and I can allow useradd create the userdirectory. BUT....puppet doesn''t like me passing that to command. exec { "$home.create": path => ''/bin:/usr/bin'', command => "mkdir -p ''${home%/*}''", } I get Could not match %/*}\" Is this possible and if so what is the correct syntax? I''ve tried lots of options. Thanks in advance Julia -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -- 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.
earthgecko
2012-Aug-14 12:44 UTC
[Puppet Users] Re: Passing special characters to exec''s command - syntax help!!
There are a number of ways to achieve that. One would be to. file { [ ''/first'', ''/first/second'' ]: ensure => directory, owner => ''root'', group => ''root'', mode => ''0755'', before => User[''julia''], } user { ''juila'': ensure => present, gid => ''julia'', groups => [''users''], # uid => ''7000'', comment => ''This user was created by puppet'', require => File[''/first/second''], # managehome => true, } Now you can declare a require or before, you do not have to specify both, but if you do it will not break. As for the passing special characters. I will post something related now. -- 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/-/_V9RvUlzSgAJ. 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.
earthgecko
2012-Aug-14 12:54 UTC
[Puppet Users] Re: Passing special characters to exec''s command - syntax help!!
So as a variable I get passed in $home and it may be for example> /first/second/userdirectory where first and second may not exist. > > So I wanted to do a simple exec command which does the following if I were > to do it at the command line: > > mkdir -p ${home%/*} > > ...this would make /first/second and I can allow useradd create the > userdirectory. > > BUT....puppet doesn''t like me passing that to command. > > exec { "$home.create": > path => ''/bin:/usr/bin'', > command => "mkdir -p ''${home%/*}''", > } > > I get Could not match %/*}\" > > >So firstly in the context of command => "mkdir -p ''${home%/*}''", Puppet will try and look up variable: home%/* Because it is ${ and double quoted, so puppet is trying to compile the command as it is ${ in a double quoted string which puppet understands as a variable. I do not understand the context of the % percent and * wildcard references. But is $home was defined as ''/first/second'', then: command => "mkdir -p ${home}", As for passing special characters, different blends of variables and special characters should always be tested. Special characters should be passed via the exec command context if single quoted and no variables, not 100% certain, it always pays to test. -- 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/-/4QCHahZc-MYJ. 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.
Julia Smith
2012-Aug-14 13:18 UTC
Re: [Puppet Users] Re: Passing special characters to exec''s command - syntax help!!
Hi Thanks for your response. The first answer won''t work for me as I want to be dynamic about it and take in a variable of the full path so it could just as easily be 10 directories deep. I''m getting the value for home from a CLI rather than hand crafting something static. The significance of the %/* means take the variable''s value and right strip back to the last ''/'' character. So where I have /first/second/userdir passed in in the variable $home, I want to create only /first/second with the mkdir -p command. Julia On 14 August 2012 13:54, earthgecko <garypwilson@gmail.com> wrote:> > > So as a variable I get passed in $home and it may be for example >> /first/second/userdirectory where first and second may not exist. >> >> So I wanted to do a simple exec command which does the following if I >> were to do it at the command line: >> >> mkdir -p ${home%/*} >> >> ...this would make /first/second and I can allow useradd create the >> userdirectory. >> >> BUT....puppet doesn''t like me passing that to command. >> >> exec { "$home.create": >> path => ''/bin:/usr/bin'', >> command => "mkdir -p ''${home%/*}''", >> } >> >> I get Could not match %/*}\" >> >> >> > So firstly in the context of > > command => "mkdir -p ''${home%/*}''", > > Puppet will try and look up variable: > > home%/* > > Because it is ${ and double quoted, so puppet is trying to compile the > command as it is ${ in a double quoted string which puppet understands as a > variable. > > I do not understand the context of the % percent and * wildcard > references. But is $home was defined as ''/first/second'', then: > > command => "mkdir -p ${home}", > > As for passing special characters, different blends of variables and > special characters should always be tested. Special characters should be > passed via the exec command context if single quoted and no variables, not > 100% certain, it always pays to test. > > > -- > 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/-/4QCHahZc-MYJ. > > 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. >-- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -- 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.
earthgecko
2012-Aug-14 14:21 UTC
Re: [Puppet Users] Re: Passing special characters to exec''s command - syntax help!!
OK then. command => "mkdir -p $(dirname ${home})", That does it. -- 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/-/1LLoBIiTMZ4J. 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.