Class: DTK::Client::DtkPuppet
- Inherits:
-
Object
- Object
- DTK::Client::DtkPuppet
- Defined in:
- lib/util/dtk_puppet.rb
Overview
Class is used as puppet wrapper, at the moment it will use console comamnds, later to be replaced with direct usage of puppet code, or re-implentation of their direct calls
Constant Summary collapse
- MODULE_PATH =
OsUtil.component_clone_location()
Class Method Summary collapse
-
.install_module(module_name) ⇒ Object
installs puppet module from puppet forge via puppet module method will print out progress or errrors.
Class Method Details
.install_module(module_name) ⇒ Object
installs puppet module from puppet forge via puppet module method will print out progress or errrors
Returns: Name of directory where module is saved
34 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 60 61 |
# File 'lib/util/dtk_puppet.rb', line 34 def self.install_module(module_name) output = nil OsUtil.suspend_output do output = `puppet module install #{module_name} --modulepath #{MODULE_PATH} --force --render-as json` end # extract json from output, regex will match json in string matched = output.match(/\{.+\}/) raise DTK::Client::DtkError, "Puppet module '#{module_name}' not found." unless matched # parse matched json result = JSON.parse(matched[0]) if result['result'] == 'failure' # we remove puppet specific messages filtered = result['error']['multiline'].gsub(/^.*puppet module.*$\n?/,'') # we strip and join multiline message filtered = filtered.split(/\n/).map(&:strip).join(', ') raise DTK::Client::DtkError, filtered end # puppet uses last part of the module name, as dir for location dir_name = module_name.split('-').last puts "Successfully installed '#{module_name}' from puppet forge, location: '#{MODULE_PATH}/#{dir_name}'" return dir_name end |