2016-12-21 4 views
1

私はパペットを学んでいるだけで、ヒエラについて読んでいます。マニフェスト内のパペット・ヒエラ・ルックアップが機能しない

$ cat /etc/puppetlabs/puppet/puppet.conf 
[master] 
codedir = /etc/puppetlabs/code 

[agent] 
server = puppet.example.com 

[master] 
certname = puppet.example.com 

[master] 
vardir = /var/opt/puppetlabs/puppetserver 
ssldir = $vardir/ssl 

[main] 
environmentpath = /etc/puppetlabs/code/environments 
basemodulepath = /etc/puppetlabs/code/modules 


$ cat /etc/puppetlabs/puppet/hiera.yaml 
--- 
:backends: 
    - yaml 
:hierarchy: 
    - "nodes/%{::trusted.certname}" 
    - 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: 

UPDATE:

問題に来る前、私は以下のいくつかのコンフィグ設定を提供しています@ UM-FelixFrankの答えを通過した後、私は私のデフォルトHieraの設定ファイルの場所を変更しました。設定ファイルには、以下の内容があります。

$ cat /etc/puppetlabs/code/hiera.yaml 
--- 
:backends: 
- yaml 
:hierarchy: 
- "hostname/%{facts.hostname}" 
- "os/%{facts.osfamily}" 
- common 
:yaml: 
:datadir: /etc/puppetlabs/code/hieradata 

私は下に述べたように、私のホスト名YAMLファイルで上記の値を上書きしようとした/etc/puppetlabs/code

$ ll /etc/puppetlabs/code/ 
total 4 
drwxr-xr-x. 4 root root 32 Dec 20 11:17 environments 
drwxr-xr-x. 3 root root 39 Dec 21 12:22 hieradata 
-rw-r--r--. 1 root root 153 Dec 20 16:51 hiera.yaml 
drwxr-xr-x. 2 root root 6 Dec 21 11:02 modules 

$ cat /etc/puppetlabs/code/hieradata/common.yaml 
--- 
puppet::status: 'running' 
puppet::enabled: true 

下hieradataディレクトリを作成しました:

$ cat /etc/puppetlabs/code/hieradata/hostname/delvmplgc1.yaml 
--- 
puppet::status: 'stopped' 
puppet::enabled: false 

$ facter hostname 
delvmplgc1 

Puppetサーバーのサンプルマニフェストを作成して、マニフェストでHieraルックアップを実行できるかどうかを確認しました。

$ cat /etc/puppetlabs/code/environments/qa/manifests/hierasample.pp 
notify { 'welcome': 
     message => "Hello!", 
} 

$status = lookup({ name => 'puppet::status', default_value => 'running' }) 
$enabled = lookup({ name => 'puppet::enabled', default_value => true }) 

service { 'puppet': 
     ensure => $status, 
     enable => $enabled, 
} 

ここで問題は、マニフェストを実行しようとすると、Hieraに関連するメッセージが表示されないことです。

$ puppet apply /etc/puppetlabs/code/environments/qa/manifests/hierasample.pp 
Notice: Compiled catalog for delvmplgc1.sapient.com in environment production in 0.99 seconds 
Notice: Hello! 
Notice: /Stage[main]/Main/Notify[welcome]/message: defined 'message' as 'Hello!' 
Notice: Applied catalog in 0.10 seconds 

助けてください。

+0

'/ etc/puppetlabs/puppet/hiera.yaml'の内容を質問に追加できますか? –

+0

'/ etc/puppetlabs/puppet/hiera.yaml'の内容で投稿を更新しました – Technext

答えて

3

標準hiera.yaml状態のコメントとして、datadir

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

に位置するので、代わりの直接/etc/puppetlabs/codehieradataを作成、/etc/puppetlabs/code/environments/qa及び他の環境に2つのレベルがそれを下に移動されます。

+0

代わりに' hiera_config = $ codedir/hiera.yaml'を使ってデフォルトのhiera設定ファイルの場所を変更しようとしました。間違いを指摘してくれてありがとう! :) – Technext

+0

まだ1つのクエリがあります:私の投稿に表示されているファイルdelvmplgc1.yamlの上書きされた値は、それぞれ 'status'と 'enabled'を 'stopped'とfalseに変更します。しかし、人形の出力には次のように書かれています: 'Notice/Stage [main]/Main/Service [puppet]/ensure: 'running'を 'stopped'に変更しました。 'Notice:/ Stage/Main/Service [puppet]/enable:変更を 'true'から 'false'に変更することもできるはずです。なぜそれをスキップしたのか? – Technext

+0

自分のカスタムhiera.yamlファイルの内容を投稿に貼り付けました。 – Technext

関連する問題