如何在 Puppet Manifest 中使用变量?

Kir*_*ran 3 wsus environment-variables puppet puppetmaster centos7

我在 Centos 7.2 上使用 WSUS 模块和 Puppet Master。我的 Puppet 代理服务器运行的是 Windows Server 2012。

我想使用带有变量的清单。但是,当 Puppet Agent 服务器运行 puppet 代理时,它会显示“错误 400,语法错误”。我尝试重新编写清单和我能想到的每一个变化。我不断收到一些错误。

以下是清单的一个示例:

class excellent {
    class { 'wsus_client':
       $cool = 'Saturday'
    server_url => 'http://acme.com',
    auto_update_option  => 'Scheduled'
    scheduled_install_day => $cool,
    scheduled_install_hour => 1,
}
}
Run Code Online (Sandbox Code Playgroud)

我试过在大括号 {} 中分配变量。我尝试使用 $LOAD_PATH、--custom-dir 和 FACTERLIB。但我无法弄清楚如何使用这三个中的任何一个。

我想在一个地方更改变量并在其父类的范围内使用它。我该怎么办?

Aar*_*ley 7

你试过这种方法吗?

class excellent {
  $cool = 'Saturday'

  class { 'wsus_client':
    server_url => 'http://acme.com',
    auto_update_option  => 'Scheduled'
    scheduled_install_day => $cool,
    scheduled_install_hour => 1,
  }
}
Run Code Online (Sandbox Code Playgroud)

或者,这样

class excellent (
  $cool = 'Saturday'
){
  class { 'wsus_client':
    server_url => 'http://acme.com',
    auto_update_option  => 'Scheduled'
    scheduled_install_day => $cool,
    scheduled_install_hour => 1,
  }
}
Run Code Online (Sandbox Code Playgroud)

  • @StefanLasiewski 是的,第二个使 `$cool` 成为类 `excellent` 的参数。这意味着你可以在 heira 中设置它,或者在你的类声明中设置“优秀”。 (2认同)