fixes to playbooks_directives generation

order is now predictable
now correctly substitutes loop for with_
adds local_action to action
This commit is contained in:
Brian Coca 2016-02-26 16:18:55 -05:00
parent 512d3dd621
commit a3489408a5
2 changed files with 25 additions and 9 deletions

View file

@ -10,9 +10,8 @@ from ansible.playbook.task import Task
template_file = 'playbooks_directives.rst.j2' template_file = 'playbooks_directives.rst.j2'
oblist = {} oblist = {}
for aclass in Play, Block, Role, Task: clist = []
aobj = aclass() class_list = [ Play, Role, Block, Task ]
oblist[type(aobj).__name__] = aobj
p = optparse.OptionParser( p = optparse.OptionParser(
version='%prog 1.0', version='%prog 1.0',
@ -24,10 +23,28 @@ p.add_option("-o", "--output-dir", action="store", dest="output_dir", default='/
(options, args) = p.parse_args() (options, args) = p.parse_args()
for aclass in class_list
aobj = aclass()
name = type(aobj).__name__
# build ordered list to loop over and dict with attributes
clist.append(name)
oblist[name] = aobj.__dict__['_attributes']
# loop is really with_ for users
if 'loop' in oblist[name]:
oblist[name]['with_<lookup_plugin>'] = True
del oblist[name]['loop']
del oblist[name]['loop_args']
# local_action is implicit with action
if 'action' in oblist[name]:
oblist[name]['local_action'] = True
env = Environment(loader=FileSystemLoader(options.template_dir), trim_blocks=True,) env = Environment(loader=FileSystemLoader(options.template_dir), trim_blocks=True,)
template = env.get_template(template_file) template = env.get_template(template_file)
outputname = options.output_dir + template_file.replace('.j2','') outputname = options.output_dir + template_file.replace('.j2','')
tempvars = { 'oblist': oblist } tempvars = { 'oblist': oblist, 'clist': clist }
with open( outputname, 'w') as f: with open( outputname, 'w') as f:
f.write(template.render(tempvars)) f.write(template.render(tempvars))

View file

@ -1,21 +1,20 @@
Directives Glossary Directives Glossary
=================== ===================
Here we list the common playbook objects and the possible directives that can be used with them. Here we list the common playbook objects and the their directives.
Note that not all directives affect the object itself and might just be there to be inherited by other contained objects. Note that not all directives affect the object itself and might just be there to be inherited by other contained objects.
Aliases for the directives are not reflected here, nor are mutable ones, for example `action` in task can be substituted by the name of any module plugin.
.. contents:: .. contents::
:local: :local:
:depth: 1 :depth: 1
{% for name in oblist %} {% for name in clist %}
{{ name }} {{ name }}
{{ '-' * name|length }} {{ '-' * name|length }}
{% for attribute in oblist[name].__dict__['_attributes']|sort %} {% for attribute in oblist[name]|sort %}
{% if attribute not in ['loop', 'loop_args'] %}
* {{ attribute }} * {{ attribute }}
{% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}