You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Bolt的apply块中获取当前目标以设置Puppet的certname参数

你可以直接使用Bolt在apply块中自动注入的内置特殊变量$target获取当前执行目标,调用$target.name即可拿到目标名称,直接填充到certname的取值位置即可。

修改后的完整代码如下:

# @summary This plan installs Puppet and configure it to use emypuppet-master.local as Puppet master
# @param targets The targets to run on.
plan puppet_bootstrapping::install_and_configure (
  TargetSpec $targets,
) {
  out::message("Installing Puppet")

  apply_prep($targets)

  apply($targets, '_description' => 'Configuring Puppet') {
    class {'::puppet_agent':
      manage_repo => false,
      config => [
        {section => main, setting => runinterval, value => '30m'},
        {section => main, setting => environment, ensure => absent},
        {section => main, setting => servername, value => 'mypuppet-master.local'},
        {section => main, setting => certname, value => $target.name}
      ]
    }
  }
}

补充说明:$target变量不需要额外定义,Bolt在为每个目标执行apply逻辑时会自动将当前目标的实例赋值给该变量,除了name属性外,你也可以通过该变量获取目标的连接配置、自定义标签、内置Facts等其他信息。

内容的提问来源于stack exchange,提问作者Frédéric Praca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 17:36:03