本文介绍了Puppet 6 和模块 puppetlabs/accounts hiera yaml 不填充内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的用户帐户定义为 Hiera 中的哈希,如下所示:

I am attempting to define my user accounts as Hashes in Hiera, like this:

---
accounts::user:
  jack:
    ensure: present
    bashrc_content: file('accounts/shell/bashrc')
    bash_profile_content: file('accounts/shell/bash_profile')

如果我在 *.pp 文件中定义它们就可以正常工作.

It works fine if I define them in my *.pp files.

请在 Gist 上找到有关 hiera.yaml、manifest 和 users.yamal 的更多详细信息

Please, find more details about hiera.yaml, manifest and users.yamal on Gist

为什么这不起作用?

附言这个问题继续,

推荐答案

不,您尝试执行的操作是不可能的.

No, what you are trying to do is not possible.

我有几个选项供您选择.在 Hiera 中,您可以拥有除调用 file() 函数之外的所有数据:

I have a few options for you. In Hiera, you could have all of the data other than the call to the file() function:

---
accounts::user:
  jack:
    locked: false
    comment: Jack Doe
    ensure: present
    groups:
    - admins
    - sudo
    shell: '/bin/bash'
    home_mode: '0700'
    purge_sshkeys: false
    managehome: true
    managevim: false
    sshkeys:
    - ssh-rsa AAAA
    password: '70'

然后在您的清单中:

$defaults = {
  'bashrc_content' => file('accounts/shell/bashrc'),
  'bash_profile_content' => file('accounts/shell/bash_profile'),
}

$user_data = lookup('accounts::user', Hash[String,Hash], 'hash', {})
$user_data.each |$user,$props| {
  accounts::user { $user: * => $props + $defaults }
}

另一种选择是简单地将您的文件内容包含在 YAML 数据中,即

Another option is to simply include your file content in the YAML data, i.e.

---
accounts::user:
  jack:
    locked: false
    comment: Jack Doe
    ensure: present
    groups:
    - admins
    - sudo
    shell: '/bin/bash'
    home_mode: '0700'
    purge_sshkeys: false
    managehome: true
    managevim: false
    bashrc_content: |
      # If not running interactively, don't do anything
      [ -z "$PS1" ] && return

      if [ -f /etc/bashrc ]; then
        . /etc/bashrc   # --> Read /etc/bashrc, if present.
      fi
      ...
    bash_profile_content: ...
    sshkeys:
    - ssh-rsa AAAA
    password: '70'

那么您将根本不需要文件功能或文件.

Then you won't need the file function or the files at all.

更多信息:

  • On what you can interpolate in Hiera data.
  • The splat operator (*) and a useful blog on how to use it.
  • On multiline-strings in YAML.

这篇关于Puppet 6 和模块 puppetlabs/accounts hiera yaml 不填充内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 08:21