Class: R10K::Puppetfile

Inherits:
Object
  • Object
show all
Includes:
Logging, Settings::Mixin, Util::Purgeable
Defined in:
lib/r10k/puppetfile.rb

Overview

Deprecated, use R10K::ModuleLoader::Puppetfile#load to load content, provide the ‘:modules` key of the returned Hash to R10K::ContentSynchronizer (either the `serial_sync` or `concurrent_sync`) and the remaining keys (`:managed_directories`, `:desired_contents`, and `:purge_exclusions`) to R10K::Util::Cleaner.

Constant Summary

Constants included from Util::Purgeable

Util::Purgeable::FN_MATCH_OPTS, Util::Purgeable::HIDDEN_FILE

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Purgeable

#current_contents, #logger, #matches?, #pending_contents, #potentially_purgeable, #purge!, #stale_contents

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods included from Settings::Mixin

included

Constructor Details

#initialize(basedir, options_or_moduledir = nil, deprecated_path_arg = nil, deprecated_name_arg = nil, deprecated_force_arg = nil) ⇒ Puppetfile

Returns a new instance of Puppetfile.

Parameters:

  • basedir (String)
  • options_or_moduledir (Hash, String, nil) (defaults to: nil)

    The directory to install the modules or a Hash of options. Usage as moduledir is deprecated. Only use as options, defaults to nil

  • puppetfile_path (String, nil)

    Deprecated - The path to the Puppetfile, defaults to nil

  • puppetfile_name (String, nil)

    Deprecated - The name of the Puppetfile, defaults to nil

  • force (Boolean, nil)

    Deprecated - Shall we overwrite locally made changes?



55
56
57
58
59
60
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
86
87
88
89
90
91
92
93
# File 'lib/r10k/puppetfile.rb', line 55

def initialize(basedir, options_or_moduledir = nil, deprecated_path_arg = nil, deprecated_name_arg = nil, deprecated_force_arg = nil)
  @basedir         = basedir
  if options_or_moduledir.is_a? Hash
    options = options_or_moduledir
    deprecated_moduledir_arg = nil
  else
    options = {}
    deprecated_moduledir_arg = options_or_moduledir
  end

  @force           = deprecated_force_arg     || options.delete(:force)           || false
  @moduledir       = deprecated_moduledir_arg || options.delete(:moduledir)       || File.join(basedir, 'modules')
  puppetfile_name = deprecated_name_arg      || options.delete(:puppetfile_name) || 'Puppetfile'
  puppetfile_path = deprecated_path_arg      || options.delete(:puppetfile_path)
  @puppetfile = puppetfile_path || puppetfile_name
  @environment     = options.delete(:environment)

  @overrides       = options.delete(:overrides) || {}
  @default_branch_override = @overrides.dig(:environments, :default_branch_override)

  @forge   = 'forgeapi.puppetlabs.com'

  @loader = ::R10K::ModuleLoader::Puppetfile.new(
    basedir: @basedir,
    moduledir: @moduledir,
    puppetfile: @puppetfile,
    overrides: @overrides,
    environment: @environment
  )

  @loaded_content = {
    modules: [],
    managed_directories: [],
    desired_contents: [],
    purge_exclusions: []
  }

  @loaded = false
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



31
32
33
# File 'lib/r10k/puppetfile.rb', line 31

def basedir
  @basedir
end

#environmentObject

Returns the value of attribute environment.



35
36
37
# File 'lib/r10k/puppetfile.rb', line 35

def environment
  @environment
end

#forceBoolean

Returns Overwrite any locally made changes.

Returns:

  • (Boolean)

    Overwrite any locally made changes



39
40
41
# File 'lib/r10k/puppetfile.rb', line 39

def force
  @force
end

#forgeObject (readonly)

Returns the value of attribute forge.



27
28
29
# File 'lib/r10k/puppetfile.rb', line 27

def forge
  @forge
end

#loaderObject (readonly)

Returns the value of attribute loader.



47
48
49
# File 'lib/r10k/puppetfile.rb', line 47

def loader
  @loader
end

#overridesObject (readonly)

Returns the value of attribute overrides.



43
44
45
# File 'lib/r10k/puppetfile.rb', line 43

def overrides
  @overrides
end

Instance Method Details

#accept(visitor) ⇒ Object



185
186
187
188
189
190
191
192
# File 'lib/r10k/puppetfile.rb', line 185

def accept(visitor)
  pool_size = self.settings[:pool_size]
  if pool_size > 1
    R10K::ContentSynchronizer.concurrent_accept(modules, visitor, self, pool_size, logger)
  else
    R10K::ContentSynchronizer.serial_accept(modules, visitor, self)
  end
end

#add_module(name, args) ⇒ Object



137
138
139
# File 'lib/r10k/puppetfile.rb', line 137

def add_module(name, args)
  @loader.add_module(name, args)
end

#desired_contentsArray<String>

Note:

This implements a required method for the Purgeable mixin

Returns an array of the full paths to all the content being managed.

Returns:

  • (Array<String>)


173
174
175
176
177
# File 'lib/r10k/puppetfile.rb', line 173

def desired_contents
  self.load

  @loaded_content[:desired_contents]
end

#load(default_branch_override = nil) ⇒ Object

Parameters:

  • default_branch_override (String) (defaults to: nil)

    The default branch to use instead of one specified in the module declaration, if applicable. Deprecated, use R10K::ModuleLoader::Puppetfile directly and pass the default_branch_override as an option on initialization.



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/r10k/puppetfile.rb', line 99

def load(default_branch_override = nil)
  if self.loaded?
    return @loaded_content
  else
    if !File.readable?(puppetfile_path)
      logger.debug _("Puppetfile %{path} missing or unreadable") % {path: puppetfile_path.inspect}
    else
      self.load!(default_branch_override)
    end
  end
end

#load!(default_branch_override = nil) ⇒ Object

Parameters:

  • default_branch_override (String) (defaults to: nil)

    The default branch to use instead of one specified in the module declaration, if applicable. Deprecated, use R10K::ModuleLoader::Puppetfile directly and pass the default_branch_override as an option on initialization.



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/r10k/puppetfile.rb', line 115

def load!(default_branch_override = nil)

  if default_branch_override && (default_branch_override != @default_branch_override)
    logger.warn("Mismatch between passed and initialized default branch overrides, preferring passed value.")
    @loader.default_branch_override = default_branch_override
  end

  @loaded_content = @loader.load!
  @loaded = true

  @loaded_content
end

#loaded?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/r10k/puppetfile.rb', line 128

def loaded?
  @loaded
end

#managed_directoriesObject



164
165
166
167
168
# File 'lib/r10k/puppetfile.rb', line 164

def managed_directories
  self.load

  @loaded_content[:managed_directories]
end

#moduledirObject



149
150
151
# File 'lib/r10k/puppetfile.rb', line 149

def moduledir
  @loader.moduledir
end

#modulesObject



132
133
134
# File 'lib/r10k/puppetfile.rb', line 132

def modules
  @loaded_content[:modules]
end

#puppetfile_pathObject



153
154
155
# File 'lib/r10k/puppetfile.rb', line 153

def puppetfile_path
  @loader.puppetfile_path
end

#purge_exclusionsObject



179
180
181
182
183
# File 'lib/r10k/puppetfile.rb', line 179

def purge_exclusions
  self.load

  @loaded_content[:purge_exclusions]
end

#set_forge(forge) ⇒ Object



145
146
147
# File 'lib/r10k/puppetfile.rb', line 145

def set_forge(forge)
  @loader.set_forge(forge)
end

#set_moduledir(dir) ⇒ Object



141
142
143
# File 'lib/r10k/puppetfile.rb', line 141

def set_moduledir(dir)
  @loader.set_moduledir(dir)
end

#syncObject



194
195
196
197
198
199
200
201
# File 'lib/r10k/puppetfile.rb', line 194

def sync
  pool_size = self.settings[:pool_size]
  if pool_size > 1
    R10K::ContentSynchronizer.concurrent_sync(modules, pool_size, logger)
  else
    R10K::ContentSynchronizer.serial_sync(modules)
  end
end