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

defined function does not work on structured facts

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Do
    • Affects Version/s: PUP 5.5.0
    • Fix Version/s: None
    • Component/s: Functions
    • Labels:
      None
    • Template:
      PUP Bug Template
    • Method Found:
      Needs Assessment
    • QA Risk Assessment:
      Needs Assessment

      Description

      To avoid 'Puppet Unknown variable' warnings for facts that may not exist, we have some code like:

      if defined('$::somepossiblefact') {
       # do something
      }

      This works fine for flat facts but not structured ones. I've tried various quoting solutions within the required single quotes, but nothing seems to work. Consider the following example:

      [root@host ~]# cat test.pp
      if defined('$::memory["swap"]["total"]')
      or defined('$::memory[swap][total]')
      or defined('$::memory[\'swap\'][\'total\']')
      or defined('$::memory[\'swap\'][\'total\']')

      {   notice('structured fact caught by defined()') }

      if $::memory['swap']['total']

      {   notice('structured fact caught outside defined()') }

      [root@host ~]#
      [root@host ~]# puppet apply test.pp
      Notice: Scope(Class[main]): structured fact caught outside defined()
      Notice: Compiled catalog for host.domain.com in environment production in 0.02 seconds
      Notice: Applied catalog in 1.15 seconds
      [root@host ~]#

       

       

       

        Attachments

          Activity

            People

            Assignee:
            henrik.lindberg Henrik Lindberg
            Reporter:
            rjd1 Ryan Dill
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support