Browse code

now generate list of playbook ojbect directives

TODO: needs links/info and conditionals added

Brian Coca authored on 2016/02/26 06:41:50
Showing 5 changed files
... ...
@@ -31,6 +31,7 @@ docs/man/man3/*
31 31
 *.sublime-workspace
32 32
 # docsite stuff...
33 33
 docsite/rst/modules_by_category.rst
34
+docsite/rst/playbooks_directives.rst
34 35
 docsite/rst/list_of_*.rst
35 36
 docsite/rst/*_module.rst
36 37
 docsite/*.html
... ...
@@ -1,10 +1,11 @@
1 1
 #!/usr/bin/make
2 2
 SITELIB = $(shell python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
3 3
 FORMATTER=../hacking/module_formatter.py
4
+DUMPER=../hacking/dump_playbook_attributes.py
4 5
 
5 6
 all: clean docs
6 7
 
7
-docs: clean modules staticmin
8
+docs: clean directives modules staticmin
8 9
 	./build-site.py
9 10
 	-(cp *.ico htmlout/)
10 11
 	-(cp *.jpg htmlout/)
... ...
@@ -41,6 +42,9 @@ clean:
41 41
 
42 42
 .PHONEY: docs clean
43 43
 
44
+directives: $(FORMATTER) ../hacking/templates/rst.j2
45
+	PYTHONPATH=../lib $(DUMPER) --template-dir=../hacking/templates --output-dir=rst/
46
+
44 47
 modules: $(FORMATTER) ../hacking/templates/rst.j2
45 48
 	PYTHONPATH=../lib $(FORMATTER) -t rst --template-dir=../hacking/templates --module-dir=../lib/ansible/modules -o rst/
46 49
 
... ...
@@ -20,3 +20,4 @@ and adopt these only if they seem relevant or useful to your environment.
20 20
    playbooks_tags
21 21
    playbooks_vault
22 22
    playbooks_startnstep
23
+   playbooks_directives
23 24
new file mode 100755
... ...
@@ -0,0 +1,33 @@
0
+#!/usr/bin/env python2
1
+
2
+import optparse
3
+from jinja2 import Environment, FileSystemLoader
4
+
5
+from ansible.playbook import  Play
6
+from ansible.playbook.block import  Block
7
+from ansible.playbook.role import  Role
8
+from ansible.playbook.task import  Task
9
+
10
+template_file = 'playbooks_directives.rst.j2'
11
+oblist = {}
12
+for aclass in Play, Block, Role, Task:
13
+    aobj = aclass()
14
+    oblist[type(aobj).__name__] = aobj
15
+
16
+p = optparse.OptionParser(
17
+    version='%prog 1.0',
18
+    usage='usage: %prog [options]',
19
+    description='Generate module documentation from metadata',
20
+)
21
+p.add_option("-T", "--template-dir", action="store", dest="template_dir", default="hacking/templates", help="directory containing Jinja2 templates")
22
+p.add_option("-o", "--output-dir", action="store", dest="output_dir", default='/tmp/', help="Output directory for rst files")
23
+
24
+(options, args) = p.parse_args()
25
+
26
+env = Environment(loader=FileSystemLoader(options.template_dir), trim_blocks=True,)
27
+template = env.get_template(template_file)
28
+outputname = options.output_dir + template_file.replace('.j2','')
29
+tempvars = { 'oblist': oblist }
30
+
31
+with open( outputname, 'w') as f:
32
+    f.write(template.render(tempvars))
0 33
new file mode 100644
... ...
@@ -0,0 +1,19 @@
0
+Directives Glossary
1
+===================
2
+
3
+Here we list the common playbook objects and the possible directives that can be used with them.
4
+Note that not all directives affect the object itself and might just be there to be inherited by other contained objects.
5
+
6
+.. contents::
7
+   :local:
8
+   :depth: 1
9
+
10
+{% for name in oblist %}
11
+
12
+{{ name }}
13
+{{ '-' * name|length }}
14
+{% for attribute in oblist[name].__dict__['_attributes']|sort %}
15
+  * {{ attribute }}
16
+{% endfor %}
17
+
18
+{% endfor %}