【问题标题】:Puppet - How to write yaml files based on Role/Profile methodPuppet - 如何基于 Role/Profile 方法编写 yaml 文件
【发布时间】:2021-04-13 09:42:49
【问题描述】:

我已将我们的基础架构设置添加到 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 并进行木偶查找,它工作正常,但我无法将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 管理代码.

【问题讨论】:

  • 我没有看到您提供的任何明显错误,但如果没有minimal reproducible example,我不能说更多。
  • 已编辑问题,希望对您有所帮助。谢谢!
  • 我不知道这里到底发生了什么,但是您描述的 puppet lookup 行为与您在 Puppet 所依赖的数据层次结构中呈现的 Hiera 数据不一致。您是否以运行 puppetserver 进程的同一用户身份运行这些 puppet lookup 命令?
  • @JohnBollinger 所有文件均已使用 root 编辑,puppet lookup 也使用 root 运行
  • 文件的编辑方式无关紧要。它们的名称和位置、适用的 Hiera 配置以及执行查找的 puppet 进程的 UID 都很重要。我仍在等待那个 MRE——点击上面的超链接,了解更多关于我们所说的这个术语的含义以及构建它的方法的信息。

标签: linux puppet hiera


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-07-07
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2017-11-28
    • 2014-04-11
    • 1970-01-01
    相关资源
    最近更新 更多