@@ -36,6 +36,8 @@ You can now open `overview.html` in your browser to view the results.
36
36
-q, --quiet Don't report warnings
37
37
-c COLUMNS, --columns=COLUMNS
38
38
Show only given columns
39
+ -C CUST_COLS, --cust-cols=CUST_COLS
40
+ Path to a custom columns definition file
39
41
-l LIMIT, --limit=LIMIT
40
42
Limit hosts to pattern
41
43
--exclude-cols=EXCLUDE_COLUMNS
@@ -92,7 +94,7 @@ For example, let's say we have the following `hosts` file:
92
94
[cust.megacorp]
93
95
db1.dev.megacorp.com dtap=dev comment="Old database server"
94
96
db2.dev.megacorp.com dtap=dev comment="New database server"
95
- test.megacorp.com dtap=test
97
+ test.megacorp.com dtap=test
96
98
acc.megacorp.com dtap=acc comment="24/7 support"
97
99
megacorp.com dtap=prod comment="Hosting by Foo" ext_id="SRV_10029"
98
100
@@ -273,7 +275,8 @@ same as `--columns`. For example:
273
275
-i hosts \
274
276
facts/
275
277
276
- If you want to add custom columns, please refer to 'Custom templates' section.
278
+ If you want to add custom columns, please refer to [ Custom
279
+ columns] ( #custom-columns ) section.
277
280
278
281
279
282
## Extending facts
@@ -285,7 +288,7 @@ hosts.
285
288
286
289
Extended facts are basically the same as normal Ansible fact files. When you
287
290
specify multiple fact directories, Ansible-cmdb scans all of the in order and
288
- overlays the facts.
291
+ overlays the facts.
289
292
290
293
Note that the host * must still* be present in your hosts file, or it will not
291
294
generate anything.
@@ -424,11 +427,73 @@ Generate the overview:
424
427
425
428
The software items will be listed under the "* Custom facts* " heading.
426
429
430
+
431
+ ## Custom columns
432
+
433
+ You can add custom columns to the host overview with the ` -C ` (` --cust-cols ` )
434
+ option. This allows you to specify
435
+ [ jsonxs] ( https://github.com/fboender/jsonxs ) expressions to extract and
436
+ display custom host facts. Such columns are fairly limited in what they can
437
+ display. If you need a more powerful method of adding custom data to your
438
+ CMDB, please refer to the [ Custom templates] ( #custom-templates ) section.
439
+
440
+ Custom columns are currently only supported by the ` html_fancy ` and
441
+ ` html_fancy_split ` templates!
442
+
443
+ The ` -C ` option takes a parameter which is the path to a JSON file containing
444
+ your custom column definitions. An example can be found in the
445
+ ` examples/cust_cols.json ` file in the repo:
446
+
447
+ [
448
+ {
449
+ "title": "AppArmor",
450
+ "id": "apparmor",
451
+ "sType": "string",
452
+ "visible": true,
453
+ "jsonxs": "ansible_facts.ansible_apparmor.status"
454
+ },
455
+ {
456
+ "title": "Proc type",
457
+ "id": "proctype",
458
+ "sType": "string",
459
+ "visible": true,
460
+ "jsonxs": "ansible_facts.ansible_processor[2]"
461
+ }
462
+ ]
463
+
464
+ This defines two new columns: 'AppArmor' and 'Proc type'. All keys are
465
+ required.
466
+
467
+ * ` title ` is what is displayed as the columns user-friendly title.
468
+ * The ` id ` key must have a unique value, to differentiate between
469
+ columns.
470
+ * The ` sType ` value determines how the values will be sorted in the host
471
+ overview. Possible values include ` string ` and ` num ` . ` visible ` determines
472
+ whether the column will be active (shown) by default.
473
+ * The ` jsonxs ` expression points to an entry in the facts files for each host,
474
+ and determines what will be shown for the column's value for each host.
475
+ The easiest way to figure out a jsonxs expression is by opening one of the
476
+ gathered facts files in a json editor. Please see
477
+ [ jsonxs] ( https://github.com/fboender/jsonxs ) for info on how to write jsonxs
478
+ expressions.
479
+
480
+ To use it:
481
+
482
+ ../ansible-cmdb/src/ansible-cmdb -C example/cust_cols.json -i example/hosts example/out/ > cmdb.html
483
+
484
+ When opening the ` cmdb.html ` file in your browser, you may have to hit the
485
+ 'Clear settings' button in the top-right before the new columns show up or
486
+ when you get strange behaviour.
487
+
488
+
427
489
## Custom templates
428
490
429
- If you want to add custom columns or other data to the output, you can create
430
- a custom template. Ansible-cmdb uses the [ Mako templating
431
- engine] ( http://www.makotemplates.org/ ) to render output.
491
+ Custom columns can be added with the ` -C ` param. See the [ Custom
492
+ columns] ( #custom-columns ) section for more info. Custom columns are somewhat
493
+ limited in the type of information they can display (basically only strings
494
+ and numbers). If you want to add more elaborate custom columns or other data
495
+ to the output, you can create a custom template. Ansible-cmdb uses the [ Mako
496
+ templating engine] ( http://www.makotemplates.org/ ) to render output.
432
497
433
498
For example, if you want to add a custom column to the ` html_fancy ` template:
434
499
0 commit comments