在 apply 块中使用当前目标

Using current target inside apply block

我想知道是否可以在 Bolt 中的 apply 块中检索当前目标。

例如,我想 bootstrap 使用以下计划在远程计算机上运行 puppet:

# @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 => ????????}
      ]
    }
  }
}

如何获取 certname 值的目标名称?是否有一个特殊的值,就好像我们 运行 它在一个循环中一样?

是的!您可以像 Puppet 代码一样访问 apply 块内的事实,包括受信任的事实:

# @summary This plan installs Puppet and configure it to use mypuppet-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 => $trusted['certname']}
      ]
    }
  }
}