FAQ
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.

Search Discussions

  • Earthgecko at Aug 14, 2012 at 12:44 pm
    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 at Aug 14, 2012 at 12:54 pm
    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 at Aug 14, 2012 at 1:19 pm
    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 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 at Aug 14, 2012 at 2:21 pm
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedAug 14, '12 at 12:05p
activeAug 14, '12 at 2:21p
posts5
users2
websitepuppetlabs.com

2 users in discussion

Earthgecko: 3 posts Julia Smith: 2 posts

People

Translate

site design / logo © 2022 Grokbase