简体   繁体   English

人偶外部配置文件?

[英]Puppet external configuration file?

I have Vagrant set up and it's using Puppet as the provisioner with Puppet scripts setting up MySQL, PHP, etc. but the Puppet scripts have the hard coded values for passwords, addresses, etc. 我已经设置了Vagrant,并且使用Puppet作为预配置程序,并使用Puppet脚本设置了MySQL,PHP等。但是Puppet脚本具有密码,地址等的硬编码值。

I'd like to pull those out and store them in a external file alongside the Vagrantfile (not nested in the Puppet folder). 我想将它们拉出并与Vagrantfile一起存储在外部文件中(不嵌套在Puppet文件夹中)。

I thought this is what Hiera was for but cannot make sense of the documentation when trying to solve my problem. 我以为这就是Hiera的目的,但是在尝试解决我的问题时无法理解文档。 Any sugggestions? 有什么建议吗?

I find that this worked example is a pretty good primer on how to use Hiera with Puppet for node specific configuration. 我发现这个工作示例很好地介绍了如何将Hiera与Puppet一起用于特定于节点的配置。

The above example basically has you go from a sites.pp file that looks like: 上面的示例基本上使您从一个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,
  }
}

To one that simply defines a list of nodes: 对于仅定义节点列表的用户:

hiera_include('classes')

node "kermit.example.com", "grover.example.com", "snuffie.example.com", "bigbird.example.com", "hooper.example.com"

The config is then inherited depending on the hierarchy defined in hiera.yaml . 然后根据hiera.yaml定义的层次结构继承配置。 In their example they simply use this: 在他们的示例中,他们只是使用以下代码:

---
:backends:
  - yaml
:yaml:
  :datadir: /etc/puppet/hieradata
:hierarchy:
  - "node/%{::fqdn}"
  - common

Which says to load any YAML config files under /etc/puppet/hieradata/node/%{::fqdn}.yaml (for example, /etc/puppet/hieradata/node/kermit.example.com.yaml ) and where needed config options aren't found in this first step then to pull any remaining config data in from /etc/puppet/hieradata/common.yaml . 这表示要在/ /etc/puppet/hieradata/node/%{::fqdn}.yaml (例如/etc/puppet/hieradata/node/kermit.example.com.yaml )下加载任何YAML配置文件在第一步中找不到config选项,然后从/etc/puppet/hieradata/common.yaml提取所有剩余的配置数据。

The YAML files themselves are then defined like: 然后,YAML文件本身的定义如下:

kermit.example.com.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 : common.yaml

---
classes: ntp
ntp::autoupdate: true
ntp::enable: true
ntp::servers:
  - grover.example.com iburst
  - kermit.example.com iburst

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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