简体   繁体   中英

Where to put hiera files in puppet hiera setup

I have a running puppet master-agent setup and currently trying to figure out how to use hiera to provision php.

My Puppetfile:

forge "http://forge.puppetlabs.com"

mod "jfryman/nginx"
mod "puppetlabs/mysql"
mod "mayflower/php"
mod 'puppetlabs-vcsrepo'
mod 'puppetlabs/ntp', '4.1.0'
mod 'puppetlabs/stdlib'

My site.pp :

hiera_include('classes')

My environment.conf , where the modulepath is maintained:

manifest = site.pp
modulepath = modules:site

My hiera config on puppet master at /etc/puppetlabs/puppet/hiera.yml :

---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - "environment/%{server_facts.environment}"
  - common

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:

From what I understand, general config that should be present on all servers goes into common.yaml . With this setup, I managed to install ntp on my node with this config at hieradata/common.yaml :

---
classes:
 - 'profile::base'

ntp::servers:
  - server 0.de.pool.ntp.org
  - server 1.de.pool.ntp.org
  - server 2.de.pool.ntp.org
  - server 3.de.pool.ntp.org

Now, my hierarchy also states that all node specific config should go into hieradata/nodes/{fqdn-of-the-node}.yml .

Now, finally coming to my questions:

I have a file hieradata/nodes/myserver.example.com.yml which holds this:

classes:
  - 'profile::php'

And a manifest under site/profile/manifests/php.pp :

class profile::php {
  class { '::php': }
}

But this does not provision php. As you saw, I use mayflower/php from the forge.

Now, my two questions are:

Is my hiera file for php in the right location? What am I missing then to make it provision php to my agent?

You have multiple issues/possibilities here, so let us go through them iteratively.


First, you are using the default datadir of:

/etc/puppetlabs/code/environments/%{environment}/hieradata

However, you have a priority of:

"environment/%{server_facts.environment}"

This does not make sense, since you have a priority that distinguishes data for nodes based on their directory environment, but you also are placing hieradata directly in directory environments. If you want priority based on directory environment, then change your hieradata directory to be outside the direct environments at:

/etc/puppetlabs/code/hieradata

Otherwise, you should remove that level from your priority as it adds no value and will increase lookup times.


Second, you did not show your site.pp , but did you remember your hiera_include('classes') ? That will lookup the array classes and then include them, which is what it seems you want. If you are not doing it, then the node provisioning issue you described would occur.


Third, is site in your modulepath ? You need to append it in either your puppet.conf or your environment.conf .


Fourth, your node's fqdn may not match the certname . Check the certs directory on your Puppetmaster for the node's cert.


Side notes:

  • The first half of your question contains a lot of extraneous information and is missing a lot of helpful relevant information. Please consider editing the question to provide more helpful information and to be more concise.
  • Since ntp worked, I am assuming your module install with r10k into the environment directories succeeded. Also I am assuming that the modules are present for the directory environment of your node.
  • There is no real reason to specify the php class as global in your declaration with ::php .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM