标签: hiera

如何设置 :datadir: 将 Hiera 与 Puppet 和 Vagrant 一起使用时

我想知道如何建立:datadir:hiera.yaml与日伪和流浪最佳利用。目前我在 Ubuntu 13.10 上使用 vagrant 1.5.0 和 virtualbox 4.2,Ubuntu 12.04 来宾运行 puppet 3.1.1

我正在尝试设置一个类似于这篇博文Puppet Best Practices: Environment specific configs 的环境。具体来说,我的 Vagrantfile 包含:

  config.vm.define "servername" do |servername|
    servername.vm.box = "precise-puppet-3"
    servername.vm.network "private_network", ip: "192.168.213.2",
      virtualbox__intnet: "networkname"

    # Provision with puppet.
    servername.vm.provision :puppet do |puppet|
      puppet.hiera_config_path = "puppet/hiera.yaml"
      puppet.manifests_path = "puppet/manifests"
      puppet.module_path = "puppet/modules"
      puppet.manifest_file  = "servername.pp"
      puppet.facter = {
        "vagrant" => "1",
        "server" => "servername",
      }
    end
  end
Run Code Online (Sandbox Code Playgroud)

我可以确认hiera_config_path是正确的,因为如果我删除hiera.yaml.

puppet/hiera.yaml 包含: …

puppet vagrant hiera

10
推荐指数
1
解决办法
1万
查看次数

如何从层次结构的其他地方引用 hiera 变量?

因此,假设在一个非常具体的 hiera YAML 文件中,我定义了一个变量,例如“env_name”。

env_name:“开发不稳定”

现在在一个更通用的 hiera 文件中,我想将该变量插入到一个字符串中。

server_name: "service-%{env_name}.%{::domain}"

我的测试似乎暗示来自层次结构中其他地方的 hiera 变量在一般情况下不可用于插值。不幸的是,这是真的吗?

puppet hiera

8
推荐指数
2
解决办法
6936
查看次数

验证人偶的 hiera 查找

在尝试调试我的 puppet manifests 与 hiera 捆绑后无数次的过程中,有时我怀疑是否正在执行正确的 hiera 查找。

我主要使用 CentOS 和 Puppet 3。

有什么工具可以用来找出我所在节点当前使用的 hiera 数据文件,而不是尝试根据我的服务器配置进行猜测?

puppet hiera

7
推荐指数
1
解决办法
3224
查看次数

基于模式的 Hiera 查找

我正在努力思考如何从我在大型 site.pp 文件中所做的事情转换为我可以在 hiera 中使用的结构。通过阅读 puppet 文档,我不清楚如何评估 hiera 数据以及何时适合图片。我最近从 puppet 2.7.x 升级到 3.3.x。这包括 hiera 作为标准包的一部分,所以我想最终考虑使用它,因为它应该使我的设置更易于阅读/理解。

我正在使用多个外部组织来支持系统。这包括配置每个组织独有的系统。在我的 site.pp 的顶部,我有一个如下所示的结构。我使用它根据与 clientcert 事实匹配的正则表达式为每个组织设置事实,这些事实以可靠地识别每个组织的方式配置和发布。

# match organization
case $::clientcert {

  /.*example1.org/ :
      { $snmp_ro_community='...'
        $snmp_location='Example Org 1' 
        ... }
  /.*example2.org/ :
      { $snmp_ro_community='...'
        $snmp_location='Example Org 2' 
        ... }
  /.*example3.org/ :
      { $snmp_ro_community='...'
        $snmp_location='Example Org 3' 
        ... }
  /.*example4.org/ :
      { $snmp_ro_community='...'
        $snmp_location='Example Org 4' 
        ... }
}
Run Code Online (Sandbox Code Playgroud)

我浏览了示例,但在 hiera.yaml 文件中看不到任何方法可以进行任何类型的模式匹配。我怀疑我一定遗漏了一些明显的东西。

我不想为此依赖自定义事实。我更喜欢坚持使用客户端证书,因为我确信这将正确识别组织和系统,并且已经使用强密码术进行了确认。我不想将一个组织的价值观赋予另一个组织。

puppet hiera

7
推荐指数
1
解决办法
5486
查看次数

Puppet&Hiera:$variable 在访问时不是散列或数组

我使用的是 Puppet 3.2.2 和 Hiera 1.2.1。我写了一个 puppet 模块,init.pp 的内容是:

class install(
  $common_instanceconfig = hiera_hash('common_instanceconfig'),
  $common_instances = hiera('common_instances')
)
{

  define instances {

    common { $title:
      name       => $title,
      path       => $common_instanceconfig[$title]['path'],
      version    => $common_instanceconfig[$title]['version'],
      files      => $common_instanceconfig[$title]['files'],
      pre        => $common_instanceconfig[$title]['pre'],
      after      => $common_instanceconfig[$title]['after'],
      properties => $common_instanceconfig[$title]['properties'],
      require    => $common_instanceconfig[$title]['require'] ,

    }
  }

  instances {$common_instances:}
}
Run Code Online (Sandbox Code Playgroud)

而 hieradata 文件是:

classes:
  - install

common_instances:
  - common_instance_1
  - common_instance_2

common_instanceconfig:
  common_instance_1
    path      : '/opt/common_instance_1'
    version   : 1.0
    files     : software-1.bin
    pre       : pre_install.sh …
Run Code Online (Sandbox Code Playgroud)

puppet hiera

6
推荐指数
1
解决办法
8168
查看次数

hiera 数据源使用 puppet 语法?

docs.puppetlabs.com 上的 hiera文档似乎给我的印象是我可以使用 puppet 语法来描述我的数据。或者将来可能会。见:Coming soon

此功能是否存在于 puppet 的发布版本中,只是没有记录,还是仍在开发中?如果存在此功能,是否有人有如何实际使用它的示例?

我的系统上存在puppet_backend.rb文件,它是 puppetmaster 包的一部分,这让我觉得这个功能存在,但只是没有记录。所以我想弄清楚如何实际使用它。

puppet hiera

5
推荐指数
1
解决办法
672
查看次数

hiera_include 等效于资源类型

我正在使用yumrepo内置类型。我可以获得与 hiera 工作的基本集成

  yumrepo { hiera('yumrepo::name') :
    metadata_expire => hiera('yumrepo::metadata_expire'),
    descr           => hiera('yumrepo::descr'),
    gpgcheck        => hiera('yumrepo::gpgcheck'),
    http_caching    => hiera('yumrepo::http_caching'),
    baseurl         => hiera('yumrepo::baseurl'),
    enabled         => hiera('yumrepo::enabled'),
  }
Run Code Online (Sandbox Code Playgroud)

如果我尝试删除该定义并改为 for hiera_include('classes'),这就是我在相应的 yaml 后端中得到的

classes:
 - "yumrepo"

yumrepo::metadata_expire: 0
yumrepo::descr: "custom repository"
yumrepo::gpgcheck: 0
yumrepo::http_caching: none
yumrepo::baseurl: "http://myserver/custom-repo/$basearch"
yumrepo::enabled: 1
Run Code Online (Sandbox Code Playgroud)

我在代理上收到此错误

服务器上的错误 400:找不到 yumrepo 类

我猜您无法摆脱某种带有 hiera 和资源类型的最小节点声明?也许hiera_hash是要走的路?

我试了一下,但它产生了语法错误

  yumrepo { 'hnav-development':
    hiera_hash('yumrepo')
  }
Run Code Online (Sandbox Code Playgroud)

puppet hiera

5
推荐指数
1
解决办法
4158
查看次数

在 Ansible 中使用 hiera 作为 ENC 的等价物是什么?

我在 Puppet 中使用 hiera 作为外部节点分类器,以避免将角色部署在例如不兼容的节点上。现在我有两台使用 Ansible 配置的服务器。我担心当集群增长时,我必须检查哪些节点可用,然后决定应该应用什么角色而不是自动执行的 hiera。例如,系统 A 是开发人员系统和部署开发角色,系统 B 是 db 系统部署数据库角色。

ansible hiera

5
推荐指数
1
解决办法
1321
查看次数

在无主设置中使用 hiera 并获取为类设置的值时遇到问题

我正在运行一个 masterless puppet 设置,它以以下方式应用 puppet 更改。

puppet apply /tmp/puppet/manifests/site.pp --modulepath=/tmp/puppet/modules --hiera_config=/tmp/puppet/hiera.yaml
Run Code Online (Sandbox Code Playgroud)

我一直在尝试在 hiera 中处理我们拥有的不同类型的节点,并且作为起点,我一直在尝试使用在节点上设置的自定义事实。这个事实是节点类型,在这个例子中被设置为无盘值。

节点上的因素认识到这一事实。

# facter -y | grep nodetype
nodetype: diskless
Run Code Online (Sandbox Code Playgroud)

并且 hiera.yaml 包含以下内容

---
:backends:
  - yaml
:yaml:
  :datadir: /tmp/puppet/data
:hierarchy:
  - node/%{::nodetype}
Run Code Online (Sandbox Code Playgroud)

在 /tmp/puppet/data/node/diskless.yaml 有

---
cluster: blues
Run Code Online (Sandbox Code Playgroud)

虽然这样做之后我尝试仔细检查 hiera 然后根据需要设置变量,但它似乎不起作用。

hiera -y diskless.yaml cluster
nil
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来调试问题。我相信这很简单,但如果 hiera 不能(或不能)在这个用例中运行会令人失望。

干杯

编辑1:

附加调试

hiera cluster '::nodetype=diskless' -d
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Hiera YAML backend starting
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Looking up …
Run Code Online (Sandbox Code Playgroud)

puppet facter hiera

4
推荐指数
1
解决办法
2842
查看次数

使用 hiera 访问另一个节点的事实

我们要做的是为 iptables 生成防火墙规则(puppetlabs/firewall)。我们的节点在概念上是这样分组的:

-- site1
---- shared1
------ specific1
------ specific2
---- shared2
------ specific3
------ specific4
Run Code Online (Sandbox Code Playgroud)

节点“specific4”将始终需要访问“shared2”上的端口 8080 和“site1”上的端口 10000。“specific1”同样需要访问“shared1”上的8080。每个节点的规则总是相同的,但它们将取决于它们属于哪个组。

我正在努力寻找一种方法来在 hiera 中不重复地表示这一点。是否可以从完全独立的节点获取事实?

我想我希望能够做这样的事情(简化):

--
hosts:
  host specific4:
    rules:
      rule:
        port: 8080
        ip: get_ip(get_my_shared())
Run Code Online (Sandbox Code Playgroud)

但显然,您不能从yaml文件中调用函数。最好的方法是使用自定义事实吗?我还没有真正使用过 hiera - 所以我不确定最佳实践和什么不是。任何朝着正确方向的温和推动将不胜感激。

编辑:

这是我采用的解决方案,但如果我可以使用导出的资源,我可以消除对 puppetdb-query 的依赖。

# helper for creating rules from an array
define firewall_rules($port, $service_type) {
    $source = $name
    firewall { "$port $service_type $source":
        proto       => 'tcp',
        dport       => $port,
        state       => 'NEW',
        source      => "$source",
        action      => 'accept' …
Run Code Online (Sandbox Code Playgroud)

puppet hiera

2
推荐指数
1
解决办法
6903
查看次数

标签 统计

hiera ×10

puppet ×9

ansible ×1

facter ×1

vagrant ×1