# Documentation strings in modules

**URL:** <https://forum.ansible.com/t/documentation-strings-in-modules/11913>\
**Category:** Ansible Project\
**Created:** [September 20, 2012, 11:28am UTC](https://forum.ansible.com/t/documentation-strings-in-modules/11913 "2012-09-20T11:28:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [September 20, 2012, 11:28am UTC](https://forum.ansible.com/t/documentation-strings-in-modules/11913/1 "2012-09-20T11:28:53Z")

</div>

Hello,

as you may have gathered (particularly if you've been following issue  
#991 on Github 🙂 we're settling on DOCUMENTATION strings for modules.  
I believe I'm the one who started all this, so I'd like to update you  
with what's been done so far, if I may, hoping we can surprise Michael  
(who's currently AWOL I believe) with completed module documentation  
when he returns. #wishfulthinkingmaybe #crossesfingers

We've agreed to add a DOCUMENTATION string to modules from which we can  
generate a module's, documentation. I think Michael wants this for the  
ansible-commander UI, and I want this for the booklet (a.k.a. reference  
card) I'm wanting to create for Ansible. Other uses could be generation  
of static documentation pages (and maybe even Ansible documentation as  
an .epub or .mobi?)

An example taken from the `lineinfile' module I documented yesterday  
(pull-request already submitted):

&nbsp;&nbsp;\> DOCUMENTATION = '''  
&nbsp;&nbsp;\> ---  
&nbsp;&nbsp;\> module: lineinfile  
&nbsp;&nbsp;\> author: Daniel Hokka Zakrisson  
&nbsp;&nbsp;\> short\_description: Ensure a particular line is in a file  
&nbsp;&nbsp;\> description:  
&nbsp;&nbsp;\> - This module will search a file for a line, and ensure that it is present or absent.  
&nbsp;&nbsp;\> - This is primarily useful when you want to change a single line in a  
&nbsp;&nbsp;\> file only. For other cases, see the M(copy) or M(template) modules.  
&nbsp;&nbsp;\> version\_added: "0.7"  
&nbsp;&nbsp;\> options:  
&nbsp;&nbsp;\> - regexp:  
&nbsp;&nbsp;\> required: true  
&nbsp;&nbsp;\> description:  
&nbsp;&nbsp;\> - The regular expression to look for in the file. For I(state=present),  
&nbsp;&nbsp;\> the pattern to replace. For I(state=absent), the pattern of the line  
&nbsp;&nbsp;\> to remove.  
&nbsp;&nbsp;\> examples:  
&nbsp;&nbsp;\> - code: lineinfile name=/etc/selinux/config regexp=^SELINUX= line=SELINUX=disabled  
&nbsp;&nbsp;\> - code: lineinfile name=/etc/sudoers state=absent regexp="^%wheel"  
&nbsp;&nbsp;\> '''

This YAML format allows us to produce reasonably good looking output for  
several different formats, using a small program and a bunch of Jinja2  
templates. (My intention was to use stuff required for Ansible anyway.)

(The get\_url, raw, setup, and a bit of the file modules are documented,  
with `get\_url' currently containing most of the tags we've settled on;  
these are in PR #1063 [3].)

The reference card (which started this whole thing rolling), a.k.a. the  
"booklet" is making progres, if slowly. Aside from $DAYJOB, the delay  
has been due to the fact that we've spent some time on settling on the  
DOCUMENTATION format.

A utility called `mofo' (MOdule FOrmatter; hmm: maybe I should change the  
name...) currently parses DOCUMENTATION from Ansible's modules in `library/',  
extracts the YAML, and uses Jinja2 templates to generate:

\* LaTeX source (which I include in main .tex)  
\* man page source (nroff/troff)  
\* HTML (barely started)

A few notes on the above YAML and the `mofo' utility:

\* I've added an optional `author' which currently finds its way into the  
&nbsp;&nbsp;man pages if it's defined.  
\* Supports generation of man pages; example in man(1) format with  
&nbsp;&nbsp;corresponding PDF output is included.  
\* Creates boilerplate DOCUMENTATION string on demand (-G)

The whole lot can currently be found at [1]. Please do glance at a  
man-page and an early preview PDF of the booklet [2], if you can spare  
some time.

I'd appreciate your comments and lots of pull requests (both for booklet  
content as well as for module DOCUMENTATION).

Best regards,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

[1]: [https://github.com/jpmens/ansible-booklet](https://github.com/jpmens/ansible-booklet)  
[2]: [https://github.com/downloads/jpmens/ansible-booklet/ansible-booklet.pdf](https://github.com/downloads/jpmens/ansible-booklet/ansible-booklet.pdf)  
[3]: [https://github.com/ansible/ansible/pull/1063](https://github.com/ansible/ansible/pull/1063)

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 21, 2012, 3:48am UTC](https://forum.ansible.com/t/documentation-strings-in-modules/11913/2 "2012-09-21T03:48:54Z")

</div>

This is a great idea, so thanks for getting this rolling. One thing  
I'm really looking forward to is having man pages for the ansible  
modules. That will be really useful.

Are things finalized enough at this point for people to start  
documenting the modules and submitting pull requests?

Romeo

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [September 21, 2012, 4:43am UTC](https://forum.ansible.com/t/documentation-strings-in-modules/11913/3 "2012-09-21T04:43:02Z")

</div>

> Are things finalized enough at this point for people to start  
> documenting the modules and submitting pull requests?

I believe so, and quoting Michael [1] : "I'm fine with this, let's go  
for it.", which is good enough for me.

Regards,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

[1] [https://github.com/ansible/ansible/issues/991#issuecomment-8690331](https://github.com/ansible/ansible/issues/991#issuecomment-8690331)

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 22, 2012, 8:12pm UTC](https://forum.ansible.com/t/documentation-strings-in-modules/11913/4 "2012-09-22T20:12:28Z")

</div>

Thanks Jan-Piet, I'll try to work on documenting some of the module  
in the coming week.

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [September 23, 2012, 6:12am UTC](https://forum.ansible.com/t/documentation-strings-in-modules/11913/5 "2012-09-23T06:12:21Z")

</div>

Romeo,

> I'll try to work on documenting some of the module  
> in the coming week.

please also follow what's going on in issue #991 [1] 🙂

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

[1] [https://github.com/ansible/ansible/issues/991](https://github.com/ansible/ansible/issues/991)
