[Puppet Users] Re: ERB Template Newb Question

2013-07-15 Thread jcbollinger


On Friday, July 12, 2013 5:57:49 PM UTC-5, towen27 wrote:

 I'm trying to write my first puppet template, but I am running into some 
 issues. The following is my template:

 *# Managed by Puppet*
 *CONFIG_FILE=/etc/rabbitmq/rabbitmq*
 *% if @rabbitmq_port != 'UNSET' -%*
 *NODE_PORT=%= @rabbitmq_port %*
 *% end -%*
 *% if @rabbitmq_address != 'UNSET' -%*
 *NODE_IP_ADDRESS=%= @rabbitmq_address %*
 *% end -%*

 This is a pretty simply template, but the issue I'm seeing is that 
 NODE_PORT=  NODE_IP_ADDRESS= is always printed into the config file 
 regardless if the variables are set to UNSET or not. What I'm wanting to do 
 is not print NODE_PORT= or NODE_IP_ADDRESS= if the matching variable is 
 equal to UNSET.

 Output of configuration file when rabbitmq_port and rabbitmq_address are 
 set to UNSET:

 *# Managed by Puppet*
 *CONFIG_FILE=/etc/rabbitmq/rabbitmq*
 *NODE_PORT=*
 *NODE_IP_ADDRESS=*
 *
 *
 Any help would be appreciated!



I was going to suggest that you add some debugging output to the template 
to show the values of the test variables, but in fact, the regular output 
tells the story. Note that it does *not* contain

NODE_PORT=UNSET
NODE_IP_ADDRESS=UNSET

, which is what you might expect it to print if the conditionals were 
somehow not working.  The variables do not contain the values you think 
they do.

My first guess would be that the Puppet variables you are trying to access 
from the template are neither global nor local to the scope in which the 
template is evaluated.  Perhaps they belong to a parent scope.  In 
particular, note that defined type bodies establish their own scopes.  To 
my knowledge, defined-type instances do not inherit variables from the 
class that declares them (though they can reference class variables by all 
the normal mechanisms).


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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Puppet Users] Re: ERB Template Newb Question

2013-07-14 Thread Virender Khatri
If you are using hiera, you can set the default value to UNSET for those
variables, it should do it.

*rabbitmq_port = hiera('**rabbitmq_port','UNSET')*
*
*
If you are using host facts, you can modify if condition like this:

*% if **@rabbitmq_port != '' and **@rabbitmq_port != 'UNSET' -%*
*
*
-Virender


On Sat, Jul 13, 2013 at 8:01 AM, badge...@hotmail.com wrote:

 Could you show the puppet code that sets '$rabbitmq_port' and
 '$rabbitmq_address' ?

 I'd recommend dropping a line like this in your template:

 *NODE_PORT=%= @rabbitmq_port.inspect %*

 (If you see 'nil', the variable either hasn't been set or has been set to
 'undef').

 Eric

  --
 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 post to this group, send email to puppet-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/puppet-users.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.




[Puppet Users] Re: ERB Template Newb Question

2013-07-13 Thread badgerea
Could you show the puppet code that sets '$rabbitmq_port' and 
'$rabbitmq_address' ?

I'd recommend dropping a line like this in your template:

*NODE_PORT=%= @rabbitmq_port.inspect %*

(If you see 'nil', the variable either hasn't been set or has been set to 
'undef'). 

Eric

-- 
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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.