-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
381 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,113 @@ | |||
# Getting Started | |||
|
|||
Hiera is a simple hierarchal database which provides an easy to use interface | |||
for looking up data using a key. | |||
|
|||
$ hiera puppetlabs_home_page | |||
http://puppetlabs.com | |||
|
|||
## Installation | |||
|
|||
We are going to install Hiera using Rubygems, so now is a good time to make | |||
sure you meet the prerequisites. | |||
|
|||
### Prerequisites | |||
|
|||
* Ruby 1.8.5+ | |||
* Rubygems 1.3.0+ | |||
|
|||
### Installing Hiera via Rubygems | |||
|
|||
$ gem install hiera | |||
Successfully installed hiera-0.3.0 | |||
1 gem installed | |||
Installing ri documentation for hiera-0.3.0... | |||
Installing RDoc documentation for hiera-0.3.0... | |||
|
|||
Make sure we can run the hiera command: | |||
|
|||
$ hiera -v | |||
0.3.0 | |||
|
|||
- | |||
|
|||
**Note:** Some Linux distributions such as Debian squeeze do not put the gem bin | |||
directory (`/var/lib/gems/1.8/bin`) in your PATH by default. You may have | |||
to call hiera using the full path: | |||
|
|||
$ /var/lib/gems/1.8/bin/hiera -v | |||
0.3.0 | |||
|
|||
## Configuration | |||
|
|||
Before using Hiera we need to create a configuration file. By default Hiera | |||
attempts to load `hiera.yaml` from the `/etc/` directory. Lets create that | |||
file now: | |||
|
|||
$ vim /etc/hiera.yaml | |||
--- | |||
:backends: | |||
- yaml | |||
|
|||
:hierarchy: | |||
- global | |||
|
|||
:yaml: | |||
:datadir: /var/lib/hiera/data | |||
|
|||
- | |||
|
|||
**Note:** If Hiera cannot locate `/etc/hiera.yaml` you will receive the follow | |||
error when trying to lookup a value: | |||
|
|||
$ hiera key | |||
Failed to start Hiera: RuntimeError: Config file /etc/hiera.yaml not found | |||
|
|||
You can specify a different configuration file using the `--config` option: | |||
|
|||
$ hiera --config ~/hiera.yaml key | |||
|
|||
## Adding data | |||
|
|||
With configuration out of the way, lets add some data. The yaml backend | |||
expects to find data files under the `datadir` we configured earlier. | |||
|
|||
Create the `/var/lib/hiera/data` data directory: | |||
|
|||
$ mkdir -p /var/lib/hiera/data | |||
|
|||
For each source in the `hierarchy`, the yaml backend will search for a | |||
corresponding YAML file under the `datadir`. | |||
|
|||
For example, our `hierarchy` consists of a single source named `global`. The | |||
yaml backend will look for `/var/lib/hiera/data/global.yaml`, and if missing | |||
skips it and move on to the next source in the hierarchy. | |||
|
|||
Lets add some data to the `global` source: | |||
|
|||
$ vim /var/lib/hiera/data/global.yaml | |||
--- | |||
driftfile: '/etc/ntp/drift' | |||
ntpservers: | |||
- '0.north-america.pool.ntp.org' | |||
- '1.north-america.pool.ntp.org' | |||
|
|||
## Looking up data | |||
|
|||
Now that we have our configuration setup and some data, lets lookup the | |||
'driftfile' key: | |||
|
|||
$ /var/lib/gems/1.8/bin/hiera driftfile | |||
/etc/ntp/drift | |||
|
|||
We get extacaly what we expected, '/etc/ntp/drift'. | |||
|
|||
Running the lookup command with the `--debug` flag, we can see the details | |||
of how Hiera lookups data: | |||
|
|||
$ /var/lib/gems/1.8/bin/hiera driftfile --debug | |||
DEBUG: Thu Jun 28 09:54:04 -0400 2012: Hiera YAML backend starting | |||
DEBUG: Thu Jun 28 09:54:04 -0400 2012: Looking up driftfile in YAML backend | |||
DEBUG: Thu Jun 28 09:54:04 -0400 2012: Looking for data source global | |||
/etc/ntp/drift | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,123 @@ | |||
# Hierarchies, Sources, and Scope | |||
|
|||
The key to mastering Hiera is understanding the following concepts: | |||
|
|||
* Hierarchies | |||
* Sources | |||
* Scope | |||
|
|||
## Hierarchies | |||
|
|||
At the very core of Hiera are the data hierarchies, which are made up of | |||
sources. Hierarchies are specified in Hiera configuration file `hiera.yaml` via the | |||
`:hierarchy:` array. | |||
|
|||
:hierarchy: | |||
- "%{certname}" | |||
- "%{environment}" | |||
- default | |||
|
|||
There are three sources in the above hierarchy, `%{certname}`, `%{environment}`, | |||
and `default`. The first two sources, `%{certname}` and `%{environment}`, | |||
represent dynamic sources which will be resolved at runtime. The third source | |||
`default` is static. | |||
|
|||
|
|||
When looking up a key Hiera iterates through each source in the hierarchy | |||
starting with the first one in the list. In our case `%{certname}`. There is | |||
no limit to the number of sources you can have. But lets not go crazy; try and | |||
keep your hierarchy below 5 - 6 levels deep. Any more than this you should | |||
start thinking about custom facts or how your data is organized. | |||
|
|||
### Order is important | |||
|
|||
Hiera uses the priority resolution type by default. This means Hiera stops at | |||
the first source in the hierarchy that provides a non `nil` answer. The | |||
behavior is a slightly different for the array and hash resolution types. Every | |||
scope in the hierarchy will be searched, but data is appended not overridden! | |||
|
|||
## Sources | |||
|
|||
Each level of the hierarchy is represented by a source which comes in two | |||
flavors, static and dynamic. | |||
|
|||
### Static sources | |||
|
|||
A source is considered static when it appears in the hierarchy as a simple | |||
string. | |||
|
|||
:hierarchy: | |||
- default | |||
|
|||
- | |||
You should consider using a static source when you want a certain level in | |||
the hierarchy to apply to all nodes. | |||
|
|||
### Dynamic sources | |||
|
|||
A source is considered dynamic when it appears in the hierarchy as a string | |||
enclosed between `%{}` like this: | |||
|
|||
:hierarchy: | |||
- %{certname} | |||
|
|||
Dynamic sources are interpolated by Hiera at runtime. | |||
|
|||
- | |||
You should consider using a dynamic source when you want to provide different | |||
data based on Facter Facts. | |||
|
|||
## Scope | |||
|
|||
A scope is a collection of key/value pairs: | |||
|
|||
certname: agent.puppetlabs.com | |||
environment: production | |||
operatingsystem: Debian | |||
|
|||
If you are thinking scopes look a lot like Facter Facts you are on to | |||
something. Hiera was designed around Facter Facts being the primary input | |||
for scope. | |||
|
|||
### Source interpolation | |||
|
|||
Hiera uses the scope when interpolating sources in the hierarchy. | |||
|
|||
<img src='https://github.com/kelseyhightower/hiera/raw/maint/1.0rc/add_getting_started_tutorial/docs/images/hiera_hierarchy_resolution.png' /> | |||
|
|||
Scopes can be empty, and when they are, dynamic sources are excluded from the | |||
hierarchy at run time. | |||
|
|||
<img src='https://github.com/kelseyhightower/hiera/raw/maint/1.0rc/add_getting_started_tutorial/docs/images/hiera_hierarchy_resolution_empty_scope.png' /> | |||
|
|||
### Feeding Hiera your scope | |||
|
|||
You can provide Hiera a scope via the command line using the `--yaml` or | |||
`--json` options. | |||
|
|||
For example: | |||
|
|||
If we had the following scope: | |||
|
|||
$ cat /tmp/scope.yaml | |||
--- | |||
certname: agent.example.com | |||
environment: production | |||
|
|||
|
|||
|
|||
You can feed it to Hiera like this: | |||
|
|||
$ hiera --yaml /tmp/scope.yaml driftfile | |||
/etc/ntp/drift | |||
|
|||
- | |||
**Note:** If you run into the follow error, you need to make sure Puppet is installed: | |||
|
|||
Could not load YAML scope: LoadError: no such file to load -- puppet | |||
|
|||
The reason for this is that the scope yaml file could have been produced by | |||
Puppet, and contained serialized objects. Since it would be desirable to use | |||
Hiera without Puppet, this restrict will be removed in the future. | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.