人偶6和模块人偶/帐户hiera yaml不填充内容

时间:2019-03-08 07:41:01

标签: puppet

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

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

如果我在* .pp文件中定义它们,效果很好。

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

为什么不起作用?

P.S。 This question continues to

1 个答案:

答案 0 :(得分:1)

不,您尝试做的事是不可能的。

我为您提供一些选择。在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'

那么您完全不需要文件功能。

有关更多信息: