Skip to content

Commit

Permalink
Make listing inventories/playbooks look nicer; add the Jinja2 template;
Browse files Browse the repository at this point in the history
  • Loading branch information
br0ziliy committed Jun 2, 2016
1 parent 11b4f2e commit 6c9c098
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ def ansible_list(self, mess, objects=None):
playbooks = []
inventories = []
# walk() comes from package "os"
for (dirpath, dirnames, filenames) in walk(self.config['PLAYBOOK_DIR']):
playbooks.extend(filenames)
break
for (dirpath, dirnames, filenames) in walk(self.config['INVENTORY_DIR']):
inventories.extend(filenames)
break
# TODO: below code sucks rocks, but it's 11pm and I have a bottle of
# cold beer waiting for me.
if objects == 'playbooks': return { 'objects': objects, 'objlist': playbooks }
elif objects == 'inventories': return { 'objects': objects, 'objlist': inventories }
return { 'objects': 'all', 'objlist': playbooks + inventories }
if objects is 'playbooks' or objects is 'all':
for (dirpath, dirnames, filenames) in walk(self.config['PLAYBOOK_DIR']):
playbooks.extend(filenames)
break
if objects is 'inventories' or objects is 'all':
for (dirpath, dirnames, filenames) in walk(self.config['INVENTORY_DIR']):
inventories.extend(filenames)
break
return { 'playbooks': playbooks, 'inventories': inventories }
19 changes: 19 additions & 0 deletions templates/list_objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{%- if playbooks is defined %}
Playbooks:

```
{% for obj in playbooks %}
* {{ obj }}
{%- endfor %}
```
{%- endif %}
{%- if inventories is defined %}
Inventory files:

```
{% for obj in inventories %}
* {{ obj }}
{%- endfor %}
```
{%- endif %}

0 comments on commit 6c9c098

Please sign in to comment.