Cool thx Den, undef worked like a charm.

much appriciated!

On 2 May 2012 01:24, denmat <tu2bg...@gmail.com> wrote:

> Hi Peter,
>
> take a look at this:
>
> class testme {
>    define vhost ($servername = "${hostname}.${domain}", $serveralias =
> [ "www.${hostname}.${domain}" ], $inorout = "1", $owner = "root",
> $group = "root", $enabled = "link", $rewrite = "", $ssl = "false",
> $cacert = "", $certchain = "", $certfile = "", $keyfile = "", $pringo
> = "false", $pringodir = "pringo4", $staging = "false", $mode = '755',
> $monstring = undef ) {
>
>  if $monstring {
>   file{"/root/test_${servername}.cfg":
>                        ensure          => present,
>                        content         =>
> "${servername}_defacementmon.erb",
>                }
>  }
> }
> }
>
>
> class runme {
>  include testme
>       testme::vhost{'blog.domain.com':
>                 servername              => 'blog.domain.com',
>                serveralias             => [ 'prod-blog.domain.com' ],
>                enabled                 => 'link',
>                 monstring               => 'string',
>                inorout                 => '0',
>        }
>
>        testme::vhost{'blog1.domain.com':
>                 servername              => 'blog1.domain.com',
>                serveralias             => [ 'prod-blog1.domain.com' ],
>                enabled                 => 'link',
>                 inorout                 => '0',
>        }
>
> }
>
> include runme
>
> Now the monstring, if it is not declared remains 'undef'.  We now just
> test on the existence of monstring. If it is declared it you create
> the file, if not the file is not created.
>
> In my quick testing it appeared to work, but may not be exactly
> suitable for your env.
>
> That help?
> Den
>
> On Wed, May 2, 2012 at 1:03 AM, Peter Horvath <peter.horvat...@gmail.com>
> wrote:
> > Hey Den, thanks for the answer
> >
> > I changed the import to include it was just a leftover when for some
> reason
> > include wasnt good enough to be able to use defined resource types with
> some
> > older version.
> >
> > This false solution isnt working sadly still that monstring get evaluated
> > with the default value and never with the later defined value.
> >
> >
> > On 1 May 2012 14:58, Denmat <tu2bg...@gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> can't see anything wrong off the top of my head except you use an import
> >> statement instead of an include.
> >>
> http://docs.puppetlabs.com/guides/language_guide.html#importing-manifests
> >>
> >> Have you tried testing for a string like 'false'? Just to see if
> something
> >> odd not going on.
> >>
> >> >>  $mode = '755', $monstring = 'false' )
> >>
> >>
> >>
> >> >> if ! $monstring == "false" {
> >>
> >>  file{"/root/${servername}.cfg":
> >>
> >> Not at a computer so can't test the code till tomorrow (that's about 8
> >> hours away).
> >>
> >> Sorry,
> >> Den
> >>
> >>
> >> On 01/05/2012, at 22:24, Peter Horvath <peter.horvat...@gmail.com>
> wrote:
> >>
> >> > Anybody got any idea on this?
> >> > I am really stuck with this one.
> >> >
> >> > On Apr 30, 4:51 pm, Peter Horvath <peter.horvat...@googlemail.com>
> >> > wrote:
> >> >> Hi,
> >> >>
> >> >> I have a modul which created the vhosts and based on the variables
> >> >> defined
> >> >> there i am creating nagios defacement host cfg.
> >> >> My problem is that I can't conditionally decide if the file should be
> >> >> created, based on the variable which will get content in the node
> >> >> config:
> >> >> When the condition get evaluated $monstring still empty since it gets
> >> >> its
> >> >> content in the node config later, so no file will be created.
> >> >> If i remove the condition there will be hundreds of nagios cfg which
> >> >> should
> >> >> not be created.
> >> >> Can you give me some idea how can i make this work, so blog file gets
> >> >> created and blog1 not.
> >> >>
> >> >> *This is the important part of my resource type*
> >> >> *
> >> >> *
> >> >> define vhost ($servername = "${hostname}.${domain}", $serveralias = [
> >> >> "www.${hostname}.${domain}" ], $inorout = "1", $owner = "root",
> $group
> >> >> =
> >> >> "root", $enabled = "link", $rewrite = "", $ssl = "false", $cacert =
> "",
> >> >> $certchain = "", $certfile = "", $keyfile = "", $pringo = "false",
> >> >> $pringodir = "pringo4", $staging = "false", $mode = '755',
> $monstring =
> >> >> '' )
> >> >>
> >> >> if ! $monstring == "" {
> >> >>  file{"/root/${servername}.cfg":
> >> >>                         ensure          => present,
> >> >>                         content         =>
> >> >> template("${module_name}/defacementmon.erb"),
> >> >>                 }
> >> >>
> >> >> }
> >> >>
> >> >> *node config:*
> >> >>
> >> >> import "apache2/vhost.pp"
> >> >>
> >> >>         vhost{'blog.domain.com':
> >> >>                 servername              => 'blog.domain.com',
> >> >>                 serveralias             => [ 'prod-blog.domain.com'
> ],
> >> >>                 enabled                 => 'link',
> >> >>                 require                 => Mount['/var/www'],
> >> >>                 monstring               => 'string',
> >> >>                 inorout                 => '0';
> >> >>         }
> >> >>
> >> >> vhost{'blog1.domain.com':
> >> >>                 servername              => 'blog1.domain.com',
> >> >>                 serveralias             => [ 'prod-blog1.domain.com'
> ],
> >> >>                 enabled                 => 'link',
> >> >>                 require                 => Mount['/var/www'],
> >> >>                 inorout                 => '0';
> >> >>         }
> >> >>
> >> >> I hope it is understandable, my english is not the best.
> >> >> Peter
> >> >
> >> > --
> >> > 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+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/puppet-users?hl=en.
> >> >
> >>
> >> --
> >> 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+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/puppet-users?hl=en.
> >>
> >
> > --
> > 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+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/puppet-users?hl=en.
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to