Class: R10K::ModuleLoader::Puppetfile
- Inherits:
-
Object
- Object
- R10K::ModuleLoader::Puppetfile
- Includes:
- Logging
- Defined in:
- lib/r10k/module_loader/puppetfile.rb,
lib/r10k/module_loader/puppetfile/dsl.rb
Defined Under Namespace
Classes: DSL
Constant Summary collapse
- DEFAULT_MODULEDIR =
'modules'
- DEFAULT_PUPPETFILE_NAME =
'Puppetfile'
Constants included from Logging
Instance Attribute Summary collapse
-
#default_branch_override ⇒ Object
Returns the value of attribute default_branch_override.
-
#desired_contents ⇒ Object
readonly
Returns the value of attribute desired_contents.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#managed_directories ⇒ Object
readonly
Returns the value of attribute managed_directories.
-
#moduledir ⇒ Object
readonly
Returns the value of attribute moduledir.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#puppetfile_path ⇒ Object
readonly
Returns the value of attribute puppetfile_path.
-
#purge_exclusions ⇒ Object
readonly
Returns the value of attribute purge_exclusions.
Instance Method Summary collapse
- #add_module(name, info) ⇒ Object
- #add_module_metadata(name, info) ⇒ Object
-
#initialize(basedir:, moduledir: DEFAULT_MODULEDIR, puppetfile: DEFAULT_PUPPETFILE_NAME, overrides: {}, environment: nil) ⇒ Puppetfile
constructor
A new instance of Puppetfile.
- #load ⇒ Object
- #load! ⇒ Object
- #load_metadata ⇒ Object
- #load_metadata! ⇒ Object
- #set_forge(forge) ⇒ Object
- #set_moduledir(moduledir) ⇒ Object
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(basedir:, moduledir: DEFAULT_MODULEDIR, puppetfile: DEFAULT_PUPPETFILE_NAME, overrides: {}, environment: nil) ⇒ Puppetfile
Returns a new instance of Puppetfile.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 32 def initialize(basedir:, moduledir: DEFAULT_MODULEDIR, puppetfile: DEFAULT_PUPPETFILE_NAME, overrides: {}, environment: nil) @basedir = cleanpath(basedir) @moduledir = resolve_path(@basedir, moduledir) @puppetfile_path = resolve_path(@basedir, puppetfile) @overrides = overrides @environment = environment @default_branch_override = @overrides.dig(:environments, :default_branch_override) @allow_puppetfile_forge = @overrides.dig(:forge, :allow_puppetfile_override) @existing_module_metadata = [] @existing_module_versions_by_name = {} @modules = [] @managed_directories = [] @desired_contents = [] @purge_exclusions = [] end |
Instance Attribute Details
#default_branch_override ⇒ Object
Returns the value of attribute default_branch_override.
17 18 19 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 17 def default_branch_override @default_branch_override end |
#desired_contents ⇒ Object (readonly)
Returns the value of attribute desired_contents.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def desired_contents @desired_contents end |
#environment ⇒ Object
Returns the value of attribute environment.
17 18 19 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 17 def environment @environment end |
#managed_directories ⇒ Object (readonly)
Returns the value of attribute managed_directories.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def managed_directories @managed_directories end |
#moduledir ⇒ Object (readonly)
Returns the value of attribute moduledir.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def moduledir @moduledir end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def modules @modules end |
#puppetfile_path ⇒ Object (readonly)
Returns the value of attribute puppetfile_path.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def puppetfile_path @puppetfile_path end |
#purge_exclusions ⇒ Object (readonly)
Returns the value of attribute purge_exclusions.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def purge_exclusions @purge_exclusions end |
Instance Method Details
#add_module(name, info) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 145 def add_module(name, info) install_path, , spec_deletable = parse_module_definition(name, info) mod = R10K::Module.(name, install_path, , @environment) mod.origin = :puppetfile mod.spec_deletable = spec_deletable # Do not save modules if they would conflict with the attached # environment if @environment && @environment.module_conflicts?(mod) return @modules end # If this module's metadata has a static version and that version # matches the existing module declaration use it, otherwise create # a regular module to sync. unless mod.version && (mod.version == @existing_module_versions_by_name[mod.name]) mod = mod.to_implementation end @modules << mod end |
#add_module_metadata(name, info) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 104 def (name, info) install_path, , _ = parse_module_definition(name, info) mod = R10K::Module.(name, install_path, , @environment) @existing_module_metadata << mod end |
#load ⇒ Object
55 56 57 58 59 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 55 def load with_readable_puppetfile(@puppetfile_path) do self.load! end end |
#load! ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 61 def load! logger.info _("Using Puppetfile '%{puppetfile}'") % {puppetfile: @puppetfile_path} logger.debug _("Using moduledir '%{moduledir}'") % {moduledir: @moduledir} dsl = R10K::ModuleLoader::Puppetfile::DSL.new(self) dsl.instance_eval(puppetfile_content(@puppetfile_path), @puppetfile_path) validate_no_duplicate_names(@modules) managed_content = @modules.group_by(&:dirname) @managed_directories = determine_managed_directories(managed_content) @desired_contents = determine_desired_contents(managed_content) @purge_exclusions = determine_purge_exclusions(@managed_directories) { modules: @modules, managed_directories: @managed_directories, desired_contents: @desired_contents, purge_exclusions: @purge_exclusions } rescue SyntaxError, LoadError, ArgumentError, NameError => e raise R10K::Error.wrap(e, _("Failed to evaluate %{path}") % {path: @puppetfile_path}) end |
#load_metadata ⇒ Object
87 88 89 90 91 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 87 def with_readable_puppetfile(@puppetfile_path) do self. end end |
#load_metadata! ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 93 def dsl = R10K::ModuleLoader::Puppetfile::DSL.new(self, metadata_only: true) dsl.instance_eval(puppetfile_content(@puppetfile_path), @puppetfile_path) @existing_module_versions_by_name = @existing_module_metadata.map {|mod| [ mod.name, mod.version ] }.to_h empty_load_output.merge(modules: @existing_module_metadata) rescue SyntaxError, LoadError, ArgumentError, NameError => e logger.warn _("Unable to preload Puppetfile because of %{msg}" % { msg: e. }) end |
#set_forge(forge) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 117 def set_forge(forge) if @allow_puppetfile_forge logger.debug _("Using Forge from Puppetfile: %{forge}") % { forge: forge } PuppetForge.host = forge else logger.debug _("Ignoring Forge declaration in Puppetfile, using value from settings: %{forge}.") % { forge: PuppetForge.host } end end |
#set_moduledir(moduledir) ⇒ Object
127 128 129 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 127 def set_moduledir(moduledir) @moduledir = resolve_path(@basedir, moduledir) end |