Class: PuppetLocal::Command::Install
- Inherits:
-
PuppetLocal::Command
- Object
- Clamp::Command
- PuppetLocal::Command
- PuppetLocal::Command::Install
- Defined in:
- lib/puppet_local/command/install.rb
Instance Method Summary collapse
- #apply ⇒ Object
- #clone_git_modules ⇒ Object
- #create_puppet_hiera_config ⇒ Object
- #execute ⇒ Object
- #hiera_path_absolute ⇒ Object
- #local_path(path = '') ⇒ Object
- #puppet_hiera_config ⇒ Object
- #puppet_module_path ⇒ Object
- #setup ⇒ Object
Methods inherited from PuppetLocal::Command
Instance Method Details
#apply ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/puppet_local/command/install.rb', line 56 def apply puppet_code = 'include hiera("classes", [])' params = { '--debug' => debug?, '-e' => puppet_code, '--hiera_config' => puppet_hiera_config, '--modulepath' => puppet_module_path } system_command 'puppet apply', params end |
#clone_git_modules ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet_local/command/install.rb', line 40 def clone_git_modules @puppet_module_paths = [] if @hiera.include? 'git-modules' @hiera['git-modules'].each do |source, version| repo_path = local_path Digest::MD5.hexdigest(source) if File.directory? repo_path repo = Git.open repo_path else repo = Git.clone source, repo_path end repo.checkout version @puppet_module_paths.push repo.dir.path + '/modules' end end end |
#create_puppet_hiera_config ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/puppet_local/command/install.rb', line 27 def create_puppet_hiera_config hiera_config = { :backends => ['json'], :hierarchy => [File.basename(@hiera_path).sub(/\.json$/, '')], :json => { :datadir => File.dirname(hiera_path_absolute) } } file = File.new(puppet_hiera_config, 'w') file.puts(hiera_config.to_yaml.gsub('!ruby/sym ', ':')) file.close end |
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/puppet_local/command/install.rb', line 7 def execute puts 'Setting up environment...' setup create_puppet_hiera_config puts 'Checking out git-modules...' clone_git_modules puts 'Applying catalog...' apply print on_green ' ' puts ' Puppet apply succeeded' end |
#hiera_path_absolute ⇒ Object
67 68 69 |
# File 'lib/puppet_local/command/install.rb', line 67 def hiera_path_absolute File. @hiera_path end |
#local_path(path = '') ⇒ Object
71 72 73 |
# File 'lib/puppet_local/command/install.rb', line 71 def local_path(path = '') ENV['HOME'] + '/.puppet-local/' + Digest::MD5.hexdigest(hiera_path_absolute) + '/' + path end |
#puppet_hiera_config ⇒ Object
75 76 77 |
# File 'lib/puppet_local/command/install.rb', line 75 def puppet_hiera_config local_path 'hiera.yaml' end |
#puppet_module_path ⇒ Object
79 80 81 |
# File 'lib/puppet_local/command/install.rb', line 79 def puppet_module_path @puppet_module_paths.join(':') end |
#setup ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/puppet_local/command/install.rb', line 19 def setup raise '`' + @hiera_path + '` does not exist' unless File.exists? @hiera_path FileUtils.mkdir_p local_path file = File.new(hiera_path_absolute, 'r') @hiera = JSON.parse file.read file.close end |