Puppet 6和模块puppetlabs / accounts hiera yaml不填充内容

问题描述 投票:0回答:1

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

---
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的更多详细信息

为什么这不起作用?

附: This question continues to

puppet
1个回答
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'

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

欲了解更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.