Skip to content

Commit

Permalink
added option to copy system-environment information to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Feb 20, 2024
1 parent fbef9c0 commit 403aaf2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/ansible-webui/aw/static/js/aw.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ function hashString(data) {
return hash;
}

function jsonToClipboard(jsonElement) {
// to create json dump element: '{{ <dict>|json_script:"<jsonElement>" }}'
let versionsJson = document.getElementById(jsonElement).innerText;
console.log('Copied: ', versionsJson);
navigator.clipboard.writeText(versionsJson);
}

// API CALLS
const CSRF_TOKEN = getCookie('csrftoken');

Expand Down
16 changes: 16 additions & 0 deletions src/ansible-webui/aw/templates/system/environment.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ <h2>System version</h2>
<td>{{ env_linux }}</td>
</tr>
</table>
{{ env_system|json_script:"aw-json-system" }}
<button class="btn btn-info aw-btn-action aw-btn-refresh" title="Copy Versions" onclick="jsonToClipboard('aw-json-system')">
<i class="fas fa-copy fa-2x aw-btn-action-icon"></i>
</button>
</div>
<hr>
<h2>Ansible Config</h2>
Expand All @@ -88,6 +92,10 @@ <h2>Ansible Config</h2>
</tr>
{% endfor %}
</table>
{{ env_ansible_config|json_script:"aw-json-ansible-config" }}
<button class="btn btn-info aw-btn-action aw-btn-refresh" title="Copy Versions" onclick="jsonToClipboard('aw-json-ansible-config')">
<i class="fas fa-copy fa-2x aw-btn-action-icon"></i>
</button>
</div>
<hr>
<h2>Ansible Collections</h2>
Expand All @@ -106,6 +114,10 @@ <h2>Ansible Collections</h2>
</tr>
{% endfor %}
</table>
{{ env_ansible_collections|json_script:"aw-json-ansible-collections" }}
<button class="btn btn-info aw-btn-action aw-btn-refresh" title="Copy Versions" onclick="jsonToClipboard('aw-json-ansible-collections')">
<i class="fas fa-copy fa-2x aw-btn-action-icon"></i>
</button>
</div>
<hr>
<h2>Python Modules</h2>
Expand All @@ -122,6 +134,10 @@ <h2>Python Modules</h2>
</tr>
{% endfor %}
</table>
{{ env_python_modules|json_script:"aw-json-python-modules" }}
<button class="btn btn-info aw-btn-action aw-btn-refresh" title="Copy Versions" onclick="jsonToClipboard('aw-json-python-modules')">
<i class="fas fa-copy fa-2x aw-btn-action-icon"></i>
</button>
</div>
</div>
{% endblock %}
29 changes: 19 additions & 10 deletions src/ansible-webui/aw/views/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from aw.config.main import config
from aw.config.environment import AW_ENV_VARS, AW_ENV_VARS_SECRET
from aw.model.system import SystemConfig
from aw.utils.deployment import deployment_docker


def _parsed_ansible_collections() -> dict:
Expand Down Expand Up @@ -131,24 +132,32 @@ def system_environment(request) -> HttpResponse:
python_modules = _parsed_python_modules()
ansible_version = _parsed_ansible_version(python_modules)

system_versions = process(['uname', '-a'])['stdout']
if deployment_docker():
system_versions += ' (dockerized)'

env_system = {
'env_linux': system_versions,
'env_git': process(['git', '--version'])['stdout'],
'env_ansible_core': ansible_version['ansible_core'],
'env_ansible_runner': ansible_version['ansible_runner'],
'env_django': python_modules['django']['version'],
'env_django_api': python_modules['djangorestframework']['version'],
'env_gunicorn': python_modules['gunicorn']['version'],
'env_jinja': ansible_version['jinja'],
'env_libyaml': ansible_version['libyaml'],
}
return render(
request, status=200, template_name='system/environment.html',
context={
'env_linux': process(['uname', '-a'])['stdout'],
'env_git': process(['git', '--version'])['stdout'],
'env_ansible_core': ansible_version['ansible_core'],
'env_ansible_runner': ansible_version['ansible_runner'],
'env_django': python_modules['django']['version'],
'env_django_api': python_modules['djangorestframework']['version'],
'env_gunicorn': python_modules['gunicorn']['version'],
'env_jinja': ansible_version['jinja'],
'env_libyaml': ansible_version['libyaml'],
**env_system,
'env_system': env_system,
'env_python': f"{version_info.major}.{version_info.minor}.{version_info.micro}",
'env_python_modules': python_modules,
'env_ansible_config': _parsed_ansible_config(),
# 'env_ansible_roles': get_role_list(),
'env_ansible_collections': _parsed_ansible_collections(),
}
},
)


Expand Down

0 comments on commit 403aaf2

Please sign in to comment.