1
1
# ansible-autodoc
2
- Generate documentation from annotated playbooks and roles using templates
2
+ Generate documentation from annotated playbooks and roles using templates.
3
3
4
- Please note this is still a work in progress, while the code might work in it's current state
5
- I don't recommend yet to use it, as I will probably change things.
4
+ Note: this project is currently in Beta, issues, ideas and pull requests are welcome.
6
5
7
6
# Features
8
7
* allow to document playbook projects and roles
@@ -13,25 +12,49 @@ I don't recommend yet to use it, as I will probably change things.
13
12
# Installation
14
13
## Manual
15
14
1 . download / git clone this project
16
- 2 . run ` install.py ` Note sudo is required
15
+ 2 . run ` install.py ` Note sudo is required ( I use this locally while developing)
17
16
18
17
## Pip
19
- using pip (not yet)
18
+ using pip
20
19
```
21
20
pip install ansible-autodoc
22
21
```
23
22
24
- # Use
23
+ ## Use
24
+ ``` $xslt
25
+ ansible-autodoc -h # print help
26
+ ansible-autodoc -p all path/to/role # print in cli all the recolected data
27
+ ansible-autodoc [path/to/project] # will generate README file based on annotations
28
+ ```
29
+ ### more flexibility
30
+ you can create a configuration file "autodoc.config.yaml" in the root of your project in order to modify
31
+ several behaviours, see the sample config file for more details:
32
+
33
+ ``` $xslt
34
+ # role or project with playbooks
35
+ $ cd <project>
36
+
37
+ # create sample configuration (optional)
38
+ # you can pass the options as parameters too
39
+ $ ansible-autodoc --sample-doc > autodoc.config.yaml
40
+ ```
25
41
26
- ## Annotations
42
+ # Annotations
27
43
28
44
Use the following annotations in your playbooks and roles
29
45
30
- * author: ` # @author: Author Name ` to annotate the author of playbook or role
31
- * description: ` # @description: Project description goes here ` to annotate the project description
46
+ * meta: ` # @meta author: Author Name ` to annotate the metadata of playbook or role, like author,
47
+ check below list of useful metadata
48
+ * author: (self explanatory)
49
+ * description: playbook / role description
50
+ * name: to define a different role/project name instead of the folder name
51
+ * license: (self explanatory)
52
+ * email: (self explanatory)
32
53
* todo: ` # @todo: section #Taskt that need to be done ` to annotate a todo
33
- * tags: ` # @tag: tagname # description ` to annotate tags
34
- * variables: ` # @var: varname: ["some_defaut","other"] # Description of the variables ` to annotate a variables
54
+ * action: ` # @action section # description of the action ` to annotate a actions performed by the playbook/role
55
+ * tag: ` # @tag tagname # description ` to annotate tags, this is a special annotation as this will not only search
56
+ for annotations, but also for used tags in the project and add that to the generated output.
57
+ * variables: ` # @var varname: ["some_defaut","other"] # Description of the variables ` to annotate a variables
35
58
* example: the idea is that after every annotation, we can define an example block, linked to the annotation.
36
59
``` $xslt
37
60
# @example: title # Some description
@@ -40,37 +63,87 @@ Use the following annotations in your playbooks and roles
40
63
# @end
41
64
```
42
65
43
- ### Not implemented:
66
+ ## Not implemented:
44
67
this is still not implemented, just ideas
45
68
46
69
` Nothing here `
47
70
48
- ## Generate Documentation
49
-
50
- ``` $xslt
51
- # role or project with playbooks
52
- $ cd <project>
53
-
54
- # create sample configuration (optional)
55
- # you can pass the options as parameters too
56
- $ ansible-autodoc --sample-doc > autodoc.config.yaml
57
-
58
- # crate documentation
59
- $ ansible-autodoc
60
-
61
- # more options
62
- $ ansible-autodoc -h
63
- ```
64
-
65
71
# Templates
66
72
the template engine uses jinja2 for document parsing, the directory structure of the template
67
73
will be recreated on the output, already existent files will be overwritten.
68
74
69
75
you can specify your own template, for extending templates create a new template directory and
70
76
specify the location of the same in the configuration file.
71
77
78
+ annotations are parsed as follows: "@annotation key: value # description"
79
+ your annotation item would then contain these values and some automatically filled if available:
80
+ ```
81
+ {
82
+ "key": "key section",
83
+ "value": "value section",
84
+ "desc": "description",
85
+ "file": "absolute path where the annotation was found",
86
+ "line": "line number of the annotation",
87
+ "role": "name of the role the annotation was found"
88
+ }
89
+ ```
90
+
91
+
92
+ ## template API
93
+ when templating autodoc projects you will have the methods from DocumentParser exposed in the templates:
94
+ 'r' is a reference to the parser in order to do things like:
95
+ ```
96
+ {{ r.get_roles() | pprint }}
97
+ ```
98
+
99
+ * r.get_gata() : get the full data of autodoc in jason structure, this can be quite overwhelming when templating
100
+ * r.get_annotations() : get a list of the scanned annotations as per configuration
101
+ * r.get_roles(exclude_playbook) : return a list of scanned roles, if exclude_playbook is True the palybook
102
+ role '_ ansible_playbook_ ' is removed
103
+ * r.is_role() : return True if the scanned project directory is identified as role, false if scanned as playbook
104
+ * r.get_role_name() : If scanned project is a role, return role name (project folder name)
105
+ * r.get_type(name,role="all"): return an array with the corresponding annotation "name", role is optional
106
+ * if "all" or not specified, the mixed result for all roles will be returned
107
+ * if "play" specified, the playbook results will be returned
108
+ * r.get_multi_type(name,role="all"): return a dict of all the annotations with structure ` section:[item1,item2] `
109
+ you can use it like:
110
+ ```
111
+ {% for key , values in r.get_multi_type("action","role_name") %}
112
+ {{ key }}
113
+ {% for item in values %}
114
+ {{ item.desc }}
115
+ {% endfor %}
116
+ {% endfor %}
117
+ ```
118
+ * r.get_keys(name,role="all"): return a list of annotation keys, same parameters as get_type.
119
+ * r.get_item(name,key,role="all"): return a single annotation item, same parameters as get_type plus "key"
120
+ * r.get_duplicates(name): return a dict of annotations that are duplicated, i.e useful for tags to identify
121
+ if they have been annotated more than once or if there are tags used in more than one role.
122
+ * r.allow_multiple(name): check if a annotation allows multiple values, like @todo or @action .
123
+ * r.include(filename): include a tex file, path relative to the project root
124
+
125
+ * r.cli_left_space("string",spaces) : left justify with spaces a string, spaces is optional, see python ljust()
126
+ * r.cli_print_section() : return the passed parameter when using cli print "-p", default is "all"
127
+
128
+ * r.capitalize(string) : wrapper for python capitalize
129
+ * r.fprn(role_name,replace_value="Playbook"): "filter playbook role name" replace the internal playbook role name
130
+ "_ ansible_playbook_ " with a different value.
72
131
73
132
# changelog
133
+
134
+ 2019/02/17 - Version 0.5.1
135
+ * add missing feature @example
136
+ * improve default template "readme"
137
+
138
+ 2019/02/17 - Version 0.5.0
139
+ * added uint tests
140
+ * refactored annotation discovery into Annotation object
141
+ * changed annotation to allow multi line description
142
+ * made annotation syntax more uniform
143
+ * moved some essential logic from AutodocCli to Config
144
+ * IMPROVEMENT: got rid of annotations author and description and use meta: author | description instead
145
+ * Missing feature from 0.4: @example
146
+
74
147
2019/01/22 - Version 0.4.2
75
148
* FIX: yaml load unicode files
76
149
* FIX: document parsing when some annotations are not present
@@ -79,26 +152,24 @@ specify the location of the same in the configuration file.
79
152
2019/01/21 - Version 0.4.2
80
153
* Added example block annotation
81
154
82
-
83
155
2019/01/21 - Version 0.4.1
84
156
* Added print template to stdout, useful for project review and development
85
157
* Added @var annotation
86
158
87
-
88
159
2019/01/20 - Version 0.4.0
89
160
* Basic functionality with tag annotations working
90
161
* simple annotations: "author", "description" and "todo2 also working
91
162
92
163
# Todo
93
164
* when a yaml file with a special char is templated, an UnicodeEncodeError will be thrown
94
- * add testing, coverage, travis
165
+ * Improve test coverage
95
166
* add template cli parameter
96
167
97
168
### improvements
98
- * instead of using different annotation for author, description etc, use one annotation @info : <section > # value
99
169
* improve the default templates : ongoing task
100
170
* improve the documentation : ongoing task
101
- * add @meta tag, for enabling and disabling parts of the template & document
171
+ * add @autodoc tag, to use as flags for specific templates, i.e # @autodoc tags: hidden #
172
+ to hide the render of tags section
102
173
* add annotation personalization by extending annotation definition in configuration file
103
174
* document annotation personalization
104
175
0 commit comments