Equivalent of Require, but slightly different

19 views
Skip to first unread message

Ugo Bellavance

unread,
May 15, 2017, 9:28:49 PM5/15/17
to Puppet Users
Hi,

I'm working on a public puppet module and while I've done a lot of improvements up to now (especially considering my puppet capabilities), there is still a lot of work to do and I'd need some help for my next step.  My repo is https://github.com/ubellavance/ZendServerPuppet and my next target is to make sure that an application action is not done before the bootstrap is complete.  Explanations: the module performs a "bootstrap" process at the first puppet run (just after installing the packages).  If I set an application action (define, for example) before the bootstrap process is complete (which would obviously happen), there is an error with obscure error messages provided by the Zend Server API, which isn't really user-friendly and it causes a failure of the puppet run.  There is a fact that is set to true if the bootstrap is complete: $::zend_gui_completed.  I tried doing a conditional statement using this variable but I don't know how to just do nothing for the application action and just output a message (notify) saying that the application actions will be applied after the bootstrap. It is a bit tricky because before the bootstrap it doesn't exist, so it is undefined, and once the bootstrap is complete, it equals to true.

I tried this, in application.pp, but it looks like the if doesn't work because the notify occurs every time

  if $::zend_gui_completed != true {

    notify {"zend_gui_completed = $::zend_gui_completed. Bootstrap must run first. Application settings will be applied after Bootstrap is done": }

  }


Here's the output:


Notice: /Stage[main]/Main/Node[default]/Zendserver::Application[patate]/Notify[zend_gui_completed = true. Bootstrap must run first. Application settings will be applied after Bootstrap is done]/message: defined 'message' as 'zend_gui_completed = true. Bootstrap must run first. Application settings will be applied after Bootstrap is done'


Could someone help me figure out how to make the if work, and, even more important, if there is a way to "bypass" the zendserver::application blocks if zend_gui_completed is not true?


Here's my application::define:


  zendserver::application { 'patate':

    ensure   => 'define',

    base_url => "http://patate.com",

    version  => "2",

    logo     => "/usr/share/pixmaps/poweredby.png"

    }


Please let me know if you need more information.  


Thanks,

Garrett Honeycutt

unread,
May 15, 2017, 10:10:18 PM5/15/17
to puppet...@googlegroups.com
On 5/15/17 9:28 PM, Ugo Bellavance wrote:
> Hi,
>
> I'm working on a public puppet module and while I've done a lot of
> improvements up to now (especially considering my puppet capabilities),
> there is still a lot of work to do and I'd need some help for my next
> step. My repo is https://github.com/ubellavance/ZendServerPuppet and my
> next target is to make sure that an application action is not done
> before the bootstrap is complete. Explanations: the module performs a
> "bootstrap" process at the first puppet run (just after installing the
> packages). If I set an application action (define, for example) before
> the bootstrap process is complete (which would obviously happen), there
> is an error with obscure error messages provided by the Zend Server API,
> which isn't really user-friendly and it causes a failure of the puppet
> run. There is a fact that is set to true if the bootstrap is complete:
> $::zend_gui_completed. I tried doing a conditional statement using this
> variable but I don't know how to just do nothing for the application
> action and just output a message (notify) saying that the application
> actions will be applied after the bootstrap. It is a bit tricky because
> before the bootstrap it doesn't exist, so it is undefined, and once the
> bootstrap is complete, it equals to true.
>
> I tried this, in application.pp, but it looks like the if doesn't work
> because the notify occurs every time
>
> if $::zend_gui_completed != true {____
>
> notify {"zend_gui_completed = $::zend_gui_completed. Bootstrap must
> run first. Application settings will be applied after Bootstrap is
> done": }____
>
> }
>
>
> Here's the output:
>
>
> Notice:
> /Stage[main]/Main/Node[default]/Zendserver::Application[patate]/Notify[zend_gui_completed
> = true. Bootstrap must run first. Application settings will be applied
> after Bootstrap is done]/message: defined 'message' as
> 'zend_gui_completed = true. Bootstrap must run first. Application
> settings will be applied after Bootstrap is done'
>
>
> Could someone help me figure out how to make the if work, and, even more
> important, if there is a way to "bypass" the zendserver::application
> blocks if zend_gui_completedis not true?
>
>
> Here's my application::define:
>
>
> zendserver::application { 'patate':____
>
> ensure => 'define',____
>
> base_url => "http://patate.com <http://patate.com/>",____
>
> version => "2",____
>
> logo => "/usr/share/pixmaps/poweredby.png"____
>
> }
>
>
> Please let me know if you need more information.
>
>
> Thanks,

Hi,

Your comparison of $::zend_gui_completed is never boolean true, so the
notify always happens. Perhaps your fact is returning a string and not a
boolean. Put this in your code just above the conditional statement.

$zgc_type = inline_template('<%= @zend_gui_completed.class %>')
notify { "zend_gui_completed is type ${zgc_type}": }

If it is a string, check out str2bool() from stdlib[1].

[1] - https://github.com/puppetlabs/puppetlabs-stdlib#str2bool

Best regards,
-g



--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

Ugo Bellavance

unread,
May 15, 2017, 10:26:07 PM5/15/17
to Puppet Users
Hi,

Your comparison of $::zend_gui_completed is never boolean true, so the
notify always happens. Perhaps your fact is returning a string and not a
boolean. Put this in your code just above the conditional statement.

$zgc_type = inline_template('<%= @zend_gui_completed.class %>')
notify { "zend_gui_completed is type ${zgc_type}": }

If it is a string, check out str2bool() from stdlib[1].

[1] - https://github.com/puppetlabs/puppetlabs-stdlib#str2bool

First thanks for your complete and super quick reply.

I understand why it doesn't work now.  I'll try that tomorrow. And would you have any hints for me regarding my 2nd question?  How can I skip the execution of a section (class?) if this variable is not true?

Thanks,
Reply all
Reply to author
Forward
0 new messages