lib/bolt/application.rb
# Apply Puppet manifest code to a list of targets.
#
# @param manifest [String, NilClass] The path to a Puppet manifest file.
# @param targets [Array[String]] The targets to run on.
# @param code [String] Puppet manifest code to apply.
# @param noop [Boolean] Whether to apply in no-operation mode.
# @return [Bolt::ResultSet]
#
Apply Puppet manifest code to a list of targets.
Apply Puppet manifest code to a list of targets .
def apply(manifest, targets, code: '', noop: false)
      manifest_code = if manifest
                        Bolt::Util.validate_file('manifest', manifest)
                        File.read(File.expand_path(manifest))
                      else
                        code
                      end
      targets = inventory.get_targets(targets)
      Puppet[:tasks] = false
      ast = pal.parse_manifest(manifest_code, manifest)
      if defined?(ast.body) &&
         (ast.body.is_a?(Puppet::Pops::Model::HostClassDefinition) ||
         ast.body.is_a?(Puppet::Pops::Model::ResourceTypeDefinition))
        message = "Manifest only contains definitions and will result in no changes on the targets. "\
                  "Definitions must be declared for their resources to be applied. You can read more "\
                  "about defining and declaring classes and types in the Puppet documentation at "\
                  "https://puppet.com/docs/puppet/latest/lang_classes.html and "\
                  "https://puppet.com/docs/puppet/latest/lang_defined_types.html"
        Bolt::Logger.warn("empty_manifest", message)
      end
      executor.publish_event(type: :plan_start, plan: nil)
      with_benchmark do
        apply_prep_results = pal.in_plan_compiler(executor, inventory, plugins.puppetdb_client) do |compiler|
          compiler.call_function('apply_prep', targets, '_catch_errors' => true)
        end
        apply_results = pal.with_bolt_executor(executor, inventory, plugins.puppetdb_client) do
          Puppet.lookup(:apply_executor)
                .apply_ast(ast, apply_prep_results.ok_set.targets, catch_errors: true, noop: noop)
        end
        Bolt::ResultSet.new(apply_prep_results.error_set.results + apply_results.results)
      end
    end
def apply ( manifest , targets , code : '' , noop : false ) manifest_code = if manifest Bolt :: Util . validate_file ( 'manifest' , manifest ) File . read ( File . expand_path ( manifest ) ) else code end targets = inventory . get_targets ( targets ) Puppet [ :tasks ] = false ast = pal . parse_manifest ( manifest_code , manifest ) if defined? ( ast . body ) && ( ast . body . is_a? ( Puppet :: Pops :: Model :: HostClassDefinition ) || ast . body . is_a? ( Puppet :: Pops :: Model :: ResourceTypeDefinition ) ) message = "Manifest only contains definitions and will result in no changes on the targets. " "Definitions must be declared for their resources to be applied. You can read more " "about defining and declaring classes and types in the Puppet documentation at " "https://puppet.com/docs/puppet/latest/lang_classes.html and " "https://puppet.com/docs/puppet/latest/lang_defined_types.html" Bolt :: Logger . warn ( "empty_manifest" , message ) end executor . publish_event ( type : :plan_start , plan : nil ) with_benchmark do apply_prep_results = pal . in_plan_compiler ( executor , inventory , plugins . puppetdb_client ) do | compiler | compiler . call_function ( 'apply_prep' , targets , '_catch_errors' => true ) end apply_results = pal . with_bolt_executor ( executor , inventory , plugins . puppetdb_client ) do Puppet . lookup ( :apply_executor ) . apply_ast ( ast , apply_prep_results . ok_set . targets , catch_errors : true , noop : noop ) end Bolt :: ResultSet . new ( apply_prep_results . error_set . results + apply_results . results ) end end
Apply Puppet manifest code to a list of targets.
Apply Puppet manifest code to a list of targets .
# Apply logging looks like plan logging
None
Bolt::ResultSet
manifest
The path to a Puppet manifest file.
The path to a Puppet manifest file .
targets
] The targets to run on.
] The targets to run on .
code
Puppet manifest code to apply.
Puppet manifest code to apply .
noop
Whether to apply in no-operation mode.
Whether to apply in no - operation mode .