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
94
# 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,
    forge: @forge,
    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



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

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



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

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>)


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

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.



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

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.



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

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)


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

def loaded?
  @loaded
end

#managed_directoriesObject



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

def managed_directories
  self.load

  @loaded_content[:managed_directories]
end

#moduledirObject



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

def moduledir
  @loader.moduledir
end

#modulesObject



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

def modules
  @loaded_content[:modules]
end

#puppetfile_pathObject



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

def puppetfile_path
  @loader.puppetfile_path
end

#purge_exclusionsObject



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

def purge_exclusions
  self.load

  @loaded_content[:purge_exclusions]
end

#set_forge(forge) ⇒ Object



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

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

#set_moduledir(dir) ⇒ Object



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

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

#syncObject



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

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