Hi,
Thanks for your reply. The problem with the tagging is solved. However
i am confused with the 2nd part. I actually want to do somethng like
this to delete files:
I am creating a class called config_variables in which i want to have
an array of dirs of files to delete:
class config_variables {
$oldfilestoremove = [ "file1", "file2" ]
$path_to_data = "/tmp"
$path_to_data2 = "/opt"
}
Then i want to declare another class according to different
environments. However i would like to do some sort of if condition
with the path variable and change it according to different
environments using the tags. The purge-data is a general define i have
and has a delete function which uses the $name variable and the path
variable defined below as parameters:
class purge_old_data inherits config_variables {
purge-data::delete{
$oldfilestoremove
if tagged(tst_env) or if tagged(stg_env)
{
path => "$path_to_data",
}
if tagged(prd_env)
{
path => "$path_to_data2",
}
}
}
The above code doesnt work. I want to declare stuff in
config_variables section both arrays and variables and then call it
later.
Any help regarding this is appreciated.
Regards,
Kevin
On Apr 25, 8:21 pm, Nan Liu <[email protected]> wrote:
> 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.