[Puppet Users] Re: Cannot set variables via Hiera for a module I've written

2014-09-28 Thread Danny Roberts

>
>
> It sounds like you have a misconception.  By recording the specified data 
> in Hiera, you provide a value to bind to class ::zabbix's parameter 
> $::zabbix::client_server.  If you declare class ::zabbix without specifying 
> a value for that parameter (e.g.
>
> include '::zabbix'
>
> or
>
> class { '::zabbix': }
>
> ) then $::zabbix::client_server will take the Hiera value.  If there were 
> no such value available from Hiera then $::zabbix::client_server would take 
> its default value instead ($::zabbix::params::client_server).  *In no 
> event is the value of class variable $::zabbix::params::client_server ever 
> different from the one with which it is initialized in the body of class 
> ::zabbix::params.*
>
>
> It was a scope issue like you suggested, the code works with some 
significant re-jigging, many thanks! 

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/426ed2f3-ffce-4052-8607-bfe2cf6529b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: Cannot set variables via Hiera for a module I've written

2014-09-25 Thread jcbollinger


On Wednesday, September 24, 2014 9:26:30 AM UTC-5, Danny Roberts wrote:
>
>
>
> On Wednesday, 24 September 2014 14:08:30 UTC+1, jcbollinger wrote:
>>
>>
>>
>> On Wednesday, September 24, 2014 5:57:45 AM UTC-5, Danny Roberts wrote:
>>>
>>> Hi Folks,
>>>
>>> I've started writing a module for zabbix monitoring (current version 
>>> here: https://github.com/kemra102/puppet-zabbix).
>>>
>>> I have a basic set-up to install the zabbix client using the module.
>>>
>>> There are some values I need to change for our environment so that the 
>>> config works, in my case I'm trying to set the $zabbix::client_server 
>>> variable via Hiera so it can be populated via template for the zabbix 
>>> client.
>>>
>>> Currently I have this in *common.yaml*:
>>>
>>> zabbix::client_server: '10.0.0.1'
>>>
>>> As far as I know this should work fine and matches the Puppetlabs NTP 
>>> module way of doing it (in this module we define our own NTP servers in 
>>> Hiera to override the defaults just fine).
>>>
>>> However it doesn't seem to be getting set as one of the error checks I 
>>> have in place is being triggered due to this value being missing.
>>>
>>
>>
>> Are you talking about these checks:
>>
>> class zabbix::client::service inherits zabbix::params {  
>>   if ($client_startagents != '0' and $client_server == '') {  fail("Your 
>> StartAgents cannot be greater than 0 or null when Server is also null. Set 
>> StartAgents to 0 or set Server.")  }  if ($client_server == '' and 
>> $client_serveractive == '') {  fail("You must set either passvie or 
>> active (or both) checks via the Server or ServerActive options.")  }  
>> [...]
>> }
>>
>> Whether you are or not, I note that in that particular class the 
>> unqualified name $client_server refers to $::zabbix::params::client_server 
>> (via class inheritance).  If you were expecting the value from hiera then 
>> you should be testing $::zabbix::client_server (and therefore that class 
>> should 'include ::zabbix', or at minimum it should document that it relies 
>> on some other class to have already done so).  Alternatively, you could 
>> read the value from hiera by calling "hiera('zabbix::client_server', 
>> $::zabbix::params::client_server)" to get exactly the same value that 
>> $::zabbix::client_server gets.
>>
>
> I don't think I've articulated this too well. I know those checks work 
> becuase for example if I hardcode an IP in params.pp for client_server then 
> the check is passed and the config file updated and service started without 
> error.
>
>

Again: the checks I quoted are against $zabbix::params::client_server, 
whose value does not depend on your Hiera data.  If that's what you 
intended then well and good, but it seems a bit pointless.  If those are 
*not* the failing checks you meant, then please point out the ones you did 
mean.  My effectiveness at predicting the errors in code I cannot analyze 
is much less than my effectiveness at spotting errors in code that I can 
analyze.

In any event, I don't see anywhere in the code on GitHub that you actually 
refer to variable $::zabbix::client_server, so I am uncertain how you could 
know whether it is getting the right value.

 

> However for example in our production common.yaml we have:
>
> ntp::servers: [ '0.uk.pool.ntp.org', '1.uk.pool.ntp.org', '
> 2.uk.pool.ntp.org', '3.uk.pool.ntp.org' ]
>
> This correctly modifies the ntp::params::servers variable.
>
> I am trying to achieve the same thing with my zabbix module by having this 
> in common.yaml:
>
> zabbix::client_server: '10.0.0.1'
>
> In order to modify the default value of zabbix::params::client_server
>
>

It sounds like you have a misconception.  By recording the specified data 
in Hiera, you provide a value to bind to class ::zabbix's parameter 
$::zabbix::client_server.  If you declare class ::zabbix without specifying 
a value for that parameter (e.g.

include '::zabbix'

or

class { '::zabbix': }

) then $::zabbix::client_server will take the Hiera value.  If there were 
no such value available from Hiera then $::zabbix::client_server would take 
its default value instead ($::zabbix::params::client_server).  *In no event 
is the value of class variable $::zabbix::params::client_server ever 
different from the one with which it is initialized in the body of class 
::zabbix::params.*



I've had a look through the Puppetlabs NTP code and it doesn't look like 
> you have to do anything special in order to be able to overwrite variables 
> in Hiera beyond what I have already done.
>


"Overwrite" sounds like you think something already set is being changed.  
That is not the case.  (Did you perhaps mean "override" instead?)  Anyway, 
your Hiera data look fine, and your class ::zabbix looks fine.  I think 
you're struggling with a scope issue, not an Hiera issue.


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 

[Puppet Users] Re: Cannot set variables via Hiera for a module I've written

2014-09-25 Thread Antoine Cotten
Hi Danny,

You should 'include' your main class (zabbix) before, or even inside your 
sub-classes, else nothing tells you in which order they will be declared, 
and apparently classes like zabbix::client::service DO require the 
parameters set in your main class.

Something like that should work:
   
class zabbix::client::service inherits zabbix::params {   # ensure the main 
class is declared
  include ::zabix

  if ($client_startagents != '0' and $client_server == '') {fail("Your 
StartAgents cannot be greater than 0 or null when Server is also null. Set 
StartAgents to 0 or set Server.")  }
...


Toni

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/5cae315d-d735-4a64-af43-8e8f56915a2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: Cannot set variables via Hiera for a module I've written

2014-09-24 Thread Danny Roberts


On Wednesday, 24 September 2014 14:08:30 UTC+1, jcbollinger wrote:
>
>
>
> On Wednesday, September 24, 2014 5:57:45 AM UTC-5, Danny Roberts wrote:
>>
>> Hi Folks,
>>
>> I've started writing a module for zabbix monitoring (current version 
>> here: https://github.com/kemra102/puppet-zabbix).
>>
>> I have a basic set-up to install the zabbix client using the module.
>>
>> There are some values I need to change for our environment so that the 
>> config works, in my case I'm trying to set the $zabbix::client_server 
>> variable via Hiera so it can be populated via template for the zabbix 
>> client.
>>
>> Currently I have this in *common.yaml*:
>>
>> zabbix::client_server: '10.0.0.1'
>>
>> As far as I know this should work fine and matches the Puppetlabs NTP 
>> module way of doing it (in this module we define our own NTP servers in 
>> Hiera to override the defaults just fine).
>>
>> However it doesn't seem to be getting set as one of the error checks I 
>> have in place is being triggered due to this value being missing.
>>
>
>
> Are you talking about these checks:
>
> class zabbix::client::service inherits zabbix::params {  
>   if ($client_startagents != '0' and $client_server == '') {  fail("Your 
> StartAgents cannot be greater than 0 or null when Server is also null. Set 
> StartAgents to 0 or set Server.")  }  if ($client_server == '' and 
> $client_serveractive == '') {  fail("You must set either passvie or 
> active (or both) checks via the Server or ServerActive options.")  }  
> [...]
> }
>
> Whether you are or not, I note that in that particular class the 
> unqualified name $client_server refers to $::zabbix::params::client_server 
> (via class inheritance).  If you were expecting the value from hiera then 
> you should be testing $::zabbix::client_server (and therefore that class 
> should 'include ::zabbix', or at minimum it should document that it relies 
> on some other class to have already done so).  Alternatively, you could 
> read the value from hiera by calling "hiera('zabbix::client_server', 
> $::zabbix::params::client_server)" to get exactly the same value that 
> $::zabbix::client_server gets.
>

I don't think I've articulated this too well. I know those checks work 
becuase for example if I hardcode an IP in params.pp for client_server then 
the check is passed and the config file updated and service started without 
error.

However for example in our production common.yaml we have:

ntp::servers: [ '0.uk.pool.ntp.org', '1.uk.pool.ntp.org', 
'2.uk.pool.ntp.org', '3.uk.pool.ntp.org' ]

This correctly modifies the ntp::params::servers variable.

I am trying to achieve the same thing with my zabbix module by having this 
in common.yaml:

zabbix::client_server: '10.0.0.1'

In order to modify the default value of zabbix::params::client_server

I've had a look through the Puppetlabs NTP code and it doesn't look like 
you have to do anything special in order to be able to overwrite variables 
in Hiera beyond what I have already done.
 

>  
>
>
>> Any ideas where the issue might lie? This is my first big piece of work 
>> doing a Puppet module in the more correct way so I may have missed 
>> something.
>>
>
>
> I suspect you are confused about variable scope.  I don't see any reason 
> to think that the problem is in your Hiera data.
>
>
> 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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/01d133df-8927-4e86-a934-edef32bbadee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: Cannot set variables via Hiera for a module I've written

2014-09-24 Thread jcbollinger


On Wednesday, September 24, 2014 5:57:45 AM UTC-5, Danny Roberts wrote:
>
> Hi Folks,
>
> I've started writing a module for zabbix monitoring (current version here: 
> https://github.com/kemra102/puppet-zabbix).
>
> I have a basic set-up to install the zabbix client using the module.
>
> There are some values I need to change for our environment so that the 
> config works, in my case I'm trying to set the $zabbix::client_server 
> variable via Hiera so it can be populated via template for the zabbix 
> client.
>
> Currently I have this in *common.yaml*:
>
> zabbix::client_server: '10.0.0.1'
>
> As far as I know this should work fine and matches the Puppetlabs NTP 
> module way of doing it (in this module we define our own NTP servers in 
> Hiera to override the defaults just fine).
>
> However it doesn't seem to be getting set as one of the error checks I 
> have in place is being triggered due to this value being missing.
>


Are you talking about these checks:

class zabbix::client::service inherits zabbix::params {  
  if ($client_startagents != '0' and $client_server == '') {  fail("Your 
StartAgents cannot be greater than 0 or null when Server is also null. Set 
StartAgents to 0 or set Server.")  }  if ($client_server == '' and 
$client_serveractive == '') {  fail("You must set either passvie or active 
(or both) checks via the Server or ServerActive options.")  }  
[...]
}

Whether you are or not, I note that in that particular class the 
unqualified name $client_server refers to $::zabbix::params::client_server 
(via class inheritance).  If you were expecting the value from hiera then 
you should be testing $::zabbix::client_server (and therefore that class 
should 'include ::zabbix', or at minimum it should document that it relies 
on some other class to have already done so).  Alternatively, you could 
read the value from hiera by calling "hiera('zabbix::client_server', 
$::zabbix::params::client_server)" to get exactly the same value that 
$::zabbix::client_server gets.
 


> Any ideas where the issue might lie? This is my first big piece of work 
> doing a Puppet module in the more correct way so I may have missed 
> something.
>


I suspect you are confused about variable scope.  I don't see any reason to 
think that the problem is in your Hiera data.


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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/f5cc811e-b922-402c-a0cb-9006d02d3065%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.