Class: R10K::Puppetfile
- Inherits:
-
Object
- Object
- R10K::Puppetfile
- Includes:
- Logging, Settings::Mixin, Util::Purgeable
- Defined in:
- lib/r10k/puppetfile.rb
Defined Under Namespace
Classes: DSL
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
-
#environment ⇒ R10K::Environment
Optional R10K::Environment that this Puppetfile belongs to.
-
#force ⇒ Boolean
Overwrite any locally made changes.
-
#forge ⇒ Object
readonly
Returns the value of attribute forge.
-
#moduledir ⇒ Object
readonly
Returns the value of attribute moduledir.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#modules_by_vcs_cachedir ⇒ Object
readonly
Returns the value of attribute modules_by_vcs_cachedir.
-
#puppetfile_path ⇒ Object
readonly
Returns the value of attribute puppetfile_path.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #add_module(name, args) ⇒ Object
-
#desired_contents ⇒ Array<String>
Returns an array of the full paths to all the content being managed.
-
#initialize(basedir, moduledir = nil, puppetfile_path = nil, puppetfile_name = nil, force = nil) ⇒ Puppetfile
constructor
A new instance of Puppetfile.
- #load(default_branch_override = nil) ⇒ Object
- #load!(default_branch_override = nil) ⇒ Object
- #loaded? ⇒ Boolean
- #managed_directories ⇒ Object
- #modules_queue(visitor) ⇒ Object
- #purge_exclusions ⇒ Object
- #set_forge(forge) ⇒ Object
- #set_moduledir(moduledir) ⇒ Object
- #validate_no_duplicate_names(modules) ⇒ Object
Methods included from Util::Purgeable
#current_contents, #logger, #pending_contents, #purge!, #stale_contents
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Methods included from Settings::Mixin
Constructor Details
#initialize(basedir, moduledir = nil, puppetfile_path = nil, puppetfile_name = nil, force = nil) ⇒ Puppetfile
Returns a new instance of Puppetfile.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/r10k/puppetfile.rb', line 55 def initialize(basedir, moduledir = nil, puppetfile_path = nil, puppetfile_name = nil, force = nil ) @basedir = basedir @force = force || false @moduledir = moduledir || File.join(basedir, 'modules') @puppetfile_name = puppetfile_name || 'Puppetfile' @puppetfile_path = puppetfile_path || File.join(basedir, @puppetfile_name) logger.info _("Using Puppetfile '%{puppetfile}'") % {puppetfile: @puppetfile_path} @modules = [] @managed_content = {} @modules_by_vcs_cachedir = {} @forge = 'forgeapi.puppetlabs.com' @loaded = false end |
Instance Attribute Details
#basedir ⇒ Object (readonly)
Returns the value of attribute basedir.
27 28 29 |
# File 'lib/r10k/puppetfile.rb', line 27 def basedir @basedir end |
#environment ⇒ R10K::Environment
Returns Optional R10K::Environment that this Puppetfile belongs to.
39 40 41 |
# File 'lib/r10k/puppetfile.rb', line 39 def environment @environment end |
#force ⇒ Boolean
Returns Overwrite any locally made changes.
43 44 45 |
# File 'lib/r10k/puppetfile.rb', line 43 def force @force end |
#forge ⇒ Object (readonly)
Returns the value of attribute forge.
19 20 21 |
# File 'lib/r10k/puppetfile.rb', line 19 def forge @forge end |
#moduledir ⇒ Object (readonly)
Returns the value of attribute moduledir.
31 32 33 |
# File 'lib/r10k/puppetfile.rb', line 31 def moduledir @moduledir end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
23 24 25 |
# File 'lib/r10k/puppetfile.rb', line 23 def modules @modules end |
#modules_by_vcs_cachedir ⇒ Object (readonly)
Returns the value of attribute modules_by_vcs_cachedir.
48 49 50 |
# File 'lib/r10k/puppetfile.rb', line 48 def modules_by_vcs_cachedir @modules_by_vcs_cachedir end |
#puppetfile_path ⇒ Object (readonly)
Returns the value of attribute puppetfile_path.
35 36 37 |
# File 'lib/r10k/puppetfile.rb', line 35 def puppetfile_path @puppetfile_path end |
Instance Method Details
#accept(visitor) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/r10k/puppetfile.rb', line 183 def accept(visitor) pool_size = self.settings[:pool_size] if pool_size > 1 concurrent_accept(visitor, pool_size) else serial_accept(visitor) end end |
#add_module(name, args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/r10k/puppetfile.rb', line 127 def add_module(name, args) if args.is_a?(Hash) && install_path = args.delete(:install_path) install_path = resolve_install_path(install_path) validate_install_path(install_path, name) else install_path = @moduledir end if args.is_a?(Hash) && @default_branch_override != nil args[:default_branch] = @default_branch_override end # Keep track of all the content this Puppetfile is managing to enable purging. @managed_content[install_path] = Array.new unless @managed_content.has_key?(install_path) mod = R10K::Module.new(name, install_path, args, @environment) mod.origin = 'Puppetfile' @managed_content[install_path] << mod.name cachedir = mod.cachedir @modules_by_vcs_cachedir[cachedir] ||= [] @modules_by_vcs_cachedir[cachedir] << mod @modules << mod end |
#desired_contents ⇒ Array<String>
This implements a required method for the Purgeable mixin
Returns an array of the full paths to all the content being managed.
165 166 167 168 169 170 171 |
# File 'lib/r10k/puppetfile.rb', line 165 def desired_contents self.load unless @loaded @managed_content.flat_map do |install_path, modnames| modnames.collect { |name| File.join(install_path, name) } end end |
#load(default_branch_override = nil) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/r10k/puppetfile.rb', line 72 def load(default_branch_override = nil) return true if self.loaded? if File.readable? @puppetfile_path self.load!(default_branch_override) else logger.debug _("Puppetfile %{path} missing or unreadable") % {path: @puppetfile_path.inspect} end end |
#load!(default_branch_override = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/r10k/puppetfile.rb', line 81 def load!(default_branch_override = nil) @default_branch_override = default_branch_override dsl = R10K::Puppetfile::DSL.new(self) dsl.instance_eval(puppetfile_contents, @puppetfile_path) validate_no_duplicate_names(@modules) @loaded = true rescue SyntaxError, LoadError, ArgumentError, NameError => e raise R10K::Error.wrap(e, _("Failed to evaluate %{path}") % {path: @puppetfile_path}) end |
#loaded? ⇒ Boolean
93 94 95 |
# File 'lib/r10k/puppetfile.rb', line 93 def loaded? @loaded end |
#managed_directories ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/r10k/puppetfile.rb', line 154 def managed_directories self.load unless @loaded dirs = @managed_content.keys dirs.delete(real_basedir) dirs end |
#modules_queue(visitor) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/r10k/puppetfile.rb', line 223 def modules_queue(visitor) Queue.new.tap do |queue| visitor.visit(:puppetfile, self) do modules_by_cachedir = modules_by_vcs_cachedir.clone modules_without_vcs_cachedir = modules_by_cachedir.delete(:none) || [] modules_without_vcs_cachedir.each {|mod| queue << Array(mod) } modules_by_cachedir.values.each {|mods| queue << mods } end end end |
#purge_exclusions ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'lib/r10k/puppetfile.rb', line 173 def purge_exclusions exclusions = managed_directories if environment && environment.respond_to?(:desired_contents) exclusions += environment.desired_contents end exclusions end |
#set_forge(forge) ⇒ Object
112 113 114 |
# File 'lib/r10k/puppetfile.rb', line 112 def set_forge(forge) @forge = forge end |
#set_moduledir(moduledir) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/r10k/puppetfile.rb', line 117 def set_moduledir(moduledir) @moduledir = if Pathname.new(moduledir).absolute? moduledir else File.join(basedir, moduledir) end end |
#validate_no_duplicate_names(modules) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/r10k/puppetfile.rb', line 98 def validate_no_duplicate_names(modules) dupes = modules .group_by { |mod| mod.name } .select { |_, v| v.size > 1 } .map(&:first) unless dupes.empty? msg = _('Puppetfiles cannot contain duplicate module names.') msg += ' ' msg += _("Remove the duplicates of the following modules: %{dupes}" % { dupes: dupes.join(' ') }) raise R10K::Error.new(msg) end end |