Puppet 6和模块PuppetLabs/Accounts Hiera Yaml不填充内容



我试图将我的用户帐户定义为Hiera中的哈希,例如:

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

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

请找到有关hiera.yaml,清单和用户的更多详细信息。

为什么不起作用?

P.S。这个问题继续,

不,您要做的是不可能的。

我有一些选择。在Hiera中,您可以拥有除了呼叫file()函数以外的所有数据:

---
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数据中,即

---
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'

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

有关更多信息:

  • 关于您可以在Hiera数据中插值的内容。
  • SPLAT运算符(*)和一个有用的博客。
  • YAML中的多弦。

最新更新