查找功能在Puppet的配置文件中不起作用

查找功能在Puppet的配置文件中不起作用,puppet,lookup,hiera,Puppet,Lookup,Hiera,在puppet运行期间,我在节点上的事件查看器中遇到以下错误。我怀疑问题在于我的个人资料中的查找功能不正确 Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Scconfig::Coserveradmin[SomeSettings]: parameter 'p

在puppet运行期间,我在节点上的事件查看器中遇到以下错误。我怀疑问题在于我的个人资料中的查找功能不正确

Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Scconfig::Coserveradmin[SomeSettings]:
parameter 'parameterA' expects a String value, got Undef
parameter 'parameterB' expects a String value, got Undef
parameter 'parameterC' expects a String value, got Undef
parameter 'parameterD' expects a String value, got Undef
coserveradmin是一个具有所有字符串参数的define资源。我想从Json文件中查找值

{
    "SASettings" : {
        "Watchdog" : {
            "ParameterA"            : "somevalue",
            "ParameterB"            : "somevalue"
        },
        "Serversettings" : {
            "ParameterC"            : "somevalue",
            "ParameterD"            : "somevalue",

        },
        "GeneralSettings" : {
            "ParameterE"            : "somevalue",
            "ParameterF"            : "somevalue",

        },
        "customsettings_prod" : {
            "ParameterG"            :"somevalue",
            "ParameterH"            : "%{facts.hostname}.example-cloud.com"
        },
        "customsettings_dev" : {
            "ParameterI"            :"",
            "ParameterK"            : "%{facts.hostname}.example.net"
        }
    }
}
在我的hiera.yaml文件中,我定义了json文件的名称和路径

- name: "Desired Some Settings"
    path: "default/serveradmin.json" 
在概要文件中,我有以下代码

    class profile::scconfig_someprofile_a {
                .
                .
                .
                $hname= $::facts['hostname']
                $mac= "${facts['macaddress'].delete(':')}"
                $adminpropeties = lookup('SASettings')

               if $hname=~someregex {
                           scconfig::coserveradmin{ 'SomeSettings':
                           property1 => $adminpropeties['customsettings_prod.ParameterG'],
                           property2 => $adminproperties['Watchdog.ParameterA'],
                           property3 => $adminproperties['Watchdog.ParameterB'],
                           property4 => $adminproperties['Serversettings.ParameterC'],
                           .
                           .
                           .
                           .
                           and so on
                           .
                           macaddress => $mac,

               }
               elsif $hname=~someregex {
                           scconfig::coserveradmin{ 'SomeSettings':
                           property1 => $adminpropeties['customsettings_dev.ParameterI'],
                           property2 => $adminproperties['Watchdog.ParameterA'],
                           property3 => $adminproperties['Watchdog.ParameterB'],
                           property4 => $adminproperties['Serversettings.ParameterC'],
                           .
                           .
                           .
                           .
                           and so on
                           .
                           macaddress => $mac,

               }
还将根据请求添加定义资源的代码

define scconfig::coserveradmin(
    String $Property1,
    String $Property2,
    String $Property3,
    String $Property4,
    .
    .
    .
    String $macaddress,

  ) {

  $dscmoduleversion = lookup('requires.modules.codsc.version')
  if $dscmoduleversion != '' {
      $module = {
          'name'    => 'codsc',
          'version' => $dscmoduleversion,
      }
  }else{
      $module = 'codsc'
  }

  $configname1='someconfig1'
  $configname2='someconfig2'
  $configname3='someconfig3'

  dsc { 'someconfig1':
    require       => lookup('requires.cloudopssoftware'),
    resource_name => 'Someresourcename',
    module        => $module,
    properties    => {
      configname         => $configname1,
      Prop1   => $Property1,
      Prop2   => $Property2,
      Prop3   =>$Property3,
    },
  }
  dsc { 'someconfig2':
   require       => lookup('requires.cloudopssoftware'),
   resource_name => 'someresourcename2',
   module        => $module,
   properties    => {
      configname    => $configname2,
            Prop1   => $Property4,
            Prop2   => $Property5,
            Prop3   =>$Property6,
    },
  }

 dsc { 'someconfig3':
   require       => lookup('requires.cloudopssoftware'),
   resource_name => 'someresourcename3',
   module        => $module,
   properties    => {
      configname    => $configname3,
            Prop1   => $Property6,
            Prop2   => $Property7,
            Prop3   =>$Property8,
            .
            .
            .
            Propn   => $macaddress
         },
       }
请注意,最后一个属性macaddress是在profile类中计算的,因此我没有看到任何错误

有什么想法吗?可能是什么问题

我怀疑问题在于我的个人资料中的查找功能不正确

Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Scconfig::Coserveradmin[SomeSettings]:
parameter 'parameterA' expects a String value, got Undef
parameter 'parameterB' expects a String value, got Undef
parameter 'parameterC' expects a String value, got Undef
parameter 'parameterD' expects a String value, got Undef
情况似乎并非如此。如果您的查找调用没有成功查找并返回散列,那么当您尝试提取值时,您将收到另一个错误

我想可能是您检索了错误的散列-这将取决于您的hiera配置和/或数据,而不是查找调用本身-但无论是正确的散列还是错误的散列,您试图用于从中提取数据的语法与问题中提供的散列结构不匹配。例如,这个表达式

尝试检索其键为“customsettings\u prod.ParameterG”的值,但显示的数据不包含此类键

你似乎想要的是

 $adminpropeties['customsettings_prod']['ParameterG']
它提取具有键“customsettings\u prod”的值,并且,该值本身是散列,它提取与键“ParameterG”关联的值

或者,您可能会发现从嵌套数据结构(如您的数据结构)中提取数据很方便:

dig($adminpropeties, 'customsettings_prod', 'ParameterG')

请您发布scconfig::coserveradmin的代码好吗?问题很可能出在它的参数列表上。我已经用define resource的代码更新了主描述。谢谢。coserveradmin的两个参数具有双美元符号,例如$$Property2。是吗?对不起,我的帖子有错。修好了。谢谢。我会试试这个,一两天后会告诉你的。谢谢!我尝试了“挖掘”功能,它工作得非常好。正是我需要的。但是,关于define scconfig::coserveradmin,我还有另一个问题。我有两个不同的节点运行不同的配置文件,它们调用相同的define资源。并非所有属性都需要在第一个节点上设置,反之亦然。我希望有没有办法将Define资源的一些参数设置为强制参数,但找不到方法。或者为每个不是首选方式的节点创建定义资源。您的想法是什么?@tafz,我的第一个想法是,如果您自己无法找到答案,并且该问题符合我们的正常指导原则,则应将一个单独的问题作为单独的问题提出。谢谢,我找到了我的答案。