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
Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP
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.
-
#environment_name ⇒ Object
readonly
Returns the value of attribute environment_name.
-
#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, module_exclude_regex: 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
add_outputters, 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, module_exclude_regex: nil) ⇒ Puppetfile
Returns a new instance of Puppetfile.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 35 def initialize(basedir:, moduledir: DEFAULT_MODULEDIR, puppetfile: DEFAULT_PUPPETFILE_NAME, overrides: {}, environment: nil, module_exclude_regex: nil) @basedir = cleanpath(basedir) @moduledir = resolve_path(@basedir, moduledir) @puppetfile_path = resolve_path(@basedir, puppetfile) @overrides = overrides @environment = environment @module_exclude_regex = module_exclude_regex @environment_name = @environment&.name @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 |
#environment_name ⇒ Object (readonly)
Returns the value of attribute environment_name.
18 19 20 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 18 def environment_name @environment_name 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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 155 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, and it ostensibly # has already has been deployed to disk, use it. Otherwise create a # regular module to sync. unless mod.version && mod.version == @existing_module_versions_by_name[mod.name] && File.directory?(mod.path) mod = mod.to_implementation end @modules << mod end |
#add_module_metadata(name, info) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 114 def (name, info) install_path, , _ = parse_module_definition(name, info) mod = R10K::Module.(name, install_path, , @environment) @existing_module_metadata << mod end |
#load ⇒ Object
61 62 63 64 65 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 61 def load with_readable_puppetfile(@puppetfile_path) do self.load! end end |
#load! ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 67 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) @modules = filter_modules(@modules, @module_exclude_regex) if @module_exclude_regex 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
94 95 96 97 98 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 94 def with_readable_puppetfile(@puppetfile_path) do self. end end |
#load_metadata! ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 100 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 ScriptError, StandardError => e logger.warn _("Unable to preload Puppetfile because of %{msg}" % { msg: e. }) @existing_module_metadata = [] @existing_module_versions_by_name = {} end |
#set_forge(forge) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 127 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
137 138 139 |
# File 'lib/r10k/module_loader/puppetfile.rb', line 137 def set_moduledir(moduledir) @moduledir = resolve_path(@basedir, moduledir) end |