【问题标题】:Puppet 6 and module puppetlabs/accounts hiera yaml does not fill contentPuppet 6 和模块 puppetlabs/accounts hiera yaml 不填充内容
【发布时间】:2019-03-08 07:41:01
【问题描述】:

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

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

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

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

为什么这不起作用?

附: This question continues to,

【问题讨论】:

    标签: puppet


    【解决方案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'
    

    那么你就不需要文件功能或文件了。

    更多信息:

    • what 上,您可以在 Hiera 数据中进行插值。
    • splat 运算符 (*) 和有用的 blog 说明如何使用它。
    • 在 YAML 中打开 multiline-strings

    【讨论】:

    • 非常感谢!它运作良好,迫使我学习 Puppet :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    相关资源
    最近更新 更多