Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-7362

Improve handling of facts and $trusted in CLI apps for Puppet lookup

    Details

    • Type: Improvement
    • Status: Needs Information
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: PUP 4.9.4
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      CentOS 7

    • QA Risk Assessment:
      Needs Assessment

      Description

      Hi,

      This issue was orginaly posted on Pupepet user lsit https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/puppet-users/0Pgxjk5Ru4I/goQU3tz3BQAJ . Being suggested by Eric Thompson and Henrik Lindberg, I file a ticket for PUP here.

      After upgrading opensource Puppet to version 4.9.4, I followed the Hiera guide https://docs.puppet.com/puppet/4.9/hiera_hierarchy.html#most-hierarchies-interpolate-variables to feed some data to it. I found that for some node, 'puppet lookup' failed to interpolate variables in yaml setting, which lead to incorrect lookup results.

      Steps to reproduce this issue

      1. Install Puppet server on puppet.pi.sjtu.edu.cn .
      2. Install Puppet agents on puppet.pi.sjtu.edu.cn, slurm1.pi.sjtu.edu.cn and mu05.pi.sjtu.edu.cn. Sign certificates for them.
      3. Delete global hiera setting `/etc/puppetlabs/code/hiera.yaml`.

      1. rm -f /etc/puppetlabs/code/hiera.yaml

      4. Create an environment named `production`.

      1. mkdir -p /etc/puppetlabs/code/environments/production/ {hieradata,maifests,modules}

      5. Create the Hiera conf file for the production environment in `/etc/puppetlabs/code/environments/production/hiera.yaml`

      ---
      version: 5
      defaults:
        datadir: hieradata
        data_hash: yaml_data
       
      hierarchy:
        - name: "Per-node data"
          path: "nodes/%{trusted.certname}.yaml"
       
        - name: "common"
          path: "common.yaml"
      

      6. Add common data in `/etc/puppetlabs/code/environments/production/hieradata/common.yaml`:

      ---
      group: Compute Nodes
      

      7a. Add per-node hiera data for slurm1.pi.sjtu.edu.cn in `/etc/puppetlabs/code/environments/production/hieradata/nodes/slurm1.pi.sjtu.edu.cn.yaml`:

      ---
      group: SLURM
      

      7b. Add per-node hiera data for puppet.pi.sjtu.edu.cn in `/etc/puppetlabs/code/environments/production/hieradata/nodes/puppet.pi.sjtu.edu.cn.yaml`:

      ---
      group: Puppet Server
      

      8a. Lookup group for puppet.pi.sjtu.edu.cn and successfully get "Puppet Server" stored in `puppet.pi.sjtu.edu.cn.yaml`.

      # puppet lookup group --node puppet.pi.sjtu.edu.cn --explain
      Searching for "lookup_options"
        Global Data Provider (hiera configuration version 5)
          No such key: "lookup_options"
        Environment Data Provider (hiera configuration version 5)
          Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
          Merge strategy hash
            Hierarchy entry "Per-node data"
              Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/puppet.pi.sjtu.edu.cn.yaml"
                Original path: "nodes/%{trusted.certname}.yaml"
                No such key: "lookup_options"
            Hierarchy entry "common"
              Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
                Original path: "common.yaml"
                No such key: "lookup_options"
      Searching for "group"
        Global Data Provider (hiera configuration version 5)
          No such key: "group"
        Environment Data Provider (hiera configuration version 5)
          Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
          Hierarchy entry "Per-node data"
            Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/puppet.pi.sjtu.edu.cn.yaml"
              Original path: "nodes/%{trusted.certname}.yaml"
              Found key: "group" value: "Puppet Server"
      

      8b. Lookup group for puppet.pi.sjtu.edu.cn and successfully get "Compute Nodes" stored in `common.yaml`.

      # puppet lookup group --node mu05.pi.sjtu.edu.cn --explain
      Searching for "lookup_options"
        Global Data Provider (hiera configuration version 5)
          No such key: "lookup_options"
        Environment Data Provider (hiera configuration version 5)
          Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
          Merge strategy hash
            Hierarchy entry "Per-node data"
              Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/mu05.pi.sjtu.edu.cn.yaml"
                Original path: "nodes/%{trusted.certname}.yaml"
                Path not found
            Hierarchy entry "common"
              Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
                Original path: "common.yaml"
                No such key: "lookup_options"
      Searching for "group"
        Global Data Provider (hiera configuration version 5)
          No such key: "group"
        Environment Data Provider (hiera configuration version 5)
          Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
          Hierarchy entry "Per-node data"
            Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/mu05.pi.sjtu.edu.cn.yaml"
              Original path: "nodes/%{trusted.certname}.yaml"
              Path not found
          Hierarchy entry "common"
            Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
              Original path: "common.yaml"
              Found key: "group" value: "Compute Nodes"
      

      8c. Lookup group for slurm1.pi.sjtu.edu.cn and fail to interpolate %{trusted.certname}
      which results in incorrect lookup fallback to `common.yaml`. It is expected to use `slurm1.pi.sjtu.edu.cn.yaml` and the correct result should be "SLURM", not "Compute Nodes".

      # puppet lookup group --node slurm1.pi.sjtu.edu.cn --explain
      Searching for "lookup_options"
        Global Data Provider (hiera configuration version 5)
          No such key: "lookup_options"
        Environment Data Provider (hiera configuration version 5)
          Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
          Merge strategy hash
            Hierarchy entry "Per-node data"
              Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/.yaml"
                Original path: "nodes/%{trusted.certname}.yaml"
                Path not found
            Hierarchy entry "common"
              Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
                Original path: "common.yaml"
                No such key: "lookup_options"
      Searching for "group"
        Global Data Provider (hiera configuration version 5)
          No such key: "group"
        Environment Data Provider (hiera configuration version 5)
          Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
          Hierarchy entry "Per-node data"
            Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/.yaml"
              Original path: "nodes/%{trusted.certname}.yaml"
              Path not found
          Hierarchy entry "common"
            Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
              Original path: "common.yaml"
              Found key: "group" value: "Compute Nodes"
      

        Attachments

          Activity

            People

            • Assignee:
              l.smith Lindsey Smith
              Reporter:
              weijianwen Jianwen Wei
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:

                Zendesk Support