On Mon, Apr 25, 2011 at 10:05 AM, linuxbsdfreak <[email protected]> wrote:
> Hi All,
>
>
> I am writing some puppet manifests to manage some deployments. I have
> created a define which takes some parameters and i am providing the
> input with variables in the site.pp file. I am managing 3 different
> environments like testing, staging and production and have tagged the
> servers as tst_env, stg_env and prd_env for doing some customization.
> However i have some common stuff to do in tst_env and stg_env
> evironments, but i have to create 3 different if conditions, something
> like this
>
> if tagged(tst_env)
> {
> do somethng...
> }
>
> if tagged(stg_env)
> {
> do somethng...
> }
>
> if tagged(prd_env)
> {
> do somethng...
> }
>
> I would like to combine the tst_env and stg_env by using somethng like
> a OR condition. Howerver the following below doesnt work.
>
> if tagged(tst_env|stg_env)
>
> Any ideas how do i apply the same code to 2 environments without
> creating an additional if statement.
tagged doesn't support regular expression, it appears to support an
array but it's requiring all tags in the array to exist. You should be
able to do this instead:
if tagged('test_env') or tagged('stg_env')
> - I have 2nd query with arrays and variables
>
> I am invoking a define by providing an array with some software
> packages to be installed.
>
> Eg:
>
> definename::install{
> [ ''package1'',
> ''package2'',
> ''package3''
> ]:
> othervariabes ...
> }
>
> Within the define i am using the $name to parse the array and do the
> stuff.
>
> Is there a possibility that i can assign that array to a variable
> before the define and use it later. It works with normal variables,
> However the following below doesnt work:
>
> Eg:
>
> $pkglist = [ ''package1'',
> ''package2'',
> ''package3''
> ]:
>
> define name::install{
> $pkglist
> othervariabes ...
> }
Try using the fully qualified namespace to access the variable
(something like path to staging directory), so
class a::param {
$pkglist = ...
}
define ... {
notice($a::param::pkglist)
}
or pass it as a parameter if it changes per resource declaration.
> - Can i also use if conditions while invoking defines?
Yes, the only thing that confuses new user, is you can't use if & case
statements in a resource declaration.
type { 'title':
# can't have if or case statement within resource.
# only selector
attribute => $var ? {
...
}
}
if ... {
# declare resources.
type { "title":
...
}
}
Thanks,
Nan
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.