Puppet external configuration file?

130 views Asked by At

I have Vagrant set up and it's using Puppet as the provisioner with Puppet scripts setting up MySQL, PHP, etc. but the Puppet scripts have the hard coded values for passwords, addresses, etc.

I'd like to pull those out and store them in a external file alongside the Vagrantfile (not nested in the Puppet folder).

I thought this is what Hiera was for but cannot make sense of the documentation when trying to solve my problem. Any sugggestions?

1

There are 1 answers

0
ydaetskcoR On

I find that this worked example is a pretty good primer on how to use Hiera with Puppet for node specific configuration.

The above example basically has you go from a sites.pp file that looks like:

node "kermit.example.com" {
  class { "ntp":
    servers    => [ '0.us.pool.ntp.org iburst','1.us.pool.ntp.org iburst','2.us.pool.ntp.org iburst','3.us.pool.ntp.org iburst'],
    autoupdate => false,
    restrict   => [],
    enable     => true,
  }
}

node "grover.example.com" {
  class { "ntp":
    servers    => [ 'kermit.example.com','0.us.pool.ntp.org iburst','1.us.pool.ntp.org iburst','2.us.pool.ntp.org iburst'],
    autoupdate => true,
    restrict   => [],
    enable     => true,
  }
}

node "snuffie.example.com", "bigbird.example.com", "hooper.example.com" {
  class { "ntp":
    servers    => [ 'grover.example.com', 'kermit.example.com'],
    autoupdate => true,
    enable     => true,
  }
}

To one that simply defines a list of nodes:

hiera_include('classes')

node "kermit.example.com", "grover.example.com", "snuffie.example.com", "bigbird.example.com", "hooper.example.com"

The config is then inherited depending on the hierarchy defined in hiera.yaml. In their example they simply use this:

---
:backends:
  - yaml
:yaml:
  :datadir: /etc/puppet/hieradata
:hierarchy:
  - "node/%{::fqdn}"
  - common

Which says to load any YAML config files under /etc/puppet/hieradata/node/%{::fqdn}.yaml (for example, /etc/puppet/hieradata/node/kermit.example.com.yaml) and where needed config options aren't found in this first step then to pull any remaining config data in from /etc/puppet/hieradata/common.yaml.

The YAML files themselves are then defined like:

kermit.example.com.yaml:

---
classes: ntp
ntp::restrict:
  -
ntp::autoupdate: false
ntp::enable: true
ntp::servers:
  - 0.us.pool.ntp.org iburst
  - 1.us.pool.ntp.org iburst
  - 2.us.pool.ntp.org iburst
  - 3.us.pool.ntp.org iburst

common.yaml:

---
classes: ntp
ntp::autoupdate: true
ntp::enable: true
ntp::servers:
  - grover.example.com iburst
  - kermit.example.com iburst