Discussion:
[Puppet Users] Hiera and ENC-set top-scope variables
Matthew Ceroni
2013-11-22 17:34:24 UTC
Permalink
I am trying to use an ENC-set top-scope variable in my Hiera hierarchy.
However it doesn't seem to be working.

Here is what is returned by my ENC script (it is the foreman ENC script)
for a node:

parameters:
san_rafael-spacewalk: mai01-sprxy-02v
puppet_ca: mai01-pmstr-02v
group: engineering
spacewalk_type: site
san_rafael_dmz-spacewalk: mai01-sprxy-01v
hostgroup: base/production/engineering/quality_assurance/locked
san_rafael_dmz-proxy: mai01-dprxy-01v
spacewalk_host: mai02-swalk-01v
santa_rosa_dmz-spacewalk: mai02-sprxy-01v
root_pw: $1$ubWDPsM+$lzyZdN91QCk6dZAhMXBlM/
foreman_env: production
santa_rosa_dmz-proxy: mai02-dprxy-01v
activation_key: 5-839beb8c567b98c0720db37f19ecb64d
puppetmaster: mai01-pmstr-02v
environment: production
classes:
security::access:
security::users:

Then in my hiera.yaml file I have:

---
:backend:
- yaml
:hierarchy:
- %{::clientcert}
- %{::group}
- %{::dc_location}_%{::is_dmz}
- %{::operatingsystem}
- common

:yaml:
:datadir: '/var/lib/hiera'

Then within /var/lib/hiera I added an engineering.yaml file. But it doesn't
seem to be referenced when Hiera goes through the hierarchy. One way I
verified this (to ensure something else funky wasn't going on) is that i
purposely put an error in the engineering.yaml file and Puppet runs without
issue.

Is it not possible to use a variable returned from ENC?

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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0db79c50-d364-4d7c-85e5-b629028ee3f3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Josh
2014-01-05 20:42:17 UTC
Permalink
Hi,

I'm trying to do the exact same thing without success. If I understand the
Hiera documentation correctly [1], this should be possible (although, I may
be misunderstanding this documentation). The only workaround I have
currently is to turn the top-scope variable (provided by my ENC) into a
fact using something like:

file { "/etc/puppetlabs/facter/facts.d/group.txt":
content => "group=$group",
}

However, this has it's disadvantages, because the $::group fact doesn't
become available until after the puppet run that declares the file resource.

Any ideas?

Thanks,

Josh

[1] http://docs.puppetlabs.com/hiera/1/variables.html
Post by Matthew Ceroni
I am trying to use an ENC-set top-scope variable in my Hiera hierarchy.
However it doesn't seem to be working.
Here is what is returned by my ENC script (it is the foreman ENC script)
san_rafael-spacewalk: mai01-sprxy-02v
puppet_ca: mai01-pmstr-02v
group: engineering
spacewalk_type: site
san_rafael_dmz-spacewalk: mai01-sprxy-01v
hostgroup: base/production/engineering/quality_assurance/locked
san_rafael_dmz-proxy: mai01-dprxy-01v
spacewalk_host: mai02-swalk-01v
santa_rosa_dmz-spacewalk: mai02-sprxy-01v
root_pw: $1$ubWDPsM+$lzyZdN91QCk6dZAhMXBlM/
foreman_env: production
santa_rosa_dmz-proxy: mai02-dprxy-01v
activation_key: 5-839beb8c567b98c0720db37f19ecb64d
puppetmaster: mai01-pmstr-02v
environment: production
---
- yaml
- %{::clientcert}
- %{::group}
- %{::dc_location}_%{::is_dmz}
- %{::operatingsystem}
- common
:datadir: '/var/lib/hiera'
Then within /var/lib/hiera I added an engineering.yaml file. But it
doesn't seem to be referenced when Hiera goes through the hierarchy. One
way I verified this (to ensure something else funky wasn't going on) is
that i purposely put an error in the engineering.yaml file and Puppet runs
without issue.
Is it not possible to use a variable returned from ENC?
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0f5dd617-8144-4c58-9c0d-ac31e3886cbc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2014-01-06 15:24:21 UTC
Permalink
Post by Matthew Ceroni
I am trying to use an ENC-set top-scope variable in my Hiera hierarchy.
However it doesn't seem to be working.
I thought that was supported.
Post by Matthew Ceroni
Here is what is returned by my ENC script (it is the foreman ENC script)
san_rafael-spacewalk: mai01-sprxy-02v
puppet_ca: mai01-pmstr-02v
group: engineering
spacewalk_type: site
san_rafael_dmz-spacewalk: mai01-sprxy-01v
hostgroup: base/production/engineering/quality_assurance/locked
san_rafael_dmz-proxy: mai01-dprxy-01v
spacewalk_host: mai02-swalk-01v
santa_rosa_dmz-spacewalk: mai02-sprxy-01v
root_pw: $1$ubWDPsM+$lzyZdN91QCk6dZAhMXBlM/
foreman_env: production
santa_rosa_dmz-proxy: mai02-dprxy-01v
activation_key: 5-839beb8c567b98c0720db37f19ecb64d
puppetmaster: mai01-pmstr-02v
environment: production
---
- yaml
- %{::clientcert}
- %{::group}
- %{::dc_location}_%{::is_dmz}
- %{::operatingsystem}
- common
:datadir: '/var/lib/hiera'
Then within /var/lib/hiera I added an engineering.yaml file. But it
doesn't seem to be referenced when Hiera goes through the hierarchy. One
way I verified this (to ensure something else funky wasn't going on) is
that i purposely put an error in the engineering.yaml file and Puppet runs
without issue.
In the doc that Josh cited, I find this notable tidbit: "In YAML files, *any
string containing an interpolation token must be quoted* in order to comply
with the YAML spec. (Under Ruby 1.8, interpolation tokens in unquoted
strings will sometimes work anyway, but this can’t be relied on.)" That
would apply to your hiera.yaml file, which does not quote the
interpolations it uses. You ought to fix that in any case, and maybe doing
so will even resolve your problem.


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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1ac587bc-c5b1-4976-b49a-593caa63f04e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Nick Walker
2014-01-06 19:00:00 UTC
Permalink
I was able to get this to work without issue using the Puppet Enterprise
console as my ENC. I did the following:

Created a top-scope variable via the console called group and set it to
engineering.

[***@master310-centos ~]# /etc/puppetlabs/puppet-dashboard/external_node
master310-centos
---
name: master310-centos
classes:
parameters:
group: engineering

I have the following hiera.yaml file. You will note that I did double
quote my variable for interpolation.

---
:backends:
- yaml
:hierarchy:
- "%{group}"
- global

:yaml:
:datadir:

I placed a file called engineering.yaml in /var/lib/hiera with the
following contents:

test: testvalue

Finally, I created the following test manifest.

class test {

notify { "group is $group": }

$test = hiera(test)

notify { "test is $test": }

}

And as I was hoping, I get the output of 'testvalue' for the variable test.


[***@master310-centos ~]# puppet agent -t
...
Notice: test is testvalue
Notice: /Stage[main]/Test/Notify[test is testvalue]/message: defined
'message' as 'test is testvalue'
Notice: group is engineering
Notice: /Stage[main]/Test/Notify[group is engineering]/message: defined
'message' as 'group is engineering'
Notice: Finished catalog run in 10.09 seconds
Post by jcbollinger
Post by Matthew Ceroni
I am trying to use an ENC-set top-scope variable in my Hiera hierarchy.
However it doesn't seem to be working.
I thought that was supported.
Post by Matthew Ceroni
Here is what is returned by my ENC script (it is the foreman ENC script)
san_rafael-spacewalk: mai01-sprxy-02v
puppet_ca: mai01-pmstr-02v
group: engineering
spacewalk_type: site
san_rafael_dmz-spacewalk: mai01-sprxy-01v
hostgroup: base/production/engineering/quality_assurance/locked
san_rafael_dmz-proxy: mai01-dprxy-01v
spacewalk_host: mai02-swalk-01v
santa_rosa_dmz-spacewalk: mai02-sprxy-01v
root_pw: $1$ubWDPsM+$lzyZdN91QCk6dZAhMXBlM/
foreman_env: production
santa_rosa_dmz-proxy: mai02-dprxy-01v
activation_key: 5-839beb8c567b98c0720db37f19ecb64d
puppetmaster: mai01-pmstr-02v
environment: production
---
- yaml
- %{::clientcert}
- %{::group}
- %{::dc_location}_%{::is_dmz}
- %{::operatingsystem}
- common
:datadir: '/var/lib/hiera'
Then within /var/lib/hiera I added an engineering.yaml file. But it
doesn't seem to be referenced when Hiera goes through the hierarchy. One
way I verified this (to ensure something else funky wasn't going on) is
that i purposely put an error in the engineering.yaml file and Puppet runs
without issue.
In the doc that Josh cited, I find this notable tidbit: "In YAML files, *any
string containing an interpolation token must be quoted* in order to
comply with the YAML spec. (Under Ruby 1.8, interpolation tokens in
unquoted strings will sometimes work anyway, but this can’t be relied
on.)" That would apply to your hiera.yaml file, which does not quote the
interpolations it uses. You ought to fix that in any case, and maybe doing
so will even resolve your problem.
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/9e71b620-cf47-4c8c-8609-440ec24f0e56%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...