首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Puppet & Hiera层次结构和类名

Puppet & Hiera层次结构和类名
EN

Stack Overflow用户
提问于 2014-10-22 03:57:15
回答 1查看 945关注 0票数 0

Hiera中的'calling_class‘查找变量让我头疼。

给出如下的hiera配置:

代码语言:javascript
复制
---
:backends: yaml
:yaml:
  :datadir: 
:hierarchy:
  - "node/%{::clientcert}"
  - "profile/%{calling_class}"
  - "roles/%{calling_class}"
  - common
:logger: console

以及Puppet中的role.pp,包含以下内容:

代码语言:javascript
复制
class role::base {
  notify { "output scope 1":
    message => inline_template("scope='<%= scope.source.name %>'"),
  }
  $profiles = hiera_array('role::profiles', [])
  notify { "Including profiles: ${profiles}": }
  # include $profiles
}

class role::app inherits role::base{
  notify { "output scope 2":
    message => inline_template("scope='<%= scope.source.name %>'"),
  }
  $profiles = hiera_array('role::profiles', [])
  notify { "Including profiles: ${profiles}": }
}

和一个包含以下内容的roles/role::app.yaml

代码语言:javascript
复制
---
role::profiles:
  - webserver
  - application

我预计会看到这样的情况:

代码语言:javascript
复制
Notice: Including profiles: webapp
Notice: scope='role::app'
Notice: Including profiles: webapp
Notice: scope='role::app'
Notice: Finished catalog run in 0.11 seconds

但这就是我所得到的:

代码语言:javascript
复制
Notice: Including profiles: 
Notice: scope='role::base'
Notice: Including profiles: webapp
Notice: scope='role::app'
Notice: Finished catalog run in 0.11 seconds

似乎当一个类被继承(或包含,两者都是一样的)时,Hiera中的'calling_class‘被设置为继承的类,而不是继承的类。我是不是漏掉了什么,或者这就是Hiera的工作方式?我认为继承一个类会将scope.source.name设置为子类,而不是父类。

EN

回答 1

Stack Overflow用户

发布于 2016-02-13 00:48:59

您也可以使用此解决方案。唯一的缺点是角色的最大数量是硬编码的。在使用Hiera3之前,这会更好,然后尝试这样做:

/etc/puppet/itera.yaml

代码语言:javascript
复制
 ---
:backends:
  - yaml
:yaml:
  :datadir: /etc/puppet/hieradata
:hierarchy:
  - 'nodes/%{::clientcert}'
  - 'roles/%{::role_4}'
  - 'roles/%{::role_3}'
  - 'roles/%{::role_2}'
  - 'roles/%{::role_1}'
  - common

/etc/puppet/manifests/site.pp

代码语言:javascript
复制
# Get roles
$roles = hiera_array('roles', [])

# Declare Roles in vars (not needed in puppet 4)
$role_1 = $roles[0]
$role_2 = $roles[1]
$role_3 = $roles[2]
$role_4 = $roles[3]

# Include Classes
hiera_include('classes')

/etc/puppet/hieradata/roles/webserver.yaml

代码语言:javascript
复制
---
classes:
  - nginx

# put nginx config here

/etc/puppet/hieradata/nodes/your_node_name.yaml

代码语言:javascript
复制
---
roles:
 - webserver

classes:
# put node specific stuff here
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26495194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档