kafo 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +34 -9
 - data/Rakefile +7 -1
 - data/doc/kafo_run.png +0 -0
 - data/doc/kafo_run.uml +2 -2
 - data/lib/kafo/configuration.rb +24 -4
 - data/lib/kafo/execution_environment.rb +84 -0
 - data/lib/kafo/exit_handler.rb +9 -4
 - data/lib/kafo/fact_writer.rb +24 -0
 - data/lib/kafo/hiera_configurer.rb +19 -93
 - data/lib/kafo/hook_context.rb +21 -2
 - data/lib/kafo/kafo_configure.rb +11 -15
 - data/lib/kafo/puppet_command.rb +6 -2
 - data/lib/kafo/puppet_configurer.rb +9 -15
 - data/lib/kafo/puppet_module.rb +5 -1
 - data/lib/kafo/scenario_manager.rb +1 -1
 - data/lib/kafo/version.rb +1 -1
 - metadata +15 -9
 - data/lib/kafo/password_manager.rb +0 -47
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b6a7603ad0e129c240e560c7f758ecbb4cbb13fc54a04913cf4a0beb7aa53f25
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 25a7d3a113b3dc90cf566221806b58a167082097fff4de2de9b71dead4b60dca
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8e7e7845606b1668728291952679461fcab7e1dec9872651a414d450362dc9050abc337884b7908e50ba034b1c65e884002a8e1284744b7e406832a306989d25
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e325a88e3c6aae2115126d672615a8d9397b4a28383d01ea6a9ea60e0745a99e193a4d405d7ee604ea1e5e7bcdb1d52d1e2d74378470ddf476976924ff472927
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1004,6 +1004,21 @@ The cache will be skipped if the file modification time of the manifest is 
     | 
|
| 
       1004 
1004 
     | 
    
         
             
            greater than the mtime recorded in the cache. Using `--parser-cache` will force
         
     | 
| 
       1005 
1005 
     | 
    
         
             
            the use of an outdated cache, but this should be used with caution.
         
     | 
| 
       1006 
1006 
     | 
    
         | 
| 
      
 1007 
     | 
    
         
            +
            ## Facts
         
     | 
| 
      
 1008 
     | 
    
         
            +
             
     | 
| 
      
 1009 
     | 
    
         
            +
            Kafo provides a structured fact describing the state. This fact is only present
         
     | 
| 
      
 1010 
     | 
    
         
            +
            during the Puppet run. Currently it's the scenario id and name where the id is
         
     | 
| 
      
 1011 
     | 
    
         
            +
            the same as passed via --scenario by the user and matches the scenario filename
         
     | 
| 
      
 1012 
     | 
    
         
            +
            with an extension. The name is a human readable version.
         
     | 
| 
      
 1013 
     | 
    
         
            +
             
     | 
| 
      
 1014 
     | 
    
         
            +
            ```yaml
         
     | 
| 
      
 1015 
     | 
    
         
            +
            ---
         
     | 
| 
      
 1016 
     | 
    
         
            +
            kafo:
         
     | 
| 
      
 1017 
     | 
    
         
            +
              scenario:
         
     | 
| 
      
 1018 
     | 
    
         
            +
                id: foreman_proxy
         
     | 
| 
      
 1019 
     | 
    
         
            +
                name: Foreman Proxy
         
     | 
| 
      
 1020 
     | 
    
         
            +
            ```
         
     | 
| 
      
 1021 
     | 
    
         
            +
             
     | 
| 
       1007 
1022 
     | 
    
         
             
            ## Configuring Hiera
         
     | 
| 
       1008 
1023 
     | 
    
         | 
| 
       1009 
1024 
     | 
    
         
             
            Kafo uses Hiera to include classes and pass parameters to classes using data
         
     | 
| 
         @@ -1018,22 +1033,20 @@ The contents of this file are as per the 
     | 
|
| 
       1018 
1033 
     | 
    
         
             
            [hiera.yaml docs](https://docs.puppet.com/hiera/latest/configuring.html).
         
     | 
| 
       1019 
1034 
     | 
    
         
             
            Only Hiera version 5 is supported.
         
     | 
| 
       1020 
1035 
     | 
    
         | 
| 
       1021 
     | 
    
         
            -
             
     | 
| 
       1022 
     | 
    
         
            -
             
     | 
| 
       1023 
     | 
    
         
            -
            ` 
     | 
| 
       1024 
     | 
    
         
            -
             
     | 
| 
       1025 
     | 
    
         
            -
            to allow a more complex hierarchy.
         
     | 
| 
      
 1036 
     | 
    
         
            +
            An answers file will be generated containing _all_ default and overriden values
         
     | 
| 
      
 1037 
     | 
    
         
            +
            for parameters managed by Kafo. During the run this is available as a
         
     | 
| 
      
 1038 
     | 
    
         
            +
            `kafo.scenario.answer_file` fact. This may change in the future to allow a more
         
     | 
| 
      
 1039 
     | 
    
         
            +
            complex hierarchy.
         
     | 
| 
       1026 
1040 
     | 
    
         | 
| 
       1027 
     | 
    
         
            -
            The hierarchy  
     | 
| 
       1028 
     | 
    
         
            -
             
     | 
| 
       1029 
     | 
    
         
            -
            the Kafo answers are loaded. Note the name is case sensitive. When it's
         
     | 
| 
       1030 
     | 
    
         
            -
            missing, it will be added.
         
     | 
| 
      
 1041 
     | 
    
         
            +
            The hierarchy must contain the path `%{facts.kafo.scenario.answer_file}`. This
         
     | 
| 
      
 1042 
     | 
    
         
            +
            contains all answers in a temporary location.
         
     | 
| 
       1031 
1043 
     | 
    
         | 
| 
       1032 
1044 
     | 
    
         
             
            As an example, a hierarchy could be set up with:
         
     | 
| 
       1033 
1045 
     | 
    
         | 
| 
       1034 
1046 
     | 
    
         
             
            ```yaml
         
     | 
| 
       1035 
1047 
     | 
    
         
             
            hierarchy:
         
     | 
| 
       1036 
1048 
     | 
    
         
             
              - name: "Kafo Answers"
         
     | 
| 
      
 1049 
     | 
    
         
            +
                path: "%{facts.kafo.scenario.answer_file}"
         
     | 
| 
       1037 
1050 
     | 
    
         
             
              - name: "Other YAML hierarchy levels"
         
     | 
| 
       1038 
1051 
     | 
    
         
             
                paths:
         
     | 
| 
       1039 
1052 
     | 
    
         
             
                  - "family/%{facts.os.family}.yaml"
         
     | 
| 
         @@ -1048,6 +1061,7 @@ hierarchy: 
     | 
|
| 
       1048 
1061 
     | 
    
         
             
                datadir: "custom"
         
     | 
| 
       1049 
1062 
     | 
    
         
             
                path: "override.yaml"
         
     | 
| 
       1050 
1063 
     | 
    
         
             
              - name: "Kafo Answers"
         
     | 
| 
      
 1064 
     | 
    
         
            +
                path: "%{facts.kafo.scenario.answer_file}"
         
     | 
| 
       1051 
1065 
     | 
    
         
             
              - name: "Other YAML hierarchy levels"
         
     | 
| 
       1052 
1066 
     | 
    
         
             
                datadir: "data"
         
     | 
| 
       1053 
1067 
     | 
    
         
             
                paths:
         
     | 
| 
         @@ -1058,6 +1072,17 @@ hierarchy: 
     | 
|
| 
       1058 
1072 
     | 
    
         
             
            This would give precedence to all Kafo-managed parameter values, but for any
         
     | 
| 
       1059 
1073 
     | 
    
         
             
            others, would check for values per OS family, followed by a `common.yaml` file.
         
     | 
| 
       1060 
1074 
     | 
    
         | 
| 
      
 1075 
     | 
    
         
            +
            The scenario id is also available as a fact which can be used to provide
         
     | 
| 
      
 1076 
     | 
    
         
            +
            scenario specific overrides for unmanaged modules.
         
     | 
| 
      
 1077 
     | 
    
         
            +
             
     | 
| 
      
 1078 
     | 
    
         
            +
            ```yaml
         
     | 
| 
      
 1079 
     | 
    
         
            +
            hierarchy:
         
     | 
| 
      
 1080 
     | 
    
         
            +
              - name: "Kafo Answers"
         
     | 
| 
      
 1081 
     | 
    
         
            +
                path: "%{facts.kafo.scenario.answer_file}"
         
     | 
| 
      
 1082 
     | 
    
         
            +
              - name: "Scenario defaults"
         
     | 
| 
      
 1083 
     | 
    
         
            +
                path: "scenario/%{facts.kafo.scenario.id}.yaml"
         
     | 
| 
      
 1084 
     | 
    
         
            +
            ```
         
     | 
| 
      
 1085 
     | 
    
         
            +
             
     | 
| 
       1061 
1086 
     | 
    
         
             
            [Migration from Hiera version 3](https://puppet.com/docs/puppet/4.9/hiera_migrate_v3_yaml.html)
         
     | 
| 
       1062 
1087 
     | 
    
         
             
            is documented by Puppet.
         
     | 
| 
       1063 
1088 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -2,6 +2,12 @@ require 'rake/testtask' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require "bundler/gem_tasks"
         
     | 
| 
       3 
3 
     | 
    
         
             
            load 'tasks/jenkins.rake'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
            Rake::TestTask.new('test:ruby') do |t|
         
     | 
| 
      
 6 
     | 
    
         
            +
              t.libs << 'lib' << 'test'
         
     | 
| 
      
 7 
     | 
    
         
            +
              t.test_files = FileList['test/**/*_test.rb']
         
     | 
| 
      
 8 
     | 
    
         
            +
              t.verbose = true
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       5 
11 
     | 
    
         
             
            Rake::TestTask.new('test:unit') do |t|
         
     | 
| 
       6 
12 
     | 
    
         
             
              t.libs << 'lib' << 'test'
         
     | 
| 
       7 
13 
     | 
    
         
             
              t.test_files = FileList['test/kafo/**/*_test.rb']
         
     | 
| 
         @@ -27,4 +33,4 @@ end 
     | 
|
| 
       27 
33 
     | 
    
         | 
| 
       28 
34 
     | 
    
         
             
            CLEAN.include 'test/tmp'
         
     | 
| 
       29 
35 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
            task :test => ['test: 
     | 
| 
      
 36 
     | 
    
         
            +
            task :test => ['test:ruby', 'test:puppet_modules']
         
     | 
    
        data/doc/kafo_run.png
    CHANGED
    
    | 
         Binary file 
     | 
    
        data/doc/kafo_run.uml
    CHANGED
    
    | 
         @@ -68,7 +68,7 @@ 
     | 
|
| 
       68 
68 
     | 
    
         
             
              #Greenyellow:**pre_values**|
         
     | 
| 
       69 
69 
     | 
    
         
             
              :load values from answer file;
         
     | 
| 
       70 
70 
     | 
    
         
             
              :load values from previous answer file;
         
     | 
| 
       71 
     | 
    
         
            -
              note right: if previous  
     | 
| 
      
 71 
     | 
    
         
            +
              note right: if previous scenario != current scenario
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
              :update help with default values;
         
     | 
| 
       74 
74 
     | 
    
         
             
              |execute|
         
     | 
| 
         @@ -94,7 +94,7 @@ 
     | 
|
| 
       94 
94 
     | 
    
         | 
| 
       95 
95 
     | 
    
         
             
              #Greenyellow:**pre**|
         
     | 
| 
       96 
96 
     | 
    
         | 
| 
       97 
     | 
    
         
            -
              :setup  
     | 
| 
      
 97 
     | 
    
         
            +
              :setup ExecutionEnvironment and save configs;
         
     | 
| 
       98 
98 
     | 
    
         | 
| 
       99 
99 
     | 
    
         
             
              #Gold:run puppet;
         
     | 
| 
       100 
100 
     | 
    
         
             
              repeat
         
     | 
    
        data/lib/kafo/configuration.rb
    CHANGED
    
    | 
         @@ -4,11 +4,11 @@ require 'tmpdir' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'kafo/puppet_module'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'kafo/color_scheme'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'kafo/data_type_parser'
         
     | 
| 
       7 
     | 
    
         
            -
            require 'kafo/ 
     | 
| 
      
 7 
     | 
    
         
            +
            require 'kafo/execution_environment'
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            module Kafo
         
     | 
| 
       10 
10 
     | 
    
         
             
              class Configuration
         
     | 
| 
       11 
     | 
    
         
            -
                attr_reader :config_file, :answer_file
         
     | 
| 
      
 11 
     | 
    
         
            +
                attr_reader :config_file, :answer_file, :scenario_id
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                DEFAULT = {
         
     | 
| 
       14 
14 
     | 
    
         
             
                    :name                 => '',
         
     | 
| 
         @@ -27,11 +27,16 @@ module Kafo 
     | 
|
| 
       27 
27 
     | 
    
         
             
                    :color_of_background  => :dark,
         
     | 
| 
       28 
28 
     | 
    
         
             
                    :hook_dirs            => [],
         
     | 
| 
       29 
29 
     | 
    
         
             
                    :custom               => {},
         
     | 
| 
      
 30 
     | 
    
         
            +
                    :facts                => {},
         
     | 
| 
       30 
31 
     | 
    
         
             
                    :low_priority_modules => [],
         
     | 
| 
       31 
32 
     | 
    
         
             
                    :verbose_log_level    => 'info',
         
     | 
| 
       32 
33 
     | 
    
         
             
                    :skip_puppet_version_check => false
         
     | 
| 
       33 
34 
     | 
    
         
             
                }
         
     | 
| 
       34 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
                def self.get_scenario_id(filename)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  File.basename(filename, '.yaml')
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       35 
40 
     | 
    
         
             
                def initialize(file, persist = true)
         
     | 
| 
       36 
41 
     | 
    
         
             
                  @config_file = file
         
     | 
| 
       37 
42 
     | 
    
         
             
                  @persist     = persist
         
     | 
| 
         @@ -47,6 +52,7 @@ module Kafo 
     | 
|
| 
       47 
52 
     | 
    
         
             
                  end
         
     | 
| 
       48 
53 
     | 
    
         | 
| 
       49 
54 
     | 
    
         
             
                  @config_dir = File.dirname(@config_file)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @scenario_id = Configuration.get_scenario_id(@config_file)
         
     | 
| 
       50 
56 
     | 
    
         
             
                end
         
     | 
| 
       51 
57 
     | 
    
         | 
| 
       52 
58 
     | 
    
         
             
                def save_configuration(configuration)
         
     | 
| 
         @@ -90,6 +96,14 @@ module Kafo 
     | 
|
| 
       90 
96 
     | 
    
         
             
                  custom_storage[key.to_sym] = value
         
     | 
| 
       91 
97 
     | 
    
         
             
                end
         
     | 
| 
       92 
98 
     | 
    
         | 
| 
      
 99 
     | 
    
         
            +
                def get_custom_fact(key)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  custom_fact_storage[key.to_s]
         
     | 
| 
      
 101 
     | 
    
         
            +
                end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                def set_custom_fact(key, value)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  custom_fact_storage[key.to_s] = value
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
       93 
107 
     | 
    
         
             
                def modules
         
     | 
| 
       94 
108 
     | 
    
         
             
                  @modules ||= begin
         
     | 
| 
       95 
109 
     | 
    
         
             
                    register_data_types
         
     | 
| 
         @@ -148,8 +162,10 @@ module Kafo 
     | 
|
| 
       148 
162 
     | 
    
         | 
| 
       149 
163 
     | 
    
         
             
                def params_default_values
         
     | 
| 
       150 
164 
     | 
    
         
             
                  @params_default_values ||= begin
         
     | 
| 
       151 
     | 
    
         
            -
                     
     | 
| 
       152 
     | 
    
         
            -
                    KafoConfigure.exit_handler.register_cleanup_path 
     | 
| 
      
 165 
     | 
    
         
            +
                    execution_env = ExecutionEnvironment.new(self)
         
     | 
| 
      
 166 
     | 
    
         
            +
                    KafoConfigure.exit_handler.register_cleanup_path(execution_env.directory)
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                    puppetconf = execution_env.configure_puppet('noop' => true)
         
     | 
| 
       153 
169 
     | 
    
         | 
| 
       154 
170 
     | 
    
         
             
                    dump_manifest = <<EOS
         
     | 
| 
       155 
171 
     | 
    
         
             
                      #{includes}
         
     | 
| 
         @@ -305,6 +321,10 @@ EOS 
     | 
|
| 
       305 
321 
     | 
    
         
             
                  app[:custom]
         
     | 
| 
       306 
322 
     | 
    
         
             
                end
         
     | 
| 
       307 
323 
     | 
    
         | 
| 
      
 324 
     | 
    
         
            +
                def custom_fact_storage
         
     | 
| 
      
 325 
     | 
    
         
            +
                  app[:facts]
         
     | 
| 
      
 326 
     | 
    
         
            +
                end
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
       308 
328 
     | 
    
         
             
                def includes
         
     | 
| 
       309 
329 
     | 
    
         
             
                  modules.map do |mod|
         
     | 
| 
       310 
330 
     | 
    
         
             
                    module_dir = module_dirs.find do |dir|
         
     | 
| 
         @@ -0,0 +1,84 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'tmpdir'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'kafo/fact_writer'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'kafo/hiera_configurer'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'kafo/puppet_configurer'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module Kafo
         
     | 
| 
      
 8 
     | 
    
         
            +
              class ExecutionEnvironment
         
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize(config, logger = KafoConfigure.logger)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @config = config
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @logger = logger
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def directory
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @directory ||= begin
         
     | 
| 
      
 16 
     | 
    
         
            +
                    directory = Dir.mktmpdir('kafo_installation')
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @logger.debug("Creating execution environment in #{directory}")
         
     | 
| 
      
 18 
     | 
    
         
            +
                    directory
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def store_answers
         
     | 
| 
      
 23 
     | 
    
         
            +
                  answer_data = HieraConfigurer.generate_data(@config.modules, @config.app[:order])
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @logger.debug("Writing temporary answers to #{answer_file}")
         
     | 
| 
      
 25 
     | 
    
         
            +
                  File.open(answer_file, 'w') { |f| f.write(YAML.dump(answer_data)) }
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def configure_puppet(settings = {})
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @logger.debug("Configuring Puppet in #{directory}")
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  @logger.debug("Writing facts to #{factpath}")
         
     | 
| 
      
 32 
     | 
    
         
            +
                  FactWriter.write_facts(facts, factpath)
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  hiera_config = configure_hiera
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  settings = {
         
     | 
| 
      
 37 
     | 
    
         
            +
                    'environmentpath' => environmentpath,
         
     | 
| 
      
 38 
     | 
    
         
            +
                    'factpath'        => factpath,
         
     | 
| 
      
 39 
     | 
    
         
            +
                    'hiera_config'    => hiera_config,
         
     | 
| 
      
 40 
     | 
    
         
            +
                  }.merge(settings)
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  PuppetConfigurer.new(puppet_conf, settings)
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                private
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                def environmentpath
         
     | 
| 
      
 48 
     | 
    
         
            +
                  File.join(directory, 'environments')
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                def factpath
         
     | 
| 
      
 52 
     | 
    
         
            +
                  File.join(directory, 'facts')
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def answer_file
         
     | 
| 
      
 56 
     | 
    
         
            +
                  File.join(directory, 'answers.yaml')
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                def puppet_conf
         
     | 
| 
      
 60 
     | 
    
         
            +
                  File.join(directory, 'puppet.conf')
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def configure_hiera
         
     | 
| 
      
 64 
     | 
    
         
            +
                  if @config.app[:hiera_config]
         
     | 
| 
      
 65 
     | 
    
         
            +
                    File.realpath(@config.app[:hiera_config])
         
     | 
| 
      
 66 
     | 
    
         
            +
                  else
         
     | 
| 
      
 67 
     | 
    
         
            +
                    config_path = File.join(directory, 'hiera.yaml')
         
     | 
| 
      
 68 
     | 
    
         
            +
                    @logger.debug("Writing default hiera config to #{config_path}")
         
     | 
| 
      
 69 
     | 
    
         
            +
                    HieraConfigurer.write_default_config(config_path)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  end
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                def facts
         
     | 
| 
      
 74 
     | 
    
         
            +
                  {
         
     | 
| 
      
 75 
     | 
    
         
            +
                    'scenario' => {
         
     | 
| 
      
 76 
     | 
    
         
            +
                      'id' => @config.scenario_id,
         
     | 
| 
      
 77 
     | 
    
         
            +
                      'name' => @config.app[:name],
         
     | 
| 
      
 78 
     | 
    
         
            +
                      'answer_file' => answer_file,
         
     | 
| 
      
 79 
     | 
    
         
            +
                      'custom' => @config.app[:facts],
         
     | 
| 
      
 80 
     | 
    
         
            +
                    },
         
     | 
| 
      
 81 
     | 
    
         
            +
                  }
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/kafo/exit_handler.rb
    CHANGED
    
    | 
         @@ -1,11 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Kafo
         
     | 
| 
       2 
2 
     | 
    
         
             
              class ExitHandler
         
     | 
| 
       3 
     | 
    
         
            -
                attr_accessor :cleanup_paths, :exit_code 
     | 
| 
      
 3 
     | 
    
         
            +
                attr_accessor :cleanup_paths, :exit_code
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                def initialize
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @cleanup_paths = []
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @exit_code = 0
         
     | 
| 
       8 
     | 
    
         
            -
                  @logger = KafoConfigure.logger
         
     | 
| 
       9 
8 
     | 
    
         
             
                end
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
10 
     | 
    
         
             
                def error_codes
         
     | 
| 
         @@ -27,8 +26,8 @@ module Kafo 
     | 
|
| 
       27 
26 
     | 
    
         
             
                def exit(code, &block)
         
     | 
| 
       28 
27 
     | 
    
         
             
                  @exit_code = translate_exit_code(code)
         
     | 
| 
       29 
28 
     | 
    
         
             
                  block.call if block
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
                   
     | 
| 
      
 29 
     | 
    
         
            +
                  logger.debug "Exit with status code: #{@exit_code} (signal was #{code})"
         
     | 
| 
      
 30 
     | 
    
         
            +
                  logger.dump_errors unless KafoConfigure.verbose
         
     | 
| 
       32 
31 
     | 
    
         
             
                  cleanup
         
     | 
| 
       33 
32 
     | 
    
         
             
                  Kernel.exit(@exit_code)
         
     | 
| 
       34 
33 
     | 
    
         
             
                end
         
     | 
| 
         @@ -54,5 +53,11 @@ module Kafo 
     | 
|
| 
       54 
53 
     | 
    
         
             
                  self.cleanup_paths<< path
         
     | 
| 
       55 
54 
     | 
    
         
             
                end
         
     | 
| 
       56 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
                private
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                def logger
         
     | 
| 
      
 59 
     | 
    
         
            +
                  @logger ||= KafoConfigure.logger
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
       57 
62 
     | 
    
         
             
              end
         
     | 
| 
       58 
63 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Kafo
         
     | 
| 
      
 2 
     | 
    
         
            +
              class FactWriter
         
     | 
| 
      
 3 
     | 
    
         
            +
                DATA_FILENAME = 'kafo.yaml'
         
     | 
| 
      
 4 
     | 
    
         
            +
                WRAPPER_FILENAME = 'kafo.rb'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def self.write_facts(facts, directory)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  Dir.mkdir(directory)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  # Write a data file containing all the facts encoded as YAML
         
     | 
| 
      
 10 
     | 
    
         
            +
                  File.open(File.join(directory, DATA_FILENAME), 'w') { |f| f.write(YAML.dump(facts)) }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  # Write a Ruby wrapper since only those are executed within puppet
         
     | 
| 
      
 13 
     | 
    
         
            +
                  File.open(File.join(directory, 'kafo.rb'), 'w') { |f| f.write(wrapper) }
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def self.wrapper
         
     | 
| 
      
 17 
     | 
    
         
            +
                  # Ruby 2.0 doesn't have <<~ heredocs
         
     | 
| 
      
 18 
     | 
    
         
            +
                  <<-WRAPPER
         
     | 
| 
      
 19 
     | 
    
         
            +
                  require 'yaml'
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, '#{DATA_FILENAME}')) } }
         
     | 
| 
      
 21 
     | 
    
         
            +
                  WRAPPER
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,111 +1,37 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'fileutils'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'tmpdir'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
1 
     | 
    
         
             
            module Kafo
         
     | 
| 
       5 
2 
     | 
    
         
             
              class HieraConfigurer
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
                def self.default_config
         
     | 
| 
      
 4 
     | 
    
         
            +
                  {
         
     | 
| 
      
 5 
     | 
    
         
            +
                    'version' => 5,
         
     | 
| 
      
 6 
     | 
    
         
            +
                    'hierarchy' => [
         
     | 
| 
      
 7 
     | 
    
         
            +
                      {
         
     | 
| 
      
 8 
     | 
    
         
            +
                        'name' => 'Kafo Answers',
         
     | 
| 
      
 9 
     | 
    
         
            +
                        'path' => '%{facts.kafo.scenario.answer_file}',
         
     | 
| 
      
 10 
     | 
    
         
            +
                        'data_hash' => 'yaml_data',
         
     | 
| 
      
 11 
     | 
    
         
            +
                      },
         
     | 
| 
      
 12 
     | 
    
         
            +
                    ],
         
     | 
| 
      
 13 
     | 
    
         
            +
                  }
         
     | 
| 
       16 
14 
     | 
    
         
             
                end
         
     | 
| 
       17 
15 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                def  
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                  if @user_config_path
         
     | 
| 
       22 
     | 
    
         
            -
                    logger.debug("Merging existing Hiera config file from #{@user_config_path}")
         
     | 
| 
       23 
     | 
    
         
            -
                    user_config = YAML.load(File.read(@user_config_path))
         
     | 
| 
       24 
     | 
    
         
            -
                  else
         
     | 
| 
       25 
     | 
    
         
            -
                    user_config = {}
         
     | 
| 
       26 
     | 
    
         
            -
                  end
         
     | 
| 
       27 
     | 
    
         
            -
                  logger.debug("Writing Hiera config file to #{config_path}")
         
     | 
| 
       28 
     | 
    
         
            -
                  File.open(config_path, 'w') do |f|
         
     | 
| 
       29 
     | 
    
         
            -
                    # merge required config changes into the user's Hiera config
         
     | 
| 
       30 
     | 
    
         
            -
                    f.write(format_yaml_symbols(generate_config(user_config).to_yaml))
         
     | 
| 
       31 
     | 
    
         
            -
                  end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                  logger.debug("Creating Hiera data files in #{data_dir}")
         
     | 
| 
       34 
     | 
    
         
            -
                  FileUtils.mkdir(data_dir)
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                  File.open(File.join(data_dir, HIERARCHY_FILENAME), 'w') do |f|
         
     | 
| 
       37 
     | 
    
         
            -
                    f.write(format_yaml_symbols(generate_data(@modules).to_yaml))
         
     | 
| 
       38 
     | 
    
         
            -
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                def self.write_default_config(path)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  File.open(path, 'w') { |f| f.write(YAML.dump(default_config)) }
         
     | 
| 
      
 18 
     | 
    
         
            +
                  path
         
     | 
| 
       39 
19 
     | 
    
         
             
                end
         
     | 
| 
       40 
20 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                def  
     | 
| 
       42 
     | 
    
         
            -
                  config ||= {}
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                  config['version'] = 5
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                  # ensure there are defaults
         
     | 
| 
       47 
     | 
    
         
            -
                  config['defaults'] ||= {}
         
     | 
| 
       48 
     | 
    
         
            -
                  config['defaults']['datadir'] = determine_data_dir_path(config['defaults']['datadir'])
         
     | 
| 
       49 
     | 
    
         
            -
                  config['defaults']['data_hash'] ||= 'yaml_data'
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                  # ensure our answers file is present and has the right settings
         
     | 
| 
       52 
     | 
    
         
            -
                  config['hierarchy'] ||= []
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                  config['hierarchy'].each do |level|
         
     | 
| 
       55 
     | 
    
         
            -
                    if level['datadir']
         
     | 
| 
       56 
     | 
    
         
            -
                      level['datadir'] = determine_data_dir_path(level['datadir'])
         
     | 
| 
       57 
     | 
    
         
            -
                    end
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                  kafo_answers = config['hierarchy'].find { |level| level['name'] == HIERARCHY_NAME }
         
     | 
| 
       61 
     | 
    
         
            -
                  if kafo_answers
         
     | 
| 
       62 
     | 
    
         
            -
                    kafo_answers.clear
         
     | 
| 
       63 
     | 
    
         
            -
                  else
         
     | 
| 
       64 
     | 
    
         
            -
                    kafo_answers = {}
         
     | 
| 
       65 
     | 
    
         
            -
                    config['hierarchy'].unshift(kafo_answers)
         
     | 
| 
       66 
     | 
    
         
            -
                  end
         
     | 
| 
       67 
     | 
    
         
            -
                  kafo_answers['name'] = HIERARCHY_NAME
         
     | 
| 
       68 
     | 
    
         
            -
                  kafo_answers['path'] = HIERARCHY_FILENAME
         
     | 
| 
       69 
     | 
    
         
            -
                  kafo_answers['datadir'] = data_dir
         
     | 
| 
       70 
     | 
    
         
            -
                  kafo_answers['data_hash'] = 'yaml_data'
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                  config
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                def generate_data(modules)
         
     | 
| 
      
 21 
     | 
    
         
            +
                def self.generate_data(modules, order = nil)
         
     | 
| 
       76 
22 
     | 
    
         
             
                  classes = []
         
     | 
| 
       77 
23 
     | 
    
         
             
                  data = modules.select(&:enabled?).inject({}) do |config, mod|
         
     | 
| 
       78 
24 
     | 
    
         
             
                    classes << mod.class_name
         
     | 
| 
       79 
25 
     | 
    
         
             
                    config.update(Hash[mod.params_hash.map { |k, v| ["#{mod.class_name}::#{k}", v] }])
         
     | 
| 
       80 
26 
     | 
    
         
             
                  end
         
     | 
| 
       81 
     | 
    
         
            -
                  data['classes'] =  
     | 
| 
      
 27 
     | 
    
         
            +
                  data['classes'] = sort_modules(classes, order)
         
     | 
| 
       82 
28 
     | 
    
         
             
                  data
         
     | 
| 
       83 
29 
     | 
    
         
             
                end
         
     | 
| 
       84 
30 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
                def sort_modules(modules, order)
         
     | 
| 
       86 
     | 
    
         
            -
                   
     | 
| 
       87 
     | 
    
         
            -
                end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                def build_temp_dir
         
     | 
| 
       90 
     | 
    
         
            -
                  @temp_dir ||= Dir.mktmpdir('kafo_hiera')
         
     | 
| 
       91 
     | 
    
         
            -
                  @config_path = File.join(temp_dir, 'hiera.conf')
         
     | 
| 
       92 
     | 
    
         
            -
                  @data_dir = File.join(temp_dir, 'data')
         
     | 
| 
       93 
     | 
    
         
            -
                end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                private
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                def format_yaml_symbols(data)
         
     | 
| 
       98 
     | 
    
         
            -
                  data.gsub('!ruby/sym ', ':')
         
     | 
| 
       99 
     | 
    
         
            -
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
                def self.sort_modules(modules, order)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  return modules unless order
         
     | 
| 
       100 
33 
     | 
    
         | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                  # Relies on data_dir being absolute or having a user config
         
     | 
| 
       103 
     | 
    
         
            -
                  path ||= data_dir
         
     | 
| 
       104 
     | 
    
         
            -
                  Pathname.new(path).relative? ? File.join(original_hiera_directory, path) : path
         
     | 
| 
       105 
     | 
    
         
            -
                end
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                def original_hiera_directory
         
     | 
| 
       108 
     | 
    
         
            -
                  @user_config_path ? File.dirname(@user_config_path) : nil
         
     | 
| 
      
 34 
     | 
    
         
            +
                  (order & modules) + (modules - order)
         
     | 
| 
       109 
35 
     | 
    
         
             
                end
         
     | 
| 
       110 
36 
     | 
    
         
             
              end
         
     | 
| 
       111 
37 
     | 
    
         
             
            end
         
     | 
    
        data/lib/kafo/hook_context.rb
    CHANGED
    
    | 
         @@ -93,14 +93,33 @@ module Kafo 
     | 
|
| 
       93 
93 
     | 
    
         
             
                  self.kafo.config.set_custom(key, value)
         
     | 
| 
       94 
94 
     | 
    
         
             
                end
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
      
 96 
     | 
    
         
            +
                # Load a custom fact from the custom fact storage as saved by store_custom_fact
         
     | 
| 
      
 97 
     | 
    
         
            +
                def get_custom_fact(key)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  self.kafo.config.get_custom_fact(key)
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                # Store a any custom fact. This will show up as kafo.scenario.custom.your_fact.
         
     | 
| 
      
 102 
     | 
    
         
            +
                # It is possible to use structures such as arrays and hashes besides the
         
     | 
| 
      
 103 
     | 
    
         
            +
                # obvious ones such as strings, integers, booleans.
         
     | 
| 
      
 104 
     | 
    
         
            +
                #
         
     | 
| 
      
 105 
     | 
    
         
            +
                # These facts can also be used in Hiera hierachy definitions.
         
     | 
| 
      
 106 
     | 
    
         
            +
                def store_custom_fact(key, value)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  self.kafo.config.set_custom_fact(key, value)
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                # Return the id of the current scenario
         
     | 
| 
      
 111 
     | 
    
         
            +
                def scenario_id
         
     | 
| 
      
 112 
     | 
    
         
            +
                  self.kafo.config.scenario_id
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
       96 
115 
     | 
    
         
             
                # Return the path to the current scenario
         
     | 
| 
       97 
116 
     | 
    
         
             
                def scenario_path
         
     | 
| 
       98 
     | 
    
         
            -
                  self.kafo. 
     | 
| 
      
 117 
     | 
    
         
            +
                  self.kafo.config.config_file
         
     | 
| 
       99 
118 
     | 
    
         
             
                end
         
     | 
| 
       100 
119 
     | 
    
         | 
| 
       101 
120 
     | 
    
         
             
                # Return the actual data in the current scenario
         
     | 
| 
       102 
121 
     | 
    
         
             
                def scenario_data
         
     | 
| 
       103 
     | 
    
         
            -
                   
     | 
| 
      
 122 
     | 
    
         
            +
                  self.kafo.config.app
         
     | 
| 
       104 
123 
     | 
    
         
             
                end
         
     | 
| 
       105 
124 
     | 
    
         
             
              end
         
     | 
| 
       106 
125 
     | 
    
         
             
            end
         
     | 
    
        data/lib/kafo/kafo_configure.rb
    CHANGED
    
    | 
         @@ -26,8 +26,7 @@ require 'kafo/progress_bar' 
     | 
|
| 
       26 
26 
     | 
    
         
             
            require 'kafo/hooking'
         
     | 
| 
       27 
27 
     | 
    
         
             
            require 'kafo/exit_handler'
         
     | 
| 
       28 
28 
     | 
    
         
             
            require 'kafo/scenario_manager'
         
     | 
| 
       29 
     | 
    
         
            -
            require 'kafo/ 
     | 
| 
       30 
     | 
    
         
            -
            require 'kafo/puppet_configurer'
         
     | 
| 
      
 29 
     | 
    
         
            +
            require 'kafo/execution_environment'
         
     | 
| 
       31 
30 
     | 
    
         | 
| 
       32 
31 
     | 
    
         
             
            module Kafo
         
     | 
| 
       33 
32 
     | 
    
         
             
              class KafoConfigure < Clamp::Command
         
     | 
| 
         @@ -424,20 +423,17 @@ module Kafo 
     | 
|
| 
       424 
423 
     | 
    
         
             
                def run_installation
         
     | 
| 
       425 
424 
     | 
    
         
             
                  self.class.hooking.execute(:pre)
         
     | 
| 
       426 
425 
     | 
    
         | 
| 
       427 
     | 
    
         
            -
                   
     | 
| 
       428 
     | 
    
         
            -
                   
     | 
| 
       429 
     | 
    
         
            -
             
     | 
| 
       430 
     | 
    
         
            -
             
     | 
| 
       431 
     | 
    
         
            -
                  puppetconf =  
     | 
| 
       432 
     | 
    
         
            -
                    'color' 
     | 
| 
       433 
     | 
    
         
            -
                    'evaltrace' 
     | 
| 
       434 
     | 
    
         
            -
                    ' 
     | 
| 
       435 
     | 
    
         
            -
                    ' 
     | 
| 
       436 
     | 
    
         
            -
                    ' 
     | 
| 
       437 
     | 
    
         
            -
                    'show_diff'       => true,
         
     | 
| 
       438 
     | 
    
         
            -
                    'environmentpath' => hiera.temp_dir,
         
     | 
| 
      
 426 
     | 
    
         
            +
                  execution_env = ExecutionEnvironment.new(config)
         
     | 
| 
      
 427 
     | 
    
         
            +
                  self.class.exit_handler.register_cleanup_path(execution_env.directory)
         
     | 
| 
      
 428 
     | 
    
         
            +
             
     | 
| 
      
 429 
     | 
    
         
            +
                  execution_env.store_answers
         
     | 
| 
      
 430 
     | 
    
         
            +
                  puppetconf = execution_env.configure_puppet(
         
     | 
| 
      
 431 
     | 
    
         
            +
                    'color'     => false,
         
     | 
| 
      
 432 
     | 
    
         
            +
                    'evaltrace' => !!@progressbar,
         
     | 
| 
      
 433 
     | 
    
         
            +
                    'noop'      => !!noop?,
         
     | 
| 
      
 434 
     | 
    
         
            +
                    'profile'   => !!profile?,
         
     | 
| 
      
 435 
     | 
    
         
            +
                    'show_diff' => true,
         
     | 
| 
       439 
436 
     | 
    
         
             
                  )
         
     | 
| 
       440 
     | 
    
         
            -
                  self.class.exit_handler.register_cleanup_path(puppetconf.config_path)
         
     | 
| 
       441 
437 
     | 
    
         | 
| 
       442 
438 
     | 
    
         
             
                  exit_code   = 0
         
     | 
| 
       443 
439 
     | 
    
         
             
                  exit_status = nil
         
     | 
    
        data/lib/kafo/puppet_command.rb
    CHANGED
    
    | 
         @@ -6,8 +6,12 @@ module Kafo 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  @command = command
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @puppet_config = puppet_config
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
                  if puppet_config
         
     | 
| 
      
 10 
     | 
    
         
            +
                    puppet_config['basemodulepath'] = modules_path.join(':')
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @options = options.push("--config=#{puppet_config.config_path}")
         
     | 
| 
      
 12 
     | 
    
         
            +
                  else
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @options = options.push("--modulepath #{modules_path.join(':')}")
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
       11 
15 
     | 
    
         
             
                  @logger  = KafoConfigure.logger
         
     | 
| 
       12 
16 
     | 
    
         
             
                  @puppet_version_check = !configuration.app[:skip_puppet_version_check]
         
     | 
| 
       13 
17 
     | 
    
         
             
                  @suffix = nil
         
     | 
| 
         @@ -2,16 +2,12 @@ require 'tempfile' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Kafo
         
     | 
| 
       4 
4 
     | 
    
         
             
              class PuppetConfigurer
         
     | 
| 
       5 
     | 
    
         
            -
                attr_reader :logger
         
     | 
| 
      
 5 
     | 
    
         
            +
                attr_reader :logger, :config_path
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                def initialize(settings = {})
         
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize(config_path, settings = {})
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @config_path = config_path
         
     | 
| 
       8 
9 
     | 
    
         
             
                  @settings = {'reports' => ''}.merge(settings)
         
     | 
| 
       9 
10 
     | 
    
         
             
                  @logger = KafoConfigure.logger
         
     | 
| 
       10 
     | 
    
         
            -
                  @temp_file = Tempfile.new(['kafo_puppet', '.conf'])
         
     | 
| 
       11 
     | 
    
         
            -
                end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                def config_path
         
     | 
| 
       14 
     | 
    
         
            -
                  @temp_file.path
         
     | 
| 
       15 
11 
     | 
    
         
             
                end
         
     | 
| 
       16 
12 
     | 
    
         | 
| 
       17 
13 
     | 
    
         
             
                def [](key)
         
     | 
| 
         @@ -23,15 +19,13 @@ module Kafo 
     | 
|
| 
       23 
19 
     | 
    
         
             
                end
         
     | 
| 
       24 
20 
     | 
    
         | 
| 
       25 
21 
     | 
    
         
             
                def write_config
         
     | 
| 
       26 
     | 
    
         
            -
                  @logger.debug("Writing Puppet config file at #{ 
     | 
| 
       27 
     | 
    
         
            -
                   
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
      
 22 
     | 
    
         
            +
                  @logger.debug("Writing Puppet config file at #{config_path}")
         
     | 
| 
      
 23 
     | 
    
         
            +
                  File.open(config_path, 'w') do |file|
         
     | 
| 
      
 24 
     | 
    
         
            +
                    file.puts '[main]'
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @settings.keys.sort.each do |key|
         
     | 
| 
      
 26 
     | 
    
         
            +
                      file.puts "#{key} = #{@settings[key]}"
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
       32 
28 
     | 
    
         
             
                  end
         
     | 
| 
       33 
     | 
    
         
            -
                ensure
         
     | 
| 
       34 
     | 
    
         
            -
                  @temp_file.close
         
     | 
| 
       35 
29 
     | 
    
         
             
                end
         
     | 
| 
       36 
30 
     | 
    
         
             
              end
         
     | 
| 
       37 
31 
     | 
    
         
             
            end
         
     | 
    
        data/lib/kafo/puppet_module.rb
    CHANGED
    
    | 
         @@ -160,7 +160,7 @@ module Kafo 
     | 
|
| 
       160 
160 
     | 
    
         
             
                end
         
     | 
| 
       161 
161 
     | 
    
         | 
| 
       162 
162 
     | 
    
         
             
                def default_params_path
         
     | 
| 
       163 
     | 
    
         
            -
                  "#{dir_name}/manifests/#{get_params_name}.pp"
         
     | 
| 
      
 163 
     | 
    
         
            +
                  "#{dir_name}/manifests/#{class_to_name(get_params_name)}.pp"
         
     | 
| 
       164 
164 
     | 
    
         
             
                end
         
     | 
| 
       165 
165 
     | 
    
         | 
| 
       166 
166 
     | 
    
         
             
                def default_manifest_name
         
     | 
| 
         @@ -179,5 +179,9 @@ module Kafo 
     | 
|
| 
       179 
179 
     | 
    
         
             
                  name.gsub('/', '::')
         
     | 
| 
       180 
180 
     | 
    
         
             
                end
         
     | 
| 
       181 
181 
     | 
    
         | 
| 
      
 182 
     | 
    
         
            +
                def class_to_name(name)
         
     | 
| 
      
 183 
     | 
    
         
            +
                  name.gsub('::', '/')
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
       182 
186 
     | 
    
         
             
              end
         
     | 
| 
       183 
187 
     | 
    
         
             
            end
         
     | 
| 
         @@ -19,7 +19,7 @@ module Kafo 
     | 
|
| 
       19 
19 
     | 
    
         
             
                      content = YAML.load_file(scn_file)
         
     | 
| 
       20 
20 
     | 
    
         
             
                      if content.is_a?(Hash) && content.has_key?(:answer_file) && content.fetch(:enabled, true)
         
     | 
| 
       21 
21 
     | 
    
         
             
                        # add scenario name for legacy configs
         
     | 
| 
       22 
     | 
    
         
            -
                        content[:name] =  
     | 
| 
      
 22 
     | 
    
         
            +
                        content[:name] = Configuration.get_scenario_id(scn_file) unless content.has_key?(:name)
         
     | 
| 
       23 
23 
     | 
    
         
             
                        scns[scn_file] = content
         
     | 
| 
       24 
24 
     | 
    
         
             
                      end
         
     | 
| 
       25 
25 
     | 
    
         
             
                    rescue Psych::SyntaxError => e
         
     | 
    
        data/lib/kafo/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: kafo
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 4.0.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Marek Hulan
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-10-17 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -59,7 +59,7 @@ dependencies: 
     | 
|
| 
       59 
59 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       60 
60 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       61 
61 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       62 
     | 
    
         
            -
              name:  
     | 
| 
      
 62 
     | 
    
         
            +
              name: minitest-reporters
         
     | 
| 
       63 
63 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       64 
64 
     | 
    
         
             
                requirements:
         
     | 
| 
       65 
65 
     | 
    
         
             
                - - ">="
         
     | 
| 
         @@ -73,19 +73,19 @@ dependencies: 
     | 
|
| 
       73 
73 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       74 
74 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       75 
75 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       76 
     | 
    
         
            -
              name:  
     | 
| 
      
 76 
     | 
    
         
            +
              name: simplecov
         
     | 
| 
       77 
77 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       78 
78 
     | 
    
         
             
                requirements:
         
     | 
| 
       79 
79 
     | 
    
         
             
                - - ">="
         
     | 
| 
       80 
80 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       81 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 81 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       82 
82 
     | 
    
         
             
              type: :development
         
     | 
| 
       83 
83 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       84 
84 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       85 
85 
     | 
    
         
             
                requirements:
         
     | 
| 
       86 
86 
     | 
    
         
             
                - - ">="
         
     | 
| 
       87 
87 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       88 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 88 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       89 
89 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       90 
90 
     | 
    
         
             
              name: kafo_wizards
         
     | 
| 
       91 
91 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -149,6 +149,9 @@ dependencies: 
     | 
|
| 
       149 
149 
     | 
    
         
             
                - - ">="
         
     | 
| 
       150 
150 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       151 
151 
     | 
    
         
             
                    version: 0.6.2
         
     | 
| 
      
 152 
     | 
    
         
            +
                - - "<"
         
     | 
| 
      
 153 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 154 
     | 
    
         
            +
                    version: 1.3.1
         
     | 
| 
       152 
155 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       153 
156 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       154 
157 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -156,6 +159,9 @@ dependencies: 
     | 
|
| 
       156 
159 
     | 
    
         
             
                - - ">="
         
     | 
| 
       157 
160 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       158 
161 
     | 
    
         
             
                    version: 0.6.2
         
     | 
| 
      
 162 
     | 
    
         
            +
                - - "<"
         
     | 
| 
      
 163 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 164 
     | 
    
         
            +
                    version: 1.3.1
         
     | 
| 
       159 
165 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       160 
166 
     | 
    
         
             
              name: highline
         
     | 
| 
       161 
167 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -239,7 +245,9 @@ files: 
     | 
|
| 
       239 
245 
     | 
    
         
             
            - lib/kafo/data_types/undef.rb
         
     | 
| 
       240 
246 
     | 
    
         
             
            - lib/kafo/data_types/variant.rb
         
     | 
| 
       241 
247 
     | 
    
         
             
            - lib/kafo/exceptions.rb
         
     | 
| 
      
 248 
     | 
    
         
            +
            - lib/kafo/execution_environment.rb
         
     | 
| 
       242 
249 
     | 
    
         
             
            - lib/kafo/exit_handler.rb
         
     | 
| 
      
 250 
     | 
    
         
            +
            - lib/kafo/fact_writer.rb
         
     | 
| 
       243 
251 
     | 
    
         
             
            - lib/kafo/help_builder.rb
         
     | 
| 
       244 
252 
     | 
    
         
             
            - lib/kafo/help_builders/advanced.rb
         
     | 
| 
       245 
253 
     | 
    
         
             
            - lib/kafo/help_builders/base.rb
         
     | 
| 
         @@ -256,7 +264,6 @@ files: 
     | 
|
| 
       256 
264 
     | 
    
         
             
            - lib/kafo/param_group.rb
         
     | 
| 
       257 
265 
     | 
    
         
             
            - lib/kafo/parser_cache_reader.rb
         
     | 
| 
       258 
266 
     | 
    
         
             
            - lib/kafo/parser_cache_writer.rb
         
     | 
| 
       259 
     | 
    
         
            -
            - lib/kafo/password_manager.rb
         
     | 
| 
       260 
267 
     | 
    
         
             
            - lib/kafo/progress_bar.rb
         
     | 
| 
       261 
268 
     | 
    
         
             
            - lib/kafo/progress_bars/black_white.rb
         
     | 
| 
       262 
269 
     | 
    
         
             
            - lib/kafo/progress_bars/colored.rb
         
     | 
| 
         @@ -308,8 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       308 
315 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       309 
316 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       310 
317 
     | 
    
         
             
            requirements: []
         
     | 
| 
       311 
     | 
    
         
            -
             
     | 
| 
       312 
     | 
    
         
            -
            rubygems_version: 2.7.6
         
     | 
| 
      
 318 
     | 
    
         
            +
            rubygems_version: 3.0.3
         
     | 
| 
       313 
319 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       314 
320 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       315 
321 
     | 
    
         
             
            summary: A gem for making installations based on puppet user friendly
         
     | 
| 
         @@ -1,47 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # encoding: UTF-8
         
     | 
| 
       2 
     | 
    
         
            -
            require 'securerandom'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'digest/sha2'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'openssl'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'base64'
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            module Kafo
         
     | 
| 
       8 
     | 
    
         
            -
              class PasswordManager
         
     | 
| 
       9 
     | 
    
         
            -
                # generate a random password of lenght n
         
     | 
| 
       10 
     | 
    
         
            -
                #
         
     | 
| 
       11 
     | 
    
         
            -
                # on ruby >= 1.9 we use builtin method urlsafe_base64, on olders we use our own
         
     | 
| 
       12 
     | 
    
         
            -
                # implementation (inspired by urlsafe_base64)
         
     | 
| 
       13 
     | 
    
         
            -
                #
         
     | 
| 
       14 
     | 
    
         
            -
                # the result may contain A-Z, a-z, 0-9, “-” and “_”. “=”
         
     | 
| 
       15 
     | 
    
         
            -
                def password(n = 32)
         
     | 
| 
       16 
     | 
    
         
            -
                  return SecureRandom.urlsafe_base64(n) if SecureRandom.respond_to?(:urlsafe_base64)
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                  s = [SecureRandom.random_bytes(n)].pack("m*")
         
     | 
| 
       19 
     | 
    
         
            -
                  s.delete!("\n")
         
     | 
| 
       20 
     | 
    
         
            -
                  s.tr!("+/", "-_")
         
     | 
| 
       21 
     | 
    
         
            -
                  s.delete!("=")
         
     | 
| 
       22 
     | 
    
         
            -
                  s
         
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                def aes_encrypt(text, passphrase)
         
     | 
| 
       26 
     | 
    
         
            -
                  cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
         
     | 
| 
       27 
     | 
    
         
            -
                  cipher.encrypt
         
     | 
| 
       28 
     | 
    
         
            -
                  cipher.key = Digest::SHA2.hexdigest(passphrase)
         
     | 
| 
       29 
     | 
    
         
            -
                  cipher.iv  = Digest::SHA2.hexdigest(passphrase + passphrase)
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  encrypted = cipher.update(text)
         
     | 
| 
       32 
     | 
    
         
            -
                  encrypted << cipher.final
         
     | 
| 
       33 
     | 
    
         
            -
                  Base64.encode64(encrypted)
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                def aes_decrypt(text, passphrase)
         
     | 
| 
       37 
     | 
    
         
            -
                  cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
         
     | 
| 
       38 
     | 
    
         
            -
                  cipher.decrypt
         
     | 
| 
       39 
     | 
    
         
            -
                  cipher.key = Digest::SHA2.hexdigest(passphrase)
         
     | 
| 
       40 
     | 
    
         
            -
                  cipher.iv  = Digest::SHA2.hexdigest(passphrase + passphrase)
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                  decrypted = cipher.update(Base64.decode64(text))
         
     | 
| 
       43 
     | 
    
         
            -
                  decrypted << cipher.final
         
     | 
| 
       44 
     | 
    
         
            -
                  decrypted
         
     | 
| 
       45 
     | 
    
         
            -
                end
         
     | 
| 
       46 
     | 
    
         
            -
              end
         
     | 
| 
       47 
     | 
    
         
            -
            end
         
     |