Skip to content

Commit

Permalink
minor fixes & demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Feb 15, 2024
1 parent fba0c8a commit fb10471
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
# paths:
# - '**.py'
# - '.github/workflows/codeql.yml'
#pull_request:
# pull_request:
# branches: ['latest']
# paths:
# - '**.py'
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ python3 -m ansible-webui

----

## Demo

Check out the demo at: [demo.webui.ansibleguy.net](demo.webui.ansibleguy.net)

Login: User `demo`, Password `Ansible1337`

----

## Usage

[Documentation](http://ansible-webui.readthedocs.io/)
Expand Down
7 changes: 7 additions & 0 deletions docs/source/usage/2_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ See `the documentation <https://docs.ansible.com/ansible/latest/installation_gui

**Make sure to read** the `Ansible best-practices <https://docs.ansible.com/ansible/2.8/user_guide/playbooks_best_practices.html#directory-layout>`_ on how to use Ansible!

Demo
****

Check out the demo at: `demo.webui.ansibleguy.net <demo.webui.ansibleguy.net>`_

Login: User :code:`demo`, Password :code:`Ansible1337`

Install
*******

Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export AW_ENV='dev'
export AW_DB="/tmp/$(date +%s).aw.db"
# shellcheck disable=SC2155
export AW_PATH_PLAY="$(pwd)/test"
export AW_ADMIN='ansible'
export AW_ADMIN='tester'
export AW_ADMIN_PWD='someSecret!Pwd'
python3 src/ansible-webui/ >/dev/null 2>/dev/null &
echo ''
Expand Down
8 changes: 6 additions & 2 deletions src/ansible-webui/aw/api_endpoints/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ def _want_job_executions(request) -> tuple:
def _has_credentials_permission(user: USERS, data: dict) -> bool:
if 'credentials_default' in data and is_set(data['credentials_default']):
try:
credentials = data['credentials_default']
if not isinstance(credentials, JobGlobalCredentials):
credentials = JobGlobalCredentials.objects.get(id=credentials)

return has_credentials_permission(
user=user,
credentials=JobGlobalCredentials.objects.get(id=data['credentials_default']),
credentials=credentials,
permission_needed=CHOICE_PERMISSION_READ,
)

Expand Down Expand Up @@ -266,7 +270,7 @@ def put(self, request, job_id: int):
)

try:
Job.objects.filter(id=job_id).update(**serializer.data)
Job.objects.filter(id=job.id).update(**serializer.data)

except IntegrityError as err:
return Response(
Expand Down
1 change: 1 addition & 0 deletions src/ansible-webui/aw/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def init_globals():
environ.setdefault('DJANGO_SETTINGS_MODULE', 'aw.settings')
environ['PYTHONIOENCODING'] = 'utf8'
environ['PYTHONUNBUFFERED'] = '1'
environ['ANSIBLE_FORCE_COLOR'] = '1'

for cnf_key in AW_ENV_VARS:
config[cnf_key] = get_aw_env_var(cnf_key)
Expand Down
24 changes: 14 additions & 10 deletions src/ansible-webui/aw/execute/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os import getpid
from os import kill as os_kill
from sys import exit as sys_exit
from threading import Thread
from threading import Thread, ThreadError
from time import sleep, time

from gunicorn.arbiter import Arbiter
Expand Down Expand Up @@ -68,18 +68,22 @@ def _run(self):
time_last_reload = time()

while True:
if self.stopping:
break
try:
if self.stopping:
break

if time() > (time_last_check + INTERVAL_CHECK):
self.check()
time_last_check = time()

if time() > (time_last_check + INTERVAL_CHECK):
self.check()
time_last_check = time()
if time() > (time_last_reload + INTERVAL_RELOAD):
self.reload()
time_last_reload = time()

if time() > (time_last_reload + INTERVAL_RELOAD):
self.reload()
time_last_reload = time()
sleep(self.WAIT_TIME)

sleep(self.WAIT_TIME)
except ThreadError as err:
log(msg=f'Got thread error: {err}', level=2)

except Exception as err:
log(msg=f'Got unexpected error: {err}', level=1)
Expand Down
1 change: 1 addition & 0 deletions src/ansible-webui/aw/static/js/aw.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function fetchApiTableData(apiEndpoint, updateFunction, secondRow = false, place
}
}
});
updateReloadTime();
}

// EVENTHANDLER
Expand Down
15 changes: 13 additions & 2 deletions src/ansible-webui/aw/templatetags/form_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,32 @@ def get_form_field_select(bf: BoundField, existing: dict) -> str:
selected = None
if bf.name in existing:
selected = str(existing[bf.name])
elif f'{bf.name}_id' in existing:
selected = str(existing[f'{bf.name}_id'])
elif bf.field.initial is not None:
selected = bf.field.initial

options_str = f'<select class="form-control" id="{bf.id_for_label}" name="{bf.name}"'
if isinstance(bf.field, MultipleChoiceField):
# todo: selected for multi-select
options_str += ' multiple'
selected = None # not implemented

options_str += '>'
if selected is None:
options_str += '<option disabled selected value>Choose an option</option>'

if not hasattr(bf.field, '_choices'):
raise AttributeError(f"Field '{bf.name}' is of an invalid type: {type(bf.field)} - {bf.field.__dict__}")

if bf.field.required:
if selected is None:
options_str += '<option disabled selected value>Choose an option</option>'

else:
if selected is None:
options_str += '<option selected value>None</option>'
else:
options_str += '<option value>None</option>'

# pylint: disable=W0212
for option in bf.field._choices:
is_selected = 'selected' if str(option[0]) == str(selected) else ''
Expand Down
36 changes: 36 additions & 0 deletions test/demo/play1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---

- hosts: localhost
become: false
gather_facts: false
tasks:
- name: Listing files in directory
ansible.builtin.command: 'ls -l /play'
register: job1

- name: Show response
ansible.builtin.debug:
var: job1.stdout_lines

- name: Add config file
ansible.builtin.copy:
content: |
# ansible_managed
# this is some config..
key={{ job_value | default('no') }}
dest: '/tmp/awtest.txt'
mode: 0640

- name: Wait some time
ansible.builtin.pause:
seconds: 30

- name: Remove file
ansible.builtin.file:
path: '/tmp/awtest.txt'
state: absent


- name: Output some information
ansible.builtin.debug:
msg: 'Ansible-WebUI DEMO'
27 changes: 27 additions & 0 deletions test/demo/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

AW_ADMIN='USER'
AW_ADMIN_PWD='PWD'

echo '### REMOVING EXISTING ###'
if docker ps -a | grep -q ansible-webui
then
docker stop ansible-webui
docker rm ansible-webui
fi
if docker image ls | grep -q ansible-webui
then
docker image rm ansible-webui:latest
fi

echo '### BUILDING LATEST ###'
cd /tmp
rm -rf /tmp/ansible-webui
git clone https://github.com/ansibleguy/ansible-webui.git
cd /tmp/ansible-webui/docker
docker build -f Dockerfile_production -t ansible-webui:latest --build-arg "AW_VERSION=latest" .

echo '### STARTING ###'
docker run -d --restart unless-stopped --name ansible-webui --publish 8000:8000 --volume /var/local/ansible-webui/:/data --volume /var/local/ansible-webui/play/:/play --env AW_ADMIN_PWD="$AW_ADMIN_PWD" --env AW_ADMIN="$AW_ADMIN" ansible-webui
2 changes: 1 addition & 1 deletion test/integration/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_add():
'limit': 'srv1',
}},
{'l': 'key', 'd': None},
{'l': 'permission', 'd': {'name': 'perm1', 'jobs': 1}},
{'l': 'permission', 'd': {'name': 'perm1', 'jobs': 1, 'credentials': 1}},
])


Expand Down

0 comments on commit fb10471

Please sign in to comment.