Puppet外部配置文件?

时间:2015-06-26 22:17:09

标签: vagrant puppet hiera

我有Vagrant设置,它使用Puppet作为配置器,Puppet脚本设置MySQL,PHP等,但Puppet脚本具有密码,地址等的硬编码值。

我希望将它们拉出来并将它们存储在Vagrantfile旁边的外部文件中(不嵌套在Puppet文件夹中)。

我认为这是Hiera的用途,但在尝试解决问题时无法理解文档。任何建议?

1 个答案:

答案 0 :(得分:1)

我发现this worked example是关于如何将Hiera与Puppet一起用于节点特定配置的非常好的入门读物。

上面的例子基本上是你从0.1.3文件看起来像:

sites.pp

简单地定义节点列表:

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,
  }
}

然后根据hiera_include('classes') node "kermit.example.com", "grover.example.com", "snuffie.example.com", "bigbird.example.com", "hooper.example.com" 中定义的层次结构继承配置。在他们的例子中,他们只是使用它:

hiera.yaml

其中说要加载--- :backends: - yaml :yaml: :datadir: /etc/puppet/hieradata :hierarchy: - "node/%{::fqdn}" - common 下的任何YAML配置文件(例如,/etc/puppet/hieradata/node/%{::fqdn}.yaml),并且在第一步中找不到所需的配置选项,然后将所有剩余的配置数据拉入来自/etc/puppet/hieradata/node/kermit.example.com.yaml

然后将YAML文件本身定义为:

<强> kermit.example.com.yaml

/etc/puppet/hieradata/common.yaml

<强> common.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
相关问题