-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hello ansible and hello ansible form route
- Loading branch information
root
committed
May 2, 2020
1 parent
9a1d4a4
commit b57e186
Showing
9 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Hello ansible | ||
hosts: 127.0.0.1 | ||
connection: local | ||
|
||
tasks: | ||
- name: Print debug message | ||
debug: | ||
msg: "Hello ansible !" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Hello ansible | ||
hosts: 127.0.0.1 | ||
connection: local | ||
|
||
tasks: | ||
- name: Print debug message | ||
debug: | ||
msg: "Hello ansible, this is my var: {{ sample_var }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
from flask import Flask | ||
from potoo.utils import get_config | ||
|
||
app = Flask(__name__) | ||
config = get_config() | ||
|
||
app = Flask(__name__,root_path='potoo') | ||
app.config.from_object(__name__) | ||
app.config['SECRET_KEY'] = config['flask']['SECRET_KEY'] | ||
|
||
from potoo.routes import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ansible_runner | ||
from potoo import app | ||
from potoo.utils import * | ||
|
||
@app.route("/hello_ansible") | ||
def hello_ansible(): | ||
|
||
PLAYBOOK_FILE = os.path.join(os.getcwd(), "playbooks/hello_ansible.yml") | ||
|
||
r = ansible_runner.run(playbook=PLAYBOOK_FILE, extravars={"my_var":"content"}) | ||
|
||
return r.stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ansible_runner | ||
from flask import Flask, render_template, flash, request | ||
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField | ||
from potoo import app | ||
from potoo.utils import * | ||
|
||
class helloAnsibleForm(Form): | ||
sample_var = TextField('Sample var:', validators=[validators.required()]) | ||
|
||
@app.route("/hello_ansible_form", methods=['GET', 'POST']) | ||
def hello(): | ||
PLAYBOOK_FILE = os.path.join(os.getcwd(), "playbooks/hello_ansible_form.yml") | ||
form = helloAnsibleForm(request.form) | ||
|
||
if request.method == 'POST': | ||
sample_var=request.form['sample_var'] | ||
|
||
if form.validate(): | ||
extravars = {"sample_var": sample_var} | ||
r = ansible_runner.run(playbook=PLAYBOOK_FILE, extravars=extravars) | ||
flash('Sample var: ' + sample_var) | ||
flash("{}: {}".format(r.status, r.rc)) | ||
flash(r.stats) | ||
else: | ||
flash('Error: All the form fields are required.') | ||
|
||
return render_template('hello_ansible_form.html', form=form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<title>Hello ansible form</title> | ||
|
||
{% with messages = get_flashed_messages(with_categories=true) %} | ||
{% if messages %} | ||
<ul> | ||
{% for message in messages %} | ||
<li>{{ message[1] }}</li> | ||
{% endfor %}</ul> | ||
{% endif %} | ||
{% endwith %} | ||
<form action="" method="post"> | ||
{{ form.csrf }} | ||
<div class="input text"> | ||
{{ form.sample_var.label }} {{ form.sample_var }}</div> | ||
<div class="input submit"> | ||
<input type="submit" value="Submit"></div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
ansi2html==1.5.2 | ||
ansible==2.9.7 | ||
ansible-runner==1.4.6 | ||
cffi==1.14.0 | ||
click==7.1.1 | ||
cryptography==2.9.2 | ||
docutils==0.16 | ||
Flask==1.1.2 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.11.2 | ||
lockfile==0.12.2 | ||
MarkupSafe==1.1.1 | ||
pexpect==4.8.0 | ||
pkg-resources==0.0.0 | ||
psutil==5.7.0 | ||
ptyprocess==0.6.0 | ||
pycparser==2.20 | ||
python-daemon==2.2.4 | ||
PyYAML==5.3.1 | ||
six==1.14.0 | ||
Werkzeug==1.0.1 | ||
WTForms==2.3.1 |