0

如果尝试从模块使用调用类获取数据,则数据不会出现在 puppet 清单中,如果将变量放入 common 或 osfamily yaml 文件值,则可以从清单中获得。我的环境:Puppet Master 3.7.4 + Foreman 1.7 + Hiera 1.3.4 Hiera 配置:

    ---
:backends:
  - yaml
:hierarchy:
  - "%{::environment}/node/%{::fqdn}" #node settings
  - "%{::environment}/profile/%{calling_class}" # profile settings
  - "%{::environment}/%{::environment}" # environment settings
  - "%{::environment}/%{::osfamily}" # osfamily settings
  - common # common settings
:yaml:
  :datadir: '/etc/puppet/hiera'

/etc/puppet/hiera/production/profile/common.yaml

profile::common::directory_hierarchy:
  - "C:\\SiteName"
  - "C:\\SiteName\\Config"
profile::common::system: "common"

在配置文件模块清单 /etc/puppet/environments/production/modules/profile/manifests/common.pp

class profile::common (
      $directory_hierarchy      =undef,
      $system                   =undef
  )
{
  notify { "Dir is- $directory_hierarchy my fqdn is $fqdn, system = $system": }
}

木偶配置/etc/puppet/puppet.config

[main]
    logdir = /var/log/puppet
    rundir = /var/run/puppet
    ssldir = $vardir/ssl
    privatekeydir = $ssldir/private_keys { group = service }
    hostprivkey = $privatekeydir/$certname.pem { mode = 640 }
    autosign       = $confdir/autosign.conf { mode = 664 }
    show_diff     = false
    hiera_config = $confdir/hiera.yaml
[agent]
    classfile = $vardir/classes.txt
    localconfig = $vardir/localconfig
    default_schedules = false
    report            = true
    pluginsync        = true
    masterport        = 8140
    environment       = production
    certname          = puppet024.novalocal
    server            = puppet024.novalocal
    listen            = false
    splay             = false
    splaylimit        = 1800
    runinterval       = 1800
    noop              = false
    configtimeout     = 120
    usecacheonfailure = true
[master]
    autosign       = $confdir/autosign.conf { mode = 664 }
    reports        = foreman
    external_nodes = /etc/puppet/node.rb
    node_terminus  = exec
    ca             = true
    ssldir         = /var/lib/puppet/ssl
    certname       = puppet024.novalocal
    strict_variables = false
    environmentpath  = /etc/puppet/environments
    basemodulepath   = /etc/puppet/environments/common:/etc/puppet/modules:/usr/share/puppet/modules
    parser = future

更有趣的是,如果在没有工头的情况下部署相同的代码,它将起作用。也许我错过了一些配置或插件?

4

1 回答 1

0

您需要一个环境(production在您的示例中)文件夹结构如下:

/etc/puppet/hiera/environments/production/node/%{::fqdn}.yaml
/etc/puppet/hiera/environments/production/profile/%{calling_class}.yaml
/etc/puppet/hiera/environments/production/production/*.yaml
/etc/puppet/hiera/environments/production/%{::osfamily}.yaml
/etc/puppet/hiera/environments/common.yaml

所以你粘贴的环境路径也是错误的。

/etc/puppet/hiera/production/profile/common.yaml

旁注

乍一看,不应将 hieradata 与 modulepath 混合,因此如果可以,请将模块移出 basemodulepath

basemodulepath   = /etc/puppet/environments/common

使用您粘贴的 puppet.conf,真正的配置文件模块路径位于三个文件夹之一:

/etc/puppet/environments/common/modules/profile
/etc/puppet/modules/profile
/usr/share/puppet/modules/profile
于 2015-03-28T11:03:49.493 回答