Using current target inside apply block

110 Views Asked by At

I'd like to know if it possible to retrieve the current target inside an apply block in Bolt.

For example, I'd like to bootstrap puppet on remote machine using the following plan:

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

How do I get the name of the target for the certname value ? Is there a special value as if we were running it in a loop ?

1

There are 1 best solutions below

0
On BEST ANSWER

Yep! You can access facts inside an apply block just like Puppet code, including trusted facts:

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