kafo 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md DELETED
@@ -1,1112 +0,0 @@
1
- # Kafo
2
-
3
- A puppet based installer and configurer (not-only) for Foreman and Katello
4
- projects. Kafo is a ruby gem that allows you to create fancy user interfaces for
5
- puppet modules. It's some kind of a nice frontend to a
6
-
7
- ```bash
8
- echo "include some_modules" | puppet apply
9
- ```
10
- ## Why should I care?
11
-
12
- Suppose you work on software which you want to distribute to a machine in an
13
- infrastructure managed by puppet. You write a puppet module for your app.
14
- But now you also want to be able to distribute your app to a machine outside of
15
- your puppet infrastructure (e.g. install it to your clients) or you want to install
16
- it in order to create a puppet infrastructure itself (e.g. foreman or
17
- foreman-proxy).
18
-
19
- With kafo you can reuse your puppet modules for creating an installer.
20
- Even better: After the installation you can easily modify your configuration.
21
- All using the very same puppet modules.
22
-
23
- With your installer you can also provide multiple configuration files defining
24
- different installation scenarios.
25
-
26
- ## What does it do, how does it work?
27
-
28
- Kafo reads a config file to find out which modules it should use. Then it
29
- loads parameters from puppet manifests and gives you different ways to customize them.
30
-
31
- There are three options how you can set parameters. You can
32
- * predefine them in the configuration file
33
- * specify them as CLI arguments
34
- * you can use the interactive mode which will ask you for all required parameters
35
-
36
- Note that your answers (gathered from any mode) are automatically saved for the next run
37
- so you don't have to specify them again. Kafo also supports default values for
38
- parameters so you can set only those you want to change. You can also combine
39
- all modes to create an answer file with default values easily
40
- and then use it for unattended installations.
41
-
42
- ## How do I use it?
43
-
44
- First install the kafo gem.
45
-
46
- Using bundler - add kafo gem to your Gemfile and run
47
- ```bash
48
- bundle install
49
- ```
50
-
51
- or without bundler
52
- ```bash
53
- gem install kafo
54
- ```
55
-
56
- Create a directory for your installer. Let's say we want to create a
57
- foreman-installer.
58
-
59
- ```bash
60
- mkdir foreman-installer
61
- cd foreman-installer
62
- ```
63
-
64
- Now we run ```kafofy``` script which will prepare the directory structure and
65
- optionally create a bin script according to the first parameter.
66
-
67
- ```bash
68
- kafofy -n foreman-installer -s foreman
69
- ```
70
-
71
- You can see that it created a modules directory where your puppet modules
72
- should live. It also created config and bin directories and the default installation
73
- scenario config file. If you specify the argument ```--name``` (or -n for short,
74
- foreman-installer in this case) a script in the "bin" directory with this name will be created.
75
-
76
- It's the script you can use to run the installer. If you did not specify any
77
- arguments you can run your installer by `kafo-configure` which is the default.
78
- All configuration related files are to be found in the config directory.
79
-
80
- You can supply custom location for your scenario configuration and answer files
81
- and change configuration and answer files names using options:
82
- ```
83
- kafofy --help
84
- Usage: kafofy [options]
85
- -c, --config_dir DIR location of the scenarios configuration directory [./config/installer-scenarios.d/]
86
- -s, --scenario SCENARIO scenario file name (without extension) [default]
87
- -a, --answer_file ANSWERS answer file file name (without extension) [default-answers]
88
- -n, --name NAME installer name [kafo-configure]
89
- ```
90
-
91
- The scenario configuration file will be created by a default template. It's the configuration
92
- of your installer (so you can setup the log level, path to puppet modules etc).
93
- On the other hand, the answer file must be created manually. Answer files define
94
- which modules should be used and hold all values for the puppet class parameters.
95
-
96
- To add another installation scenario just run kafofy again:
97
- ```bash
98
- kafofy -n foreman-installer -s foreman-proxy
99
- ```
100
- it will create new configuration template for you. You can check available scenarios with:
101
- ```bash
102
- $ bin/foreman-installer --list-scenarios
103
- Available scenarios
104
- foreman-proxy (use: --scenario foreman-proxy)
105
- foreman (use: --scenario foreman)
106
- ```
107
-
108
- Let's see for example how to install foreman:
109
- ```bash
110
- cd foreman-installer/modules
111
- git clone https://github.com/theforeman/puppet-foreman/ foreman
112
- ```
113
- You must also download any dependant modules.
114
- Then you need to tell kafo it's going to use the foreman module.
115
- ```bash
116
- cd ..
117
- echo "foreman: true" > config/installer-scenarios.d/foreman-answers.yaml
118
- ```
119
-
120
- Alternatively you can use the librarian-puppet project to manage all dependencies for you.
121
- You just create a Puppetfile and call librarian to install your modules. See
122
- https://github.com/rodjek/librarian-puppet for more details.
123
-
124
- When you have your modules in-place, fire the installer with -h as argument
125
- and specify the foreman scenario to let installer find the right modules
126
- ```bash
127
- bin/foreman-installer -S foreman -h
128
- ```
129
-
130
- This will show you all the possible arguments you can pass to kafo. Note that underscored
131
- puppet parameters are automatically converted to dashed arguments. You can
132
- also see a documentation extracted from the foreman puppet module and a default
133
- value.
134
-
135
- Now run it without the -h argument. It will print you the puppet apply command
136
- to execute. This will be automatized later. Once the installer is run the scenario
137
- is remembered and it is not necessary to specify it again.
138
- Look at config/answers.yaml, it was populated with default values.
139
- To change those options you can use arguments like this
140
-
141
- ```bash
142
- bin/foreman-installer --foreman-enc=false --foreman-db-type=sqlite
143
- ```
144
-
145
- or you can run it in interactive mode
146
-
147
- ```bash
148
- bin/foreman-installer --interactive
149
- ```
150
-
151
- Also every change made to the `config/installer-scenarios.d/foreman-answers.yaml` persists
152
- and becomes the new default value for the next run.
153
-
154
- As you may have noticed there are several ways how to specify arguments. Here's the list:
155
- (the lower the item is in this list the higher precedence it has):
156
- * default values from puppet modules
157
- * values from answers.yaml
158
- * values specified on CLI
159
- * interactive mode arguments
160
-
161
- ## Requirements
162
-
163
- Kafo is supported with Puppet versions 3 and 4. Puppet 2 is no longer supported
164
- in current versions, use an older version of Kafo or update Puppet.
165
-
166
- Puppet may be installed as a gem (add it to Gemfile) or through a package,
167
- including official AIO packages.
168
-
169
- ## How do I report bugs or contribute?
170
-
171
- You can find our redmine issue tracker [here](http://projects.theforeman.org/projects/kafo),
172
- you can use your github account for logging in. When reporting new issues please
173
- don't forget to specify your:
174
- * puppet version
175
- * installation options (GEM/RPM/DEB)
176
- * error trace (if any) or log with debug level
177
- * reproducing steps
178
-
179
- Since Kafo is a side project of Foreman you can use its IRC channels to
180
- contact us on freenode. #theforeman is the channel for generic discussions
181
- and #theforeman-dev is reserved only for technical topics. Likewise you can use the Foreman
182
- mailing lists on googlegroups. For more information see [this page](http://theforeman.org/support.html)
183
-
184
- Patches are always welcome. You can use instructions for Foreman, just
185
- substitute Foreman with Kafo. More details are [here](http://projects.theforeman.org/projects/foreman/wiki/Contribute#New-Way-github)
186
-
187
- # Advanced topics
188
-
189
- ## Testing aka noop etc
190
-
191
- Since you'll probably want to tweak your installer before you run it, you may find the
192
- ```--noop``` argument handy (-n for short). This will run puppet in
193
- noop so no change will be done to your system. The default value here is set to
194
- false!
195
-
196
- Sometimes you may want kafo not to store answers from the current run. You can
197
- disable saving answer by passing a ```--dont-save-answers``` argument (or -d for short).
198
-
199
- Note that running ```--noop``` implies ```--dont-save-answers```.
200
-
201
- ## Executing Puppet with multiple versions
202
-
203
- Kafo calls the `puppet` binary during an installer run to both compute default
204
- parameter values and perform the actual installer changes. This relies on
205
- `puppet` being in the PATH environment variable or as fallback, in
206
- `/opt/puppetlabs/bin`.
207
-
208
- When using Puppet via a Gemfile, Bundler should set up PATH to point at the
209
- gem version. If using a system/packaged version, it will typically find and
210
- execute /usr/bin/puppet from the regular PATH.
211
-
212
- When using an AIO/PC1 packaged version of Puppet, other versions of Puppet from
213
- PATH will be preferred if they exist, so they should either be removed or PATH
214
- set to prefer /opt/puppetlabs/bin, i.e. `export PATH=/opt/puppetlabs/bin:$PATH`.
215
- Debug logs from Kafo should indicate the full path of the binary used.
216
-
217
- Note that Kafo parsers supports specific versions of Puppet, and may require
218
- extra modules (such as puppet-strings on Puppet 4+) to parse manifests.
219
-
220
- ## Parameters prefixes
221
-
222
- As a default every module parameter is prefixed by the module name.
223
- If you use just one module it's probably not necessary and you
224
- can disable this behavior in config/kafo.yaml. Just enable the following option
225
- ```yaml
226
- :no_prefix: true
227
- ```
228
- ## Scenarios
229
-
230
- With your installer you can provide multiple configuration files aka. scenarios.
231
- Every scenario has its own answer file to store the scenario settings.
232
- The files are kept in `installer-scenarios.d/` directory.
233
-
234
- ### Using scenarios
235
-
236
- To list scenarios available on your system
237
- ```bash
238
- foreman-installer --list-scenarios
239
- ```
240
-
241
- The installer needs to know the configuration even for such a basic operation
242
- as printing help is because it contains basic settings and defines where
243
- to look for module parameters. There are multiple ways how the installer can select the scenario:
244
- * from a command line argument `-S` or `--scenario`
245
- ```bash
246
- foreman-installer --scenario foreman -h
247
- ...
248
- ```
249
- * by user selection in interractive mode (`-i` or `--interractive`)
250
- ```bash
251
- foreman-installer -i
252
-
253
- Select installation scenario
254
-
255
- Please select one of the pre-set installation scenarios. You can customize your installtion later during the installtion.
256
-
257
- Available actions:
258
- 1. Foreman: Basic and most generic installation of Foreman
259
- 2. Foreman Proxy: Install Foreman proxy without Foreman
260
- 3. Cancel Installation
261
- Your choice:
262
- ```
263
- * automatically if there is only one scenario available
264
- * automatically if installer was ran already with scenario selected
265
-
266
- ### Re-installing with different scenario
267
-
268
- Lets assume you have already completed installation with one scenario (e.g. smart-proxy).
269
- Now you want to reinstall or upgrade with different scenario (e.g. foreman). This is tricky
270
- situation and may end with unpredictable results so you should double check
271
- if the scenario and the puppet modules used in it support such kind of change.
272
-
273
- Installer tries to prevent unintentional change of a scenario and interrupts when such situation is detected:
274
- ```bash
275
- foreman-installer -S foreman-installer
276
- ERROR: You are trying to replace existing installation with different scenario. This may lead to unpredictable states. Use --force to override. You can use --compare-scenarios to see the differences
277
- ```
278
-
279
- To avoid losing some configuration values installer can detect differences between answer files of the two scenarios.
280
- To display them use either interactive mode (`-i`) or `--compare-scenarios` flag:
281
- ```bash
282
- foreman-installer --compare-scenarios --scenario foreman
283
- Scenarios are being compared, that may take a while...
284
-
285
- Values from previous installation that will be added by installer:
286
- foreman_proxy::http_port: 8000 -> 8080
287
-
288
- Values from previous installation that will be lost by scenario change:
289
- foreman_proxy::plugin::abrt::enabled: true
290
- ...
291
- ```
292
-
293
- It may take some time as the installer has to evaluate default values for both scenarios. As a result it prints two lists.
294
- - __Values from previous installation that will be added by installer:__ - in this list are options present in both scenarios but having different default values.
295
- The only item from the example says that the default value for the new scenario is '8000' while the value for currently intalled scenario is '8080'.
296
- When the new scenario is used the installer tries to keep the customized values from current installation and thus will use the `8080` value
297
- - __Values from previous installation that will be lost by scenario change:__ - this list contains options that are part of current installation
298
- and are missing from the new scenario. Most of the items are options from puppet modules that are disabled in the new scenario by default but were enabled
299
- in the old one.
300
-
301
- If you are sure you want to proceed use `--force` to run the installation. Installer will replace
302
- the default values with values from the previous installation where possible as was indicated in the `--compare-scenario` output.
303
-
304
- ### Adding scenario
305
-
306
- You can add new scenario using kafofy as it was explained earlier or by creating
307
- config and answer file in the `installer-scenarios.d/` directory.
308
- [Template](https://github.com/theforeman/kafo/blob/master/config/kafo.yaml.example)
309
- provided by Kafo can be used and customized to satisfy your needs
310
- ```bash
311
- cp `gem content kafo|grep "kafo.yaml.example"` <config>/installer-scenarios.d/new-scenario.yaml
312
- touch <config>/installer-scenarios.d/new-scenario-answers.yaml
313
- ```
314
-
315
- ### Scenario as an installer plugin
316
-
317
- Scenarios were designed to make it possible to package them separately as optional installer extension.
318
- Config files are located in separate directory which makes packaging of additional scenarios easy.
319
- Configuration of paths to modules, checks and hooks accepts multiple directories
320
- so it is possible to bundle your scenario with additional modules, hooks and checks.
321
-
322
- ### Updating scenarios
323
-
324
- As your project grows you may need to change your installer modules or add new ones. To make upgrades of existing installations easier
325
- Kafo has support for scenario migrations. Migrations are ruby scripts similar to hooks and are located
326
- in `<config>/installer-scenarios.d/your-scenario.migrations/` so each scenario has its own set of independent migrations.
327
- During its initialization the installer checks for migrations that were not applied yet. It happens exactly between execution of `pre-migrations` and `boot` hooks.
328
- The installer stores names of applied migrations in `<config>/installer-scenarios.d/your-scenario.migrations/.applied` to avoid runnig the migrations multiple times.
329
- It is recommended to prefix the migration names with `date +%y%m%d%H%M%S` to avoid migration ordering issues.
330
-
331
- In a migration you can modify the scenario configuration as well as the answer file. The changed configs are stored immediately after all the migrations were applied.
332
- If you just want to apply the migrations you can use `--migrations-only` switch.
333
- Note that `--noop` and `--dont-save-answers` has no effect on migrations.
334
-
335
- Sample migration adding new module could look like as follows:
336
-
337
- ```bash
338
- cat <<EOF > "/etc/foreman/installer-scenarios.d/foreman-installer.migrations/`date +%y%m%d%H%M%S`-gutterball.rb"
339
- scenario[:mapping]['katello::plugin::gutterball'] = {
340
- :dir_name => 'katello',
341
- :manifest_name => 'plugin/gutterball'
342
- }
343
- answers['katello::plugin::gutterball'] = true
344
- EOF
345
- ```
346
-
347
- The migration can also call `facts`, which returns a hash of symbol fact names to values (from
348
- Facter), to help determine new parameter values.
349
-
350
- ```ruby
351
- answers['module']['foo'] = 'bar' if facts[:osfamily] == 'Debian'
352
- ```
353
-
354
- ### Enabling/disabling scenarios
355
-
356
- Scenarios that are deprecated or wanted to be hidden on the system can be disabled with:
357
-
358
- ```bash
359
- foreman-installer --disable-scenario deprecated-scenario
360
- Scenario deprecated-scenario was disabled.
361
- ```
362
- The disabled scenario is not shown in the scenario list and is prevented from being installed.
363
- It is not deleted from the file system however so the custom values in the answer file are preserved
364
- and e.g. migration to new scenario is still possible.
365
-
366
- Disabled scenario can be enabled back again with `foreman-installer --enable-scenario SCENARIO`.
367
-
368
- ## Store
369
-
370
- Kafo features simple key value store that can be used to ship data with the installer.
371
-
372
- The data are loaded from yaml files located in `store.d` directory that is either specified in
373
- the scenario config's `store_dir:` or on same directory
374
- level as configuration directory containing the scenarios. The files are loaded in
375
- alphabetical order and the data are merged in that order.
376
-
377
- The store is read-only during the run and the content can be influenced only by adding
378
- new files into the `store.d` directory (e.g. from installer plugins)
379
-
380
- ## Documentation
381
-
382
- Every parameter that can be set by kafo *must* be documented. This means that
383
- you must add documentation to your puppet class in init.pp. It's basically a
384
- rdoc formatted documentation that must be above the class definitions. There can
385
- be no space between the doc block and the class definition.
386
-
387
- In case of emergency, it's still possible to use
388
- `--ignore-undocumented` option, but in general it's not recommended to override it.
389
-
390
- Example:
391
- ```puppet
392
- # Manage your foreman server
393
- #
394
- # This class ...
395
- # ... does what it does.
396
- #
397
- # === Parameters:
398
- #
399
- # $foreman_url:: URL on which foreman is going to run
400
- #
401
- # $enc:: Should foreman act as an external node classifier (manage puppet class
402
- # assignments)
403
- #
404
- class foreman (
405
- String $foreman_url = $foreman::params::foreman_url,
406
- Boolean $enc = $foreman::params::enc
407
- ) {
408
- class { 'foreman::install': }
409
- }
410
- ```
411
-
412
- You can separate your parameters into groups like this.
413
-
414
- Example - separating parameters into groups:
415
- ```puppet
416
- # Manage your foreman server
417
- #
418
- # === Parameters:
419
- #
420
- # $foreman_url:: URL on which foreman is going to run
421
- #
422
- # === Advanced parameters:
423
- #
424
- # $foreman_port:: Foreman listens on this port
425
- #
426
- # ==== MySQL:
427
- #
428
- # $mysql_host:: MySQL server address
429
- ```
430
-
431
- When you run the installer with the ```--help``` argument it displays only
432
- parameters specified in the ```=== Parameters:``` group. If you don't specify
433
- any group all parameters will be considered as basic and will be displayed.
434
-
435
- If you run the installer with ```--full-help``` you'll receive help for all
436
- parameters divided into groups. Note that only headers that include word
437
- parameters are considered as parameter groups. Other headers are ignored.
438
- Also note that you can nest parameter groups and the child has precedence.
439
- Help output does not take header level into account though.
440
-
441
- So in the previous example, each parameter would be printed in one group even
442
- though MySQL is a child of Advanced parameter. All groups in help would be
443
- prefixed with a second level (==). The first level is always a module to which
444
- the particular parameter belongs.
445
-
446
- ## Argument types
447
-
448
- When using Puppet 4 or newer, the data type will be read from the parameter
449
- list and defaults to Puppet's [Any](https://docs.puppet.com/puppet/latest/reference/lang_data_abstract.html#any)
450
- data type, which Kafo handles as a basic string with no validation.
451
-
452
- If more specific data types, such as `Optional[Array[2]]` or similar are
453
- given in the [parameter list](https://docs.puppet.com/puppet/4.5/reference/lang_data_type.html#usage)
454
- then Kafo will parse and validate parameters values according to the
455
- specification.
456
-
457
- ```puppet
458
- class example (
459
- Boolean $param = false
460
- ) {
461
- ```
462
-
463
- When using Puppet 3, data types can be specified in the manifest documentation
464
- rather than the parameter list, like this:
465
-
466
- ```puppet
467
- # $param:: Some documentation for param
468
- type:Array[String]
469
- ```
470
-
471
- For compatibility with older Kafo releases, additional types are supported:
472
- string, boolean, integer, array, password, hash. These are equivalent to their
473
- Puppet 4 namesakes, plus wrapped in `Optional[..]` to permit `undef`.
474
-
475
- If the data type is given in both the manifest documentation and the parameter
476
- list, then the manifest documentation will be preferred.
477
-
478
- Note that all arguments that are nil (have no value in answers.yaml or you
479
- set them UNDEF (see below)) are translated to ```undef``` in puppet.
480
-
481
- If your module declares its own types, you can add new corresponding subclasses
482
- of DataType which implement validation and typecasting. This can be added to a
483
- `boot` hook by calling:
484
-
485
- Kafo::DataType.register_type('YourType', Kafo::DataType::YourType)
486
-
487
- ## Password arguments
488
-
489
- Kafo supports password arguments. It's adding some level of protection for your
490
- passwords. Usually people generate random strings for passwords. However all
491
- values are stored in config/answers.yaml which may introduce a security risk.
492
-
493
- If this is something to consider for you, you can use the password type (see
494
- Argument types for more info how to define parameter type). It will
495
- generate a secure (random) password with a length of 32 chars and encrypts
496
- it using AES 256 in CBC mode. It uses a passphrase that is stored in
497
- config/kafo.yaml so if anyone gets an access to this file, he can read all
498
- the passwords from the answers.yaml, too. A random password is generated and stored
499
- if there is none in kafo.yaml yet.
500
-
501
- When Kafo runs puppet, puppet will read this password from config/kafo.yaml.
502
- It runs under the same user so it should have read access by default. The Kafo
503
- puppet module also provides a function that you can use to decrypt such
504
- parameters. You can use it like this
505
-
506
- ```erb
507
- password: <%= scope.function_decrypt([scope.lookupvar("::foreman::db_password"))]) -%>
508
- ```
509
-
510
- Also you can take advantage of already encrypted passwords and store since it is
511
- (encrypted). Your application can decrypt it as long as it knows the
512
- passphrase. The passphrase can be obtained from $kafo_configure::password.
513
-
514
- Note that we use a bit extraordinary form of encrypted passwords. All our
515
- encrypted passwords look like "$1$base64encodeddata". As you can see we
516
- use the $1$ as prefix by which we can detect that it is our specially encrypted password.
517
- The form has nothing common with Modular Crypt Format. Also our AES output
518
- is base64 encoded. To get a password from this format you can do something
519
- like this in your application
520
-
521
- ```ruby
522
- require 'base64'
523
- encrypted = "$1$base64encodeddata"
524
- encrypted = encrypted[3..-1] # strip $1$ prefix
525
- encrypted = Base64.decode64(encrypted) # decode base64 string
526
- result = aes_decrypt(encrypted) # for example how to implement aes_decrypt see lib/kafo/password_manager.rb
527
- ```
528
-
529
- ## Array arguments
530
-
531
- Some arguments may be Arrays. If you want to specify array values you can
532
- specify CLI argument multiple times e.g.
533
- ```bash
534
- bin/foreman-installer --puppetmaster-environments=development --puppetmaster-environments=production
535
- ```
536
-
537
- In interactive mode you'll be prompted for another value until you specify
538
- blank line.
539
-
540
- ## Hash arguments
541
-
542
- You can use a Hash value like an Array. It's also a multivalue type but
543
- you have to specify a key:value pair like in the following example.
544
- ```bash
545
- bin/foreman-installer --puppet-server-git-branch-map=master:some --puppet-server-git-branch-map=development:another
546
- ```
547
-
548
- The same applies to the interactive mode, you enter each pair on separate lines
549
- just like with an Array, the only difference is that the line must be formatted
550
- as key:value.
551
-
552
- When parsing the value, the first colon divides key and value. All other
553
- colons are ignored.
554
-
555
- ## Resetting an argument
556
-
557
- Existing stored parameters can be reset back to their default value from the
558
- command line or interactive mode. This deletes the stored value in the answers
559
- file and stores the default from the Puppet manifest in its place.
560
-
561
- The default value is the value set in, or computed by the Puppet params
562
- manifest. This will _not_ reset to any defaults specified in the answers file
563
- before running the Kafo-based installer, they are not kept.
564
-
565
- Using the CLI, a --reset option is available for every parameter, e.g.
566
-
567
- ```bash
568
- bin/foreman-installer --reset-puppet-server-git-branch-map
569
- ```
570
-
571
- The parameter can also be reset to the default in interactive mode, via the
572
- reset parameters sub-menu under each module.
573
-
574
- ## Grouping in interactive mode
575
-
576
- If your module has too many parameters you may find the grouping feature useful.
577
- Every block in your documentation (prefixed by header) forms a group. Unlike for
578
- help, all blocks are used in interactive mode. Suppose you have the following
579
- example:
580
-
581
- ```puppet
582
- # Testing class
583
- #
584
- # == Parameters:
585
- #
586
- # $one:: number one
587
- #
588
- # == Advanced parameters:
589
- #
590
- # $two:: number two
591
- #
592
- # === Advanced A:
593
- #
594
- # $two_a:: 2_a
595
- #
596
- # === Advanced 2_b
597
- #
598
- # $two_b:: 2_b
599
- #
600
- # == Extra parameters:
601
- #
602
- # $three:: number three
603
- ```
604
-
605
- When you enter the Testing class module in interactive mode you can see parameters
606
- from the Basic group and options to configure parameters which belong to the rest
607
- of groups on same level, in this case Advanced and Extra parameters.
608
-
609
- ```
610
- Module foreman configuration
611
- 1. Enable/disable foreman module, current value: true
612
- 2. Set one, current value: '1'
613
- 3. Configure Advanced parameters
614
- 4. Configure Extra parameters
615
- 5. Back to main menu
616
- ```
617
-
618
- When you enter Extra parameters, you see only $three and an option to get back
619
- to the parent. In Advanced you can see $two and two more subgroups - Advanced A and
620
- Advanced B. When you enter these subgroups, you can again see their parameters.
621
- Nesting is unlimited. Also there's no naming rule. Just notice that
622
- the main group must be called `Parameters` and it's parameters are always
623
- displayed on first level of the module configuration.
624
-
625
- ```
626
- Group Extra parameters (of module foreman)
627
- 1. Set two_b, current value: '2b'
628
- 2. Back to parent menu
629
- ```
630
-
631
- If there's no primary group a new one is created for you and it does not have
632
- any parameter. This means when a user enters the module configuration he or she will
633
- see only subgroups in the menu (no parameters until a particular subgroup is entered).
634
- If there is no group in the documentation a new primary group is created and it
635
- holds all module parameters (there are no subgroups in the module configuration).
636
-
637
- ## Conditional parameters in interactive mode
638
-
639
- You can also define conditions to parameters and their groups. These conditions
640
- are evaluated in interactive mode and are based on the results which are then displayed
641
- to the user. You can use this for example to hide mysql_* parameters when
642
- $db_type is not set 'mysql'. Let's look at following example
643
-
644
- ```puppet
645
- # Testing class
646
- #
647
- # == Parameters:
648
- #
649
- # $use_db:: use database?
650
- # type:boolean
651
- #
652
- # == Database parameters: condition: $use_db
653
- #
654
- # $database_type:: mysql/sqlite
655
- #
656
- # === MySQL: condition: $database_type == 'mysql'
657
- #
658
- # $remote:: use remote connection
659
- # type:boolean
660
- # $host server to connect to
661
- # condition: $remote
662
- # $socket server to connect to
663
- # condition: !$remote
664
- ```
665
-
666
- Here you can see we defined several conditions on the group and parameter level.
667
- You can write a condition in ruby. All dollar-prefixed words will be
668
- substituted with the value of the particular puppet parameter.
669
-
670
- Note that conditions are combined using ```&&``` when you nest them. So these
671
- are facts based on example:
672
-
673
- * $database_type, $remote, $host, $socket are displayed only when $use_db is set to true
674
- * $remote, $host, $socket are displayed only when $database_type is set to 'mysql'
675
- * $host is displayed only if $remote is set to true, $socket is displayed otherwise
676
-
677
- Here's explanation how conditions are constructed
678
-
679
- ```
680
- -----------------------------------------------------------------------------
681
- | parameter name | resulting condition |
682
- -----------------------------------------------------------------------------
683
- | $use_db | true |
684
- | $database_type | true && $use_db |
685
- | $remote | true && $use_db && $database_type == 'mysql' |
686
- | $host | true && $use_db && $database_type == 'mysql' && $remote |
687
- | $socket | true && $use_db && $database_type == 'mysql' && !$remote |
688
- -----------------------------------------------------------------------------
689
- ```
690
- As already said you can use whatever ruby code, so you could leverage e.g.
691
- parentheses, &&, ||, !, and, or
692
-
693
- ## Custom modules and manifest names
694
-
695
- By default Kafo expects a common module structure. For example if you add
696
- ```yaml
697
- foreman: true
698
- ```
699
- to you answer file, Kafo expects a ```foreman``` subdirectory in ```modules/```. Also
700
- it expects that there will be init.pp which it will instantiate. If you need
701
- to change this behavior you can via ```mapping``` option in ```config/kafo.yaml```.
702
-
703
- Suppose we have a puppet module and we want to use a puppet/server.pp as our init
704
- file. Also we want to name our module puppetmaster. To do so we add the following mapping
705
- to kafo.yaml
706
-
707
- ```yaml
708
- :mapping:
709
- :puppetmaster: # a module name, so we'll have puppetmaster: true in answer file
710
- :dir_name: 'puppet' # the subdirectory in modules/
711
- :manifest_name: 'server' # manifest filename without .pp extension
712
- :params_path: ... # params manifest full path, overriding params_name, must be with .pp extension
713
- :params_name: 'params' # name of manifest holding the params class without .pp extension
714
- ```
715
-
716
- Note that if you add a mapping you must enter both the dir_name and manifest_name even
717
- if one of them is already the default. The arguments params_path and params_name are optional.
718
- You can use just "params_name" or override not just the file name but also complete paths using "params_path".
719
- If you use "params_path" for this purpose, "params_name" is ignored.
720
-
721
- ## Validations
722
-
723
- If you specify validations of parameters in your init.pp manifest they
724
- will be replaced with your values even before Puppet is run. In order to do this
725
- you must follow a few rules however:
726
-
727
- * you must use standard validation functions (e.g. validate_array, validate_re, ...)
728
-
729
- These functions are re-implemented in Kafo from common stdlib functions, so please
730
- contribute any missing ones.
731
-
732
- If class parameters are declared with Puppet 4 data types then Kafo will
733
- validate user inputs against Puppet's type validation rules, which should
734
- replace the use of separate validation functions.
735
-
736
- ## Enabling or disabling module
737
-
738
- You can enable or disable a module specified in the answers.yaml file. Every module
739
- automatically adds two options to the foreman-installer script. For the module "foreman"
740
- you have two flag options ```--enable-foreman``` and ```--no-enable-foreman```.
741
-
742
- When you disable a module all its answers will be removed and "module" will be
743
- set to false. When you reenable the module you'll end up with the default values.
744
-
745
- ## Special values for arguments
746
-
747
- Sometimes you may want to enforce ```undef``` value for a particular parameter.
748
- You can set this value by specifying an UNDEF string e.g.
749
-
750
- ```bash
751
- bin/foreman-installer --foreman-db-password=UNDEF
752
- ```
753
-
754
- It also works in interactive mode.
755
-
756
- You may also need to override array parameters with empty array values. For this
757
- purpose you can use `EMPTY_ARRAY` string as a value. Similarly you can use
758
- `EMPTY_HASH` for hash parameters.
759
-
760
- ## Hooks
761
-
762
- You may need to add new features to the installer. Kafo provides a simple hook
763
- mechanism that allows you to run custom code at 6 different occasions.
764
- We currently support the following hooks.
765
-
766
- * pre_migrations - just after kafo reads its configuration - useful for config file updates. Only in this stage it is posible to request config reload (`Kafo.request_config_reload`) to get in our changes
767
- * boot - before kafo is ready to work, useful for adding new installer arguments, but logger won't work yet
768
- * init - just after hooking is initialized and kafo is configured, parameters have no values yet
769
- * pre_values - just before value from CLI is set to parameters (they already have default values)
770
- * pre_validations - just after system checks and before validations are executed (and before interactive wizard is started), at this point all parameter values are already set but not yet stored in answer file
771
- * pre_commit - after validations or interactive wizard have completed, all parameter values are set but not yet stored in the answer file
772
- * pre - just before puppet is executed to converge system, after parameter values are stored in the answer file
773
- * post - just after puppet is executed to converge system
774
-
775
- Let's assume we want to add the ```--reset-foreman-db``` option to our
776
- foreman-installer. We could add the following lines to the generated
777
- installer script.
778
-
779
- ```ruby
780
- require 'kafo/hooking'
781
-
782
- # first hook that creates new app option --reset-foreman-db
783
- KafoConfigure.hooking.register_boot(:add_reset_option) do
784
- app_option '--reset-foreman-db',
785
- :flag, 'Drop foreman database first? You will lose all data!', :default => false
786
- end
787
-
788
- # second hook which resets the db if value was set to true
789
- KafoConfigure.hooking.register_pre(:reset_db) do
790
- if app_value(:reset_foreman_db) && !app_value(:noop)
791
- `which foreman-rake > /dev/null 2>&1`
792
- if $?.success?
793
- logger.info 'Dropping database!'
794
- output = `foreman-rake db:drop 2>&1`
795
- logger.debug output.to_s
796
- unless $?.success?
797
- logger.warn "Unable to drop DB, ignoring since it's not fatal, output was: '#{output}''"
798
- end
799
- else
800
- logger.warn 'Foreman not installed yet, can not drop database!'
801
- end
802
- end
803
- end
804
- ```
805
-
806
- Note that the hook is evaluated in HookContext object which provides a DSL:
807
-
808
- * ```app_option``` creates a new installer option
809
- * ```app_value(:reset_foreman_db)``` accesses values of installer options
810
- * ```param('module name', 'parameter name')``` accessor allows parameters to be modified if already
811
- defined
812
- * ```add_module``` registers your own module not specified in the answer file (custom mapping is also
813
- supported), useful if you need to add some module to the existing installer based on kafo but you
814
- don't have control over its source code
815
- * ```module_enabled?('module_name')``` indicates whether a module is currently enabled
816
- * ```get_custom_config``` and ```store_custom_config``` access custom config storage which persists
817
- among kafo runs
818
- * ```logger``` is also available for writing log messages
819
-
820
- For more details, see
821
- [hook_context.rb](https://github.com/theforeman/kafo/blob/master/lib/kafo/hook_context.rb).
822
-
823
- If you don't want to modify your installer script you can place your hooks into the
824
- hooks directory. By default the hooks dir is searched for ruby files in subdirectories
825
- based on hook type. For example pre hooks are searched for in ```$installer_dir/hooks/pre/*.rb```
826
- The hooks from the previous example would look like this. The only change to the code is
827
- that you don't explicitely register hooks, it's done automatically for you.
828
-
829
- ```ruby
830
- # hooks/boot/10-add_reset_option.rb
831
- app_option '--reset-foreman-db', :flag, 'Drop foreman database first? You will lose all data!', :default => false
832
- ```
833
-
834
- ```ruby
835
- # hooks/pre/10-reset_option_feature.rb
836
- if app_value(:reset_foreman_db) && !app_value(:noop)
837
- `which foreman-rake > /dev/null 2>&1`
838
- if $?.success?
839
- logger.info 'Dropping database!'
840
- output = `foreman-rake db:drop 2>&1`
841
- logger.debug output.to_s
842
- unless $?.success?
843
- logger.warn "Unable to drop DB, ignoring since it's not fatal, output was: '#{output}''"
844
- end
845
- else
846
- logger.warn 'Foreman not installed yet, can not drop database!'
847
- end
848
- end
849
- ```
850
-
851
-
852
- If you want to add more directories to be search you can use the "hook_dirs" option
853
- in the installer configuration file.
854
-
855
- ```yaml
856
- :hook_dirs:
857
- - /opt/hooks
858
- - /my/plugin/hooks
859
- ```
860
-
861
- You can register as many hooks as you need. The order of execution for a particular hook type
862
- is based on hook file name.
863
-
864
- If you want to cancel the installation you can use the ```exit``` method and specify an exit code.
865
-
866
- ## Colors
867
-
868
- Everybody loves colors right? In case you don't you can disable them using the ```--no-colors```
869
- argument or disallow them in the installer config file (search for ```colors:``` key and set
870
- it to false). If you don't touch this setting, kafo will try to detect whether colors
871
- are supported and will enable/disable it accordingly.
872
-
873
- Kafo supports two sets of colors, one for terminals with bright and one for dark backround.
874
- You can specify your installer default scheme in installer config file (```color_of_background```
875
- key). Alternatively the user can override this default setting with the ```--color-of-background``` argument.
876
- Possible values are ```dark``` and ```bright```.
877
-
878
- You can reuse the kafo color schema in your custom hooks (so you can reuse dark/bright logic).
879
- Look at this example in bin/foreman-installer
880
- ```ruby
881
- #!/usr/bin/env ruby
882
-
883
- # Run the install
884
- @result = Kafo::KafoConfigure.run
885
- exit 0 if @result.nil? # --help invocation
886
-
887
- # Puppet status codes say 0 for unchanged, 2 for changed succesfully
888
- if [0,2].include?(@result.exit_code)
889
- say " <%= color('Success!', :good) %>"
890
-
891
- if module_enabled? 'foreman'
892
- say " * <%= color('Foreman', :info) %> is running at <%= color('#{get_param('foreman','foreman_url')}', :info) %>"
893
- say " Default credentials are '<%= color('admin:changeme', :info) %>'"e
894
- end
895
- end
896
- ```
897
-
898
- As you can see you can use HighLine helpers (e.g. say) with colors. Look at kafo/color_schema.rb for
899
- supported color identifiers. We can guarantee that there will always be at least :good, :bad, :info.
900
-
901
- Methods like module_enabled? and get_param are just helpers defined in the same file. If you find
902
- them useful, here's the definition
903
-
904
- ```ruby
905
- def module_enabled?(name)
906
- mod = @result.module(name)
907
- return false if mod.nil?
908
- mod.enabled?
909
- end
910
-
911
- def get_param(mod, name)
912
- @result.param(mod, name).value
913
- end
914
- ```
915
-
916
- ## Custom paths
917
-
918
- Usually when you package your installer you want to load files from specific
919
- paths. In order to do that you can use following configuration options:
920
-
921
- * :answer_file: /etc/kafo/kafo.yaml
922
- * :installer_dir: /usr/share/kafo/
923
- * :module_dirs: /usr/share/foreman-installer/modules
924
- * :hook_dirs: /user/share/foreman-installer/hooks
925
- * :check_dirs: /user/share/foreman-installer/checks
926
- * :kafo_modules_dir: /usr/share/kafo/modules
927
- * :store_dir: /etc/foreman-installer/store.d
928
-
929
- Answer file is obvious. The "installer_dir" is the place where your installer is
930
- located. E.g. system checks will be loaded from here (under checks
931
- subdirectory) if not set elsewhere by `check_dirs`. You can optionally change foreman-installer modules dir
932
- using `module_dirs` option and hooks dir using `hook_dirs` option. `module_dirs`, `hook_dirs` and `check_dirs`
933
- can hold multiple directories where to look for the resources.
934
-
935
- On debian systems you may want to specify kafo modules dir
936
- independent on your installer location. If you specify this option kafo's
937
- internal-installer puppet-modules will be loaded from here.
938
-
939
- ## Order of puppet modules execution
940
-
941
- When you have more than one module you may end up in the situation where you need a
942
- specific order of execution. It seems as a puppet antipattern to me however
943
- there may be cases where it's needed. You can set order in config/kafo.yaml
944
- like this
945
-
946
- ```yaml
947
- order:
948
- - foreman
949
- - foreman_proxy
950
- ```
951
-
952
- If you have other modules in your answer file they will be executed after
953
- those that have explicit order. Their order is not be specified.
954
-
955
- ## Changing the order of module appearance in interactive mode
956
-
957
- We sort our modules alphabetically. Sometimes you may want to reorder
958
- modules, e.g. a display plugin modules as last module.
959
- For this you can use the ```low_priority_modules```
960
- configuration option. It accepts an array of patterns considering the
961
- first to have the lowest priority. So in follwing example
962
-
963
- ```yaml
964
- low_priority_modules:
965
- - compute
966
- - plugin
967
- ```
968
-
969
- all modules containing a word compute in their name would be listed
970
- at the end. If there are two modules containing compute, their order
971
- is alphabetical on suffix after compute word. If there are some modules
972
- containing word plugin, they will be above compute modules as they
973
- were mentioned later.
974
-
975
- ## Changing of log directory and user/group
976
-
977
- By default kafo logs every run to a separate file in /var/log/kafo.
978
- You probably want to put your installation logs alongside with other logs of
979
- your application. That's why kafo has its own configuration file in which you
980
- can tune details like these.
981
-
982
- In order to do that, create a configuration file under config/kafo.yaml. You can
983
- use config/kafo.yaml.example as a template. If config/kafo.yaml does not exist
984
- default values will be used.
985
-
986
- As a developer you can appreciate more verbose log. You can set a debug level
987
- in config/kafo.yml. Also you can change a user or group that will own the
988
- log file. This is usefull if your installer requires to be run as root
989
- but you want the logs to be readable by specific users.
990
-
991
- ## System checks
992
-
993
- When you want to make sure that a user has a certain software installed or has the
994
- right version you can write a simple script and put it into the checks directory.
995
- All files found there will be executed and if any of these exits with an non-zero
996
- exit code, kafo won't execute puppet but only print an error message
997
- `Your system does not meet configuration criteria.`
998
-
999
- Everything on STDOUT and STDERR is logged in error level.
1000
-
1001
- Example shell script which checks java version
1002
-
1003
- ```bash
1004
- #!/bin/sh
1005
- java -version 2>&1 | grep OpenJDK
1006
- exit $?
1007
- ```
1008
-
1009
- If you want to ignore results of the check scripts, you can use the builtin
1010
- parameter `--skip-checks-i-know-better` (or `-s`). This will completely
1011
- disable running all system check scripts. Note that this option is
1012
- not persisted between runs.
1013
-
1014
- ## Parser cache
1015
-
1016
- One or more caches of parsed Puppet modules and manifests can be created to skip the use
1017
- of kafo_parsers at runtime. This is useful when kafo_parsers doesn't support the
1018
- version of Puppet in use, and may also provide a small performance benefit. When multiple
1019
- cache files are used, they are being loaded in order they are specified in the config
1020
- file. If their files overlap, the later cache fully replaces the previous cache for each
1021
- file/manifest.
1022
-
1023
- Create the cache with `kafo-export-params -f parsercache --no-parser-cache` and
1024
- configure it in config/kafo.yaml with:
1025
-
1026
- ```yaml
1027
- # single cache
1028
- :parser_cache_path: ./parser_cache.yaml
1029
-
1030
- # multiple caches
1031
- :parser_cache_path:
1032
- - ./parser_cache.yaml
1033
- - ./another_parser_cache.yaml
1034
- ```
1035
-
1036
- The cache will be skipped if the file modification time of the manifest is
1037
- greater than the mtime recorded in the cache. Using `--parser-cache` will force
1038
- the use of an outdated cache, but this should be used with caution.
1039
-
1040
- ## Configuring Hiera
1041
-
1042
- Kafo uses Hiera to include classes and pass parameters to classes using data
1043
- binding, but this can be extended so parameters can be set for classes not
1044
- being managed by Kafo. Set a custom Hiera config file in Kafo's config with:
1045
-
1046
- ```yaml
1047
- :hiera_config: /usr/share/kafo/hiera.yaml
1048
- ```
1049
-
1050
- The contents of this file are as per the [hiera.yaml docs](https://docs.puppet.com/hiera/latest/configuring.html),
1051
- but hierarchy should contain the item `kafo_answers` and the `yaml` backend
1052
- should be enabled. Kafo will add these if they're missing.
1053
-
1054
- When running Puppet, Kafo will copy the Hiera config and YAML data directory to
1055
- a temporary location to include its data. The file `kafo_answers.yaml` will be
1056
- generated containing _all_ default and overriden values for parameters managed
1057
- by Kafo. This may change in the future to allow a more complex hierarchy. As an
1058
- example, a hierarchy could be set up with:
1059
-
1060
- ```yaml
1061
- :hierarchy:
1062
- - kafo_answers
1063
- - "%{::osfamily}"
1064
- - common
1065
- ```
1066
-
1067
- This would give precedence to all Kafo-managed parameter values, but for any
1068
- others, would check for values per OS family, followed by a `common.yaml` file.
1069
-
1070
- ## Exit code
1071
-
1072
- Kafo can terminate either before or after puppet is run. If it is run with
1073
- ```--detailed-exitcodes``` Kafo returns the same exit code as puppet does. If
1074
- kafo terminates after puppet run exit codes are like the following:
1075
- * '1' means there were parser/validation errors
1076
- * '2' means there were changes,
1077
- * '4' means there were failures during the transaction,
1078
- * '6' means there were both changes and failures.
1079
-
1080
- Other exit codes that can be returned:
1081
- * '0' means everything went fine no changes were made
1082
- * '20' means your system does not meet configuration criteria (system checks failed)
1083
- * '21' means your answer file contains invalid values
1084
- * '22' means that puppet modules contains some error (e.g. missing documentation)
1085
- * '23' means that you have no answer file
1086
- * '24' means that your answer file asks for puppet module that you did not provide
1087
- * '25' means that kafo could not get default values from puppet
1088
- * '26' means that kafo could not find the specified scenario
1089
- * '27' means that kafo found found scenario configuration error that prevents installation from continuing
1090
- * '28' means that a value is missing for a parameter given on the command line
1091
- * '130' user interrupt (^C)
1092
-
1093
- ## Running Puppet Profiling
1094
-
1095
- As of Puppet 3.2, performance data can be gathered during a puppet run by adding the `--profile` option. See [Tune Puppet for Performance with Profiler](https://puppetlabs.com/blog/tune-puppet-performance-profiler) for more information from the Puppet team. Users who wish to perform a Kafo run and gather this type of profiling data to analyze can pass the same option to their installer. The profiling data will then be present in the normal Kafo logs.
1096
-
1097
- ## Issue tracker
1098
-
1099
- Issues are tracked in Redmine, see:
1100
-
1101
- * [Open Kafo issues](http://projects.theforeman.org/projects/kafo/issues/)
1102
- * [File new issue](http://projects.theforeman.org/projects/kafo/issues/new)
1103
-
1104
- ## Related projects
1105
-
1106
- * [kafo_module_lint](https://github.com/domcleal/kafo_module_lint) will lint Puppet modules to ensure data types are specified correctly etc.
1107
- * [kafo_parsers](https://github.com/theforeman/kafo_parsers) parses Puppet manifests for class documentation and parameter data
1108
- * [puppet-lint-param-docs](https://github.com/voxpupuli/puppet-lint-param-docs) will lint Puppet modules to ensure all parameters are documented
1109
-
1110
- # License
1111
-
1112
- This project is licensed under the GPLv3+.