如何在puppet中使用特定版本的dsc属性

问题描述 投票:0回答:1

我有一个场景,我必须在 puppet 中的 dsc 资源中使用特定属性以用于特定版本,而不是其他版本。

由于仅 2022 版本需要 $productbysa,其他版本不需要,因此它在 2022 年成功,但对于旧版本失败,因为“productbysa”无法识别

寻找如何在 puppet 中使用 $productbysa 执行此 dsc 资源的想法/想法,而对于其他版本,则需要排除它

  if ($install_version == "2022") {
    $productbysa = $manage_productbysa
  }
  else {
    $productbysa = false
  }

  dsc { 'SQLServer':
    resource_name => 'SqlSetup',
    module        => 'SqlServerDsc',
    properties    => {
      action              => 'Install',
      instancename        => 'mssqlserver',
      sourcepath          => $path_sql_install_media,
      suppressreboot      => true,
      features            => $features,
      **productbysa**     => $**productbysa**,
      updateenabled       => 'False',
      sqmreporting        => 'False',
      errorreporting      => 'False',
      installshareddir    => $path_sql_install_shared,
      installsharedwowdir => $path_sql_install_shared_wow,
      instancedir         => $path_sql_instance,
      sqlsvcaccount       => {
        'dsc_type'       => 'MSFT_Credential',
        'dsc_properties' => {
          'user'     => "${domain_prefix}\\${service_acct_with_dollar}",
          'password' => Sensitive($credential_service_acct[password]),
        },
      },
puppet
1个回答
0
投票

您可以使用

+
运算符进行哈希合并:

if ($install_version == "2022") {
  $productbysa = { productbysa => $manage_productbysa }
}
else {
  $productbysa = {}
}

properties    => {
  action              => 'Install',
  instancename        => 'mssqlserver',
  sourcepath          => $path_sql_install_media,
  suppressreboot      => true,
  features            => $features,
  updateenabled       => 'False',
  sqmreporting        => 'False',
  errorreporting      => 'False',
  installshareddir    => $path_sql_install_shared,
  installsharedwowdir => $path_sql_install_shared_wow,
  instancedir         => $path_sql_instance,
  sqlsvcaccount       => {
    'dsc_type'       => 'MSFT_Credential',
    'dsc_properties' => {
      'user'     => "${domain_prefix}\\${service_acct_with_dollar}",
      'password' => Sensitive($credential_service_acct[password]),
    },
  },
} + $productbysa

请注意,您还可以将第一个条件转换为选择器:

$productbysa = $install_version ? {
  '2022'  => { productbysa => $manage_productbysa },
  default => {},
}
© www.soinside.com 2019 - 2024. All rights reserved.