Академический Документы
Профессиональный Документы
Культура Документы
1 of 5
https://rnelson0.com/2015/11/17/troubleshooting-hiera-from-the-cli/
rnelson0
Infrastructure, Virtualization, Security
POSTED BY
RNELSON0
POSTED ON
NOVEMBER 17, 2015
POSTED UNDER
PUPPET, VDM30IN30
COMMENTS
LEAVE A COMMENT
14-08-2016 01:50
2 of 5
https://rnelson0.com/2015/11/17/troubleshooting-hiera-from-the-cli/
Tier 1: global
Lets look up the ntp::servers key from the global tier. One thing to note here is that the datadir includes
the variable environment, so we will need to provide that tuple to the cli, like so:
[rnelson0@puppet ~]$ hiera ntp::servers environment=production
["0.pool.ntp.org", "2.centos.pool.ntp.org", "1.rhel.pool.ntp.org"]
It is important to note that the variables MUST match how they are referred to in hiera.yaml as there
is no normalization. Thus, environment=production and ::environment=product are entirely dierent.
Ensure you match the usage in your conguration.
Tier 2: puppet_role
Next, lets look at the classes key, which exists at the puppet_role tier. Using the same command with a
dierent key wont work:
[rnelson0@puppet ~]$ hiera classes environment=production
nil
It didnt even look at the puppet_role tier! This is by design, because we did not provide that value.
Lets try it while specifying a puppet_role:
[rnelson0@puppet ~]$ hiera classes environment=production puppet_role=mysql
role::mysql_server
14-08-2016 01:50
3 of 5
https://rnelson0.com/2015/11/17/troubleshooting-hiera-from-the-cli/
Tier 3: clientcert
Now lets take a look at the mysql::override_options hash:
Dang, thats apparently not found at that tier, its at the clientcert tier! Well have to add that to the
arguments:
14-08-2016 01:50
4 of 5
https://rnelson0.com/2015/11/17/troubleshooting-hiera-from-the-cli/
--version
--debug
--array
--hash
--config CONFIG
--json SCOPE
--yaml SCOPE
--mcollective IDENTITY
--inventory_service IDENTITY
Version information
Show debugging information
Return all values as an array
Return all values as a hash
Configuration file
JSON format file to load scope from
YAML format file to load scope from
Use facts from a node (via mcollective) as scop
Use facts from a node (via Puppet's inventory s
We can load scope from a le! We need to create one rst, though. Thankfully, facter has what we
need:
[rnelson0@mysql ~]$ facter --help
facter(8) -- Gather system information
======
SYNOPSIS
-------Collect and display facts about the system.
USAGE
-----
Run facter with the puppet and yaml|json ags and save it in a le:
[rnelson0@mysql ~]$ sudo facter -py > mysql.yaml
[rnelson0@mysql ~]$ grep role mysql.yaml
puppet_role: mysql
Transfer the le to your puppet master. Before you use it, add any variables you need, like
environment or clientcert, that arent part of the facter output but are important to your hierarchy:
14-08-2016 01:50
5 of 5
https://rnelson0.com/2015/11/17/troubleshooting-hiera-from-the-cli/
This server is intended for use by the Nelson family. All other use is unauthorized.
rnelson0@mysql's password:
mysql.yaml
[rnelson0@puppet ~]$ cat >>mysql.yaml
environment: production
clientcert: mysql.nelson.va
100% 480
Remember that not all variables in your hierarchy, like clientcert, are considered facts. In this case, the
conguration directive clientcert remains the same over time whereas the similar fact fqdn can vary.
Though we generated the list using facter, we can add whatever we want to it.
You can now make a much simpler call to hiera that only varies by the key youre looking up:
[rnelson0@puppet ~]$ hiera -y mysql.yaml ntp::servers
["0.pool.ntp.org", "2.centos.pool.ntp.org", "1.rhel.pool.ntp.org"]
[rnelson0@puppet ~]$ hiera -y mysql.yaml classes
role::mysql_server
[rnelson0@puppet ~]$ hiera -y mysql.yaml mysql::server::override_options
{"client"=>{"socket"=>"/data/mysql/mysql.sock"},
"mysqld"=>
{"bind-address"=>"0.0.0.0",
"log_bin_index"=>"/data/mysql/replog/mysql-bin.log.index",
"relay-log"=>"/data/mysql/replog/slave-relay.log",
"server-id"=>1,
"datadir"=>"/data/mysql",
"auto-increment-increment"=>2,
"socket"=>"/data/mysql/mysql.sock",
"log-bin"=>"/data/mysql/replog/mysql-bin.log",
"relay-log-index"=>"/data/mysql/replog/slave-relay-log.index",
"auto-increment-offset"=>1},
"mysqld_safe"=>{"socket"=>"/data/mysql/mysql.sock"}}
Summary
You now have a good idea of how to use hiera at the cli and how to do repeated lookups without
excessive typing and with the actual facts from a node. Enjoy!
Blog at WordPress.com.
14-08-2016 01:50