Skip to content

Commit

Permalink
Merge pull request #7 from cidrblock/test_ansible
Browse files Browse the repository at this point in the history
Test ansible
  • Loading branch information
Bradley A. Thornton authored Dec 7, 2017
2 parents 3244a09 + ab9858e commit f2756ef
Show file tree
Hide file tree
Showing 24 changed files with 460 additions and 95 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ RUN apk add gcc libffi-dev musl-dev openssl-dev sshpass make
# RUN apk add py-crypto python-dev

# Install td4a
RUN pip install td4a==1.5
RUN pip install td4a==1.6

# Clear out extras
RUN rm -rf /var/cache/apk/*

RUN mkdir /filter_plugins
# Start td4a
CMD [ "td4a-server", "-f", "/filter_plugins" ]
CMD [ "td4a-server" ]
92 changes: 63 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,122 @@ All jinja2 filters are supported along with the filter plguins from Ansible vers

### Installation:

#### docker

If you do not have custom filter plugins.
#### using docker:

```
docker run -p 5000:5000 cidrblock/td4a
docker pull cidrblock/td4a
```

TD4A will look for custom plugins at /filter_plugins within the container. Pass your custom filter_plugins directory as a volume and expose port 5000.
```
docker run -p 5000:5000 -v `pwd`/my_filter_plugins:/filter_plugins cidrblock/td4a
```
The docker file can be found here:
The docker hub page can be found here:

https://hub.docker.com/r/cidrblock/td4a/

#### pip:
#### using the cli:
```
$ virtualenv venv
$ source venv/bin/activate
$ pip install td4a
$ td4a-server
```

The pip package can be found here:

https://pypi.python.org/pypi/td4a

### Usage
### Starting the TD4A server

The interface is browser based and has been tested using Chrome. If your browser did not automatically open when TD4A was started, you can visit http://127.0.0.1:5000 to see the interface.

The UI is broken into three sections:
#### Simple

1) DATA, this is where the data in yaml format is provided.
2) TEMPLATE, the jinja2 template to be rendered.
3) RESULT, after clicking the render button, the result pane will be populated with the rendered template.
##### using docker:
```
docker run -p 5000:5000 cidrblock/td4a
```

### Keyboard shortcuts
##### using the cli:
```
td4a-server
```

`cmd+r`: Render the template
##### open your browser to:

`cmd+s`: Save the data in browser local storage
http://127.0.0.1:5000

`cmd+b`: Begin new, clear the screen
#### Loading custom filter plugins

### Custom filters
##### using docker:

TD4A will look for custom plugins at /filter_plugins within the container. Pass your custom filter_plugins directory as a volume and expose port 5000.
```
docker run -p 5000:5000 -v `pwd`/my_filter_plugins:/filter_plugins cidrblock/td4a
```

##### using the cli:

TD4A can load custom filters from a directory specified from the command line:
```
td4a-server -f ./my_filter_plugins
```

#### Loading an ansible inventory

##### using docker:

TD4A will look for custom plugins at /filter_plugins within the container. Pass your custom filter_plugins directory as a volume and expose port 5000.
```
td4a-server -f ./filter_plugins
docker run -p 5000:5000 -v `pwd`/my_filter_plugins:/filter_plugins cidrblock/td4a
```

### Saving docs and building links
##### using the cli:

TD4A can load multiple ansible inventories, specifc each with `-i` on the command line:
```
td4a-server -i ./my_ansible_inventory -v 'my_vault_password'
```

#### Enabling storage and links using a couch database

TD4A has the ability to store data and templates in a CouchDB. This is disabled by defualt.

The CouchDB needs to previously created.

To enable link support, and add the link button to the UI, set the following environ variables:

#### docker:
##### using docker:

```
docker run -p 5000:5000 \
-v `pwd`/my_filter_plugins:/filter_plugins \
-e "COUCH_USERNAME=admin" \
-e "COUCH_PASSWORD=password" \
-e "COUCH_URL=http://192.168.1.5:5984/td4a" \
-e "ENABLE_LINK=true" \
td4a
cidrblock/td4a
```

#### pip:
##### using the cli:
```
export COUCH_USERNAME=admin
export COUCH_PASSWORD=password
export COUCH_URL=http://localhost:5984/td4a
export ENABLE_LINK=True
```

### User Interface

The interface is browser based and has been tested using Chrome. If your browser did not automatically open when TD4A was started, you can visit http://127.0.0.1:5000 to see the interface.

The UI is broken into three sections:

1) DATA, this is where the data in yaml format is provided.
2) TEMPLATE, the jinja2 template to be rendered.
3) RESULT, after clicking the render button, the result pane will be populated with the rendered template.

#### Keyboard shortcuts

`cmd+r`: Render the template

`cmd+s`: Save the data in browser local storage

`cmd+b`: Begin new, clear the screen

### Python version

To date, this has only been tested with python 2.7.
Expand Down
1 change: 1 addition & 0 deletions my_ansible_inventory/group_vars/all/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application_name: td4a
1 change: 1 addition & 0 deletions my_ansible_inventory/group_vars/routers/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
manufacturer: quagga
1 change: 1 addition & 0 deletions my_ansible_inventory/group_vars/servers/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
manufacturer: whitebox
29 changes: 29 additions & 0 deletions my_ansible_inventory/host_vars/router00/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ansible_ssh_pass: "{{ lookup('env', 'ANSIBLE_PASSWORD') }}"

interfaces:
Ethernet4/10:
description: siteassw100-g0/1-siteasrt001-eth4/10
name: Ethernet4/10
shutdown:
negate: true
switchport:
mode:
- trunk
switchport: true
Ethernet4/11:
channel_group:
id: 31
mode: active
description: unity1interface1
mtu: 9216
name: Ethernet4/11
shutdown:
negate: true
switchport:
mode:
- trunk
switchport: true
trunk:
allowed_vlans:
vlans: 3605,3607
native_vlan: 5
61 changes: 61 additions & 0 deletions my_ansible_inventory/host_vars/server00/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
# defaults file for ansible-apache2

# Defines if Apache2 should be configured
apache2_config: false

# Defines if php.ini should be configured for Apache2
apache2_config_php: false

# Defines if Apache2 virtual hosts should be configured
apache2_config_virtual_hosts: true

# Defines Apache2 default listen port
apache2_default_port: 80

# Defines if php-sqlite should be installed
apache2_install_php_sqlite: false

# Defines if php should be installed
apache2_install_php: false

apache2_php_max_execution_time: 30

apache2_php_max_input_time: 60

# Defines max memory for Apache php
# default is 128M
apache2_php_max_memory: 128M

apache2_php_post_max_size: 8M

apache2_php_timezone: "UTC"

apache2_php_upload_max_filesize: 2M

apache2_server_admin: webmaster@localhost

# Define Apache2 virtual hosts
apache2_virtual_hosts:
- documentroot: '/var/www/example.com'
default_site: false
port: 80
serveradmin: '{{ apache2_server_admin }}'
servername: 'www.example.com'
- documentroot: '/var/www/example.org'
default_site: false
port: 80
serveradmin: '{{ apache2_server_admin }}'
servername: 'www.example.org'
- documentroot: '/var/www/html'
default_site: true
port: 80
serveradmin: '{{ apache2_server_admin }}'
servername: ''

apache2_web_root: /var/www/html
apache2_log_dir: /var/log/apache

testVar: testing

anotherTestVar: "{{ testVar }}"
24 changes: 24 additions & 0 deletions my_ansible_inventory/host_vars/test00/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
a: "{{ b }}"
b:
c: this
d: that

foo: "{{ bar }}"
bar:
- 1
- 2
- 3

ansible_ssh_pass: "{{ lookup('env', 'FOO') }}"
cisco_xr_cli:
username: "{{ ansible_ssh_user }}"


y: "{{ z }}"
z:
aa:
bb:
cc:
dd: dd

f: "{{ bar + bar }}"
9 changes: 9 additions & 0 deletions my_ansible_inventory/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
router[00:03]
server[00:03]
test[00:03]

[routers]
router[00:03]

[servers]
server[00:03]
2 changes: 1 addition & 1 deletion now/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM cidrblock/td4a:latest
FROM cidrblock/td4a:1.6
EXPOSE 5000
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Flask==0.12.2
netaddr==0.7.19
Twisted==17.9.0
requests==2.18.4
ruamel.yaml==0.15.34
ruamel.yaml==0.15.35
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='td4a',
version='1.5',
version='1.6',
description='A browser based jinja template renderer',
url='http://github.com/cidrblock/td4a',
author='Bradley A. Thornton',
Expand All @@ -18,6 +18,6 @@
'netaddr==0.7.19',
'Twisted==17.9.0',
'requests==2.18.4',
'ruamel.yaml==0.15.34'
'ruamel.yaml==0.15.35'
],
zip_safe=False)
13 changes: 12 additions & 1 deletion td4a-server
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env python
from td4a import app
from td4a.models.filters import filters_load
from td4a.models.inventory import inventory_load
from argparse import ArgumentParser, RawTextHelpFormatter
import os
from twisted.internet import reactor
Expand All @@ -15,16 +16,25 @@ def parse_args():
parser.add_argument('-f', action="store", dest="custom_filters",
required=False,
help="A folder containing custom filters.")
parser.add_argument('-i', action="append", dest="inventory_source",
required=False,
help="A folder containing the inventory.")
parser.add_argument('-v', action="store", dest="vault_secret",
required=False,
help="A vault secret.")
args = parser.parse_args()
args.username = os.environ.get('COUCH_USERNAME', False)
args.password = os.environ.get('COUCH_PASSWORD', False)
args.enable_links = os.environ.get('ENABLE_LINK', False)
args.url = os.environ.get('COUCH_URL', False)
return args

def main():
print "Loading..."
app.args = parse_args()
app.filters = filters_load(app.args.custom_filters)
if app.args.inventory_source:
app.inventory = inventory_load(inventory_sources=app.args.inventory_source,
vault_secret=app.args.vault_secret)
reactor_args = {}
app.debug = False
def wsgi():
Expand All @@ -36,6 +46,7 @@ def main():
reactor_args['installSignalHandlers'] = 0
import werkzeug.serving
wsgi = werkzeug.serving.run_with_reloader(wsgi)
print "Ready."
wsgi()

if __name__ == '__main__':
Expand Down
13 changes: 9 additions & 4 deletions td4a/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from flask import Flask, request, jsonify
from td4a.controllers.render import api_render
from td4a.controllers.config import api_config
from td4a.controllers.hosts import api_hosts
from td4a.controllers.inventory import api_inventory
from td4a.controllers.link import api_link
from td4a.controllers.render import api_render
from td4a.controllers.retrieve import api_retrieve
from td4a.controllers.enable_link import api_enable_link


app = Flask(__name__, static_url_path='') # pylint: disable=invalid-name
app.register_blueprint(api_render)
app.register_blueprint(api_config)
app.register_blueprint(api_hosts)
app.register_blueprint(api_inventory)
app.register_blueprint(api_link)
app.register_blueprint(api_render)
app.register_blueprint(api_retrieve)
app.register_blueprint(api_enable_link)

@app.route('/')
def root():
Expand Down
Loading

0 comments on commit f2756ef

Please sign in to comment.