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

puppet lookup fails to interpolate topscope variables when an environment is specified

    XMLWordPrintable

Details

    • Hide

      The puppet lookup command should resolve topscope variables when an environment is specified on the command line in the same way it does when the environment is specified in puppet.conf.

      Show
      The puppet lookup command should resolve topscope variables when an environment is specified on the command line in the same way it does when the environment is specified in puppet.conf.
    • Phoenix
    • 2
    • Phoenix 2022-03-02, Phoenix 2022-03-16
    • Needs Assessment
    • 49053
    • 1
    • Bug Fix
    • Hide
      (Note from Heston: I've added the known issue to the docs, it will need to be removed when the fix goes live in the versions above.)

      Puppet 6.26 and 7.14 will fail to resolve toplevel facts in hiera configs when using the --environment option for puppet lookup. As a workaround use trusted facts or specify the fact value using the "facts" hash, such as "%{facts.hostname}"
      Show
      (Note from Heston: I've added the known issue to the docs, it will need to be removed when the fix goes live in the versions above.) Puppet 6.26 and 7.14 will fail to resolve toplevel facts in hiera configs when using the --environment option for puppet lookup. As a workaround use trusted facts or specify the fact value using the "facts" hash, such as "%{facts.hostname}"
    • Needs Assessment

    Description

      A regression introduced in PUP-7479 causes "puppet lookup --environment <env> <key>" to no longer set node parameters as topscope variables. If hiera.yaml is configured to interpolate based on topscope variables, such as "nodes/%{fqdn}.yaml", then the variable will be interpolated as an empty string.

      Given a basic setup:

      # tree /etc/puppetlabs/code/environments/
      /etc/puppetlabs/code/environments/
      ├── production
      └── test
          ├── data
          │   ├── common.yaml
          │   └── iron-judgement.yaml
          └── hiera.yaml
       
      3 directories, 3 files
      # cat /etc/puppetlabs/code/environments/test/hiera.yaml 
      ---
      version: 5
      hierarchy:
        - name: "node"
          paths:
            - "%{hostname}.yaml"
        - name: "common"
          paths:
            - "common.yaml"
      # cat /etc/puppetlabs/code/environments/test/data/common.yaml 
      ---
      foo: defined in common
      # cat /etc/puppetlabs/code/environments/test/data/iron-judgement.yaml 
      --- {}
      

      Then a warning is generated trying to resolve the `hostname` variable:

      # bundle exec puppet lookup -E test foo --explain
      Warning: Undefined variable 'hostname'; 
         (file & line not available)
      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/test/hiera.yaml"
          Merge strategy hash
            Hierarchy entry "node"
              Path "/etc/puppetlabs/code/environments/test/data/.yaml"
                Original path: "%{hostname}.yaml"
                Path not found
            Hierarchy entry "common"
              Path "/etc/puppetlabs/code/environments/test/data/common.yaml"
                Original path: "common.yaml"
                No such key: "lookup_options"
      

      Note the path "/etc/puppetlabs/code/environments/test/data/.yaml"

      The issue does not occur when an environment is omitted from the command line or when hiera interpolation uses facts such as "nodes/%{facts.hostname}.yaml".

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              josh Josh Cooper
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support