On Thursday, April 4, 2013 9:52:08 AM UTC-5, wrd4wrd wrote:
>
> Hi,
>
> I am trying to write a manifest that iterates through an array to create
> and maintain application users.
> The list of users is passed to the manifest from init.pp in the following
> fashion:
>
> *$app_users = [ at1,et1,at2,et2 ]*
>
> The users.pp manifest then reads the array to create the users:
>
> * define appuser {
> user { $name:
> ensure => 'present',
> comment => "Application User - $name",
> gid => 'app',
> home => "/apps/$app/$name",
> shell => '/usr/bin/bash',
> }
> }
>
> appuser { $app_users: }
> *
> This solution worked very well with another module I wrote, but in this
> case the home directory path includes a variable, that depends on the user
> name.
>
> Adding the following if statement inside the resource issues an error:
>
> * if $name =~ /^(et|ep)/ {
> $app = "echos"
> notice('app is $app')
> }*
>
> *Syntax error at 'if'; expected '}' at .../users.pp:9 *
>
> I read somewhere that you cannot place an if statement inside a resource,
> and in that case, what are my options?
> We're using puppet master version 2.7.19 (Puppet Enterprise 2.7.0).
>
>
You cannot put an 'if' statement inside a resource *declaration*. In your
example, that would be the block
user { $name: ... }
The contents of a resource declaration can only bind parameter values to an
instance of the specified resource type; it consists of the title and a
series of key / value pairs. The parameter values can be expressions,
including more complicated ones than the string interpolation in your
example. In particular, they can be selector expressions, which is one way
to assign parameter values conditionally.
You certainly can use 'if' statements and any other valid Puppet DSL code
in the body of a defined type *definition*, however. You did not give a
complete example of the failing code, so I have to speculate about what may
be wrong. The 'if' statement itself looks syntactically correct, however,
so it is probably the placement. Put it between "define appuser {" and "user
{ $name: ", and you should be fine.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.