【发布时间】:2015-06-26 22:17:09
【问题描述】:
我设置了 Vagrant,它使用 Puppet 作为配置器,使用 Puppet 脚本设置 MySQL、PHP 等,但 Puppet 脚本具有密码、地址等的硬编码值。
我想将它们拉出来并将它们存储在 Vagrantfile 旁边的外部文件中(不嵌套在 Puppet 文件夹中)。
我认为这就是 Hiera 的用途,但在尝试解决我的问题时无法理解文档。有什么建议吗?
【问题讨论】:
我设置了 Vagrant,它使用 Puppet 作为配置器,使用 Puppet 脚本设置 MySQL、PHP 等,但 Puppet 脚本具有密码、地址等的硬编码值。
我想将它们拉出来并将它们存储在 Vagrantfile 旁边的外部文件中(不嵌套在 Puppet 文件夹中)。
我认为这就是 Hiera 的用途,但在尝试解决我的问题时无法理解文档。有什么建议吗?
【问题讨论】:
我发现this worked example 是关于如何使用 Hiera 和 Puppet 进行节点特定配置的非常好的入门书。
上面的例子基本上让你从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
这表示要在/etc/puppet/hieradata/node/%{::fqdn}.yaml(例如/etc/puppet/hieradata/node/kermit.example.com.yaml)下加载任何YAML 配置文件,并且在第一步中找不到所需的配置选项,然后从/etc/puppet/hieradata/common.yaml 中提取任何剩余的配置数据。
YAML 文件本身的定义如下:
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
【讨论】: