微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Puppet - 如何根据 Role/Profile 方法编写 yaml 文件

如何解决Puppet - 如何根据 Role/Profile 方法编写 yaml 文件

我已将我们的基础设施设置添加到 puppet,并使用了角色和配置文件方法。每个配置文件都驻留在一个组中,基于它们的性质。比如 Chronyd setup 和 Message of the day 在“base”组,Nginx相关的配置在“app”组。此外,在角色上,每个配置文件添加到相应的组中。例如对于 memcached,我们有以下内容

class role::prod::memcache inherits role::base::debian {

  include profile::app::memcache
}

profile::app::memcached 的设置如下:

class profile::app::memcache {

  service { 'memcached':
    ensure => running,enable => true,hasrestart => true,hasstatus  => true,}
}

对于 role::base::debian 我有

class role::base::debian {

  include profile::base::motd
  include profile::base::chrony

}

事实证明,上述结构对于我们的基础架构来说足够灵活。添加服务和创建新角色再简单不过了。但现在我面临一个新的问题。我一直在尝试将数据与逻辑分开,使用 Hiera 版本 5 编写一些 yaml 文件以将数据保存在那里。通过互联网浏览了几天,但我无法根据结构推断出如何编写我的 hiera 文件我有。我尝试将 profile::base::motd 添加到 common.yaml 并进行了 puppet 查找,它工作正常,但我无法将 chrony 附加到 common.yaml。 Puppet 查找不返回以下 common.yaml 内容

---
profile::base::motd::content: This server access is restricted to authorized users only. All activities on this system are logged. Unauthorized access will be liable to prosecution.'
profile::base::chrony::servers: 'ntp.centos.org'
profile::base::chrony::service_enable: 'true'
profile::base::chrony::service_ensure: 'running'

Motd 查找工作正常。但其余的,没有运气。 puppet lookup profile::base::chrony::servers 没有输出返回。不知道我在这里缺少什么。非常感谢社区对此的帮助。

此外,使用hiera,以下代码是否足以用于服务傀儡文件

class profile::base::motd {

        class { 'motd':
        }
}

PS:我知道我可以在模块中添加 yaml 文件来保存数据,但我希望我的 .yaml 文件位于一个地方(例如 $PUPPET_HOME/environment/production/data),以便我可以使用 git 管理代码.

解决方法

问题是在 puppet 模块本身内的 init.pp 文件中,变量 $content 被分配了一个值。删除值解决了问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。