Passing Blank Values in Hiera Hashes

391 views
Skip to first unread message

Danny Roberts

unread,
Feb 5, 2015, 5:24:12 AM2/5/15
to puppet...@googlegroups.com
I am trying to configure NGINX entirely within Hiera. For the most part this is very easy as the module directly supports setting things up in Hiera.

Where I am having an issue though is when creating an upstream in Hiera I am wanting to pass the 'ip_hash' parameter to it. The in source docs show an example of doing this from in a manifest but not Hiera. So I came up with this Hiera code for the upstream:

nginx::nginx_upstreams:
 
'mycluster':
   
ensure: 'present'
    members
: [ '192.168.0.1:80', '192.168.0.2:80' ]
    upstream_cfg_prepend
:
      ip_hash
: ''

Though presumably because the value of that hash key/value pair is empty the ip_hash variable does not get added to the resulting config file on the server, you just get a blank line inserted. I've done some searching and cannot find a way to make this work in Hiera so it may simply not be possible, but does anyone know a way around this?

Garrett Honeycutt

unread,
Feb 5, 2015, 6:59:39 AM2/5/15
to puppet...@googlegroups.com
On 2/5/15 11:24 AM, Danny Roberts wrote:
> I am trying to configure NGINX entirely within Hiera. For the most part
> this is very easy as the module directly supports setting things up in
> Hiera.
>
> Where I am having an issue though is when creating an upstream in Hiera
> I am wanting to pass the 'ip_hash' parameter to it. The in source docs
> <https://github.com/jfryman/puppet-nginx/blob/master/manifests/resource/upstream.pp#L28-L40> show
> an example of doing this from in a manifest but not Hiera. So I came up
> with this Hiera code for the upstream:
>
> |
> nginx::nginx_upstreams:
> 'mycluster':
> ensure:'present'
> members:['192.168.0.1:80','192.168.0.2:80']
> upstream_cfg_prepend:
> ip_hash:''
> |
>
>
> Though presumably because the value of that hash key/value pair is empty the ip_hash variable does not get added to the resulting config file on the server, you just get a blank line inserted. I've done some searching and cannot find a way to make this work in Hiera so it may simply not be possible, but does anyone know a way around this?
>

Hi,

It appears that ip_hash is being represented as a string instead of a
hash itself. If you are not going to give ip_hash any values, I don't
think you need to specify it at all.

HTH,
-g


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

Dan White

unread,
Feb 5, 2015, 8:13:29 AM2/5/15
to puppet...@googlegroups.com
Looks to me like the template upstream_header.erb is not built to handle this.
I know a template that can handle this sort of input --
Check out https://github.com/puppetlabs/puppetlabs-mysql/blob/master/templates/my.cnf.erb
line 9 specifically looks for true or '' in the value of a key/value pair and then just outputs the key.

The logic you need is in there, but it will take a bit of tinkering, I think.
“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”  (Bill Waterson: Calvin & Hobbes)
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/52ff4e6a-e99a-4697-81e9-6d0f0c1ae4cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages