From ccad5c1201d36b3fac8a54796e5c1cabcd47efab Mon Sep 17 00:00:00 2001 From: ske087 Date: Tue, 12 May 2026 16:42:37 +0300 Subject: [PATCH] feat: fix migrate_to_wmt playbook; restructure sidebar nav; add Client Name column to WMT dashboard --- ansible/playbooks/migrate_to_wmt.yml | 40 +++++++++++++++++++++++----- app/web/ansible.py | 13 ++++++++- templates/ansible/execute.html | 6 +++++ templates/ansible/playbooks.html | 6 ++--- templates/base.html | 16 +++++------ templates/wmt/index.html | 2 ++ 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/ansible/playbooks/migrate_to_wmt.yml b/ansible/playbooks/migrate_to_wmt.yml index c76336a..f3091f5 100644 --- a/ansible/playbooks/migrate_to_wmt.yml +++ b/ansible/playbooks/migrate_to_wmt.yml @@ -97,13 +97,39 @@ debug: msg: "work_place will be set to: '{{ work_place_value }}'" - # ── 5. Replace work_place value in WMT/data/config.txt ─────────────── - - name: Replace work_place in WMT config.txt - lineinfile: - path: /home/pi/Desktop/WMT/data/config.txt - regexp: '^work_place\s*=.*' - line: "work_place={{ work_place_value }}" - backup: true + # ── 5. Write work_place into WMT/data/config.txt ────────────────────── + # Uses Python (always available on Raspberry Pi) to correctly + # read/write the INI file and set work_place inside [device]. + # Also resets last_synced to epoch so first startup does NOT + # overwrite work_place with a potentially empty server value. + - name: Set work_place in WMT config.txt via Python + ansible.builtin.shell: + cmd: | + python3 - <<'PYEOF' + import configparser, os + path = '/home/pi/Desktop/WMT/data/config.txt' + p = configparser.ConfigParser() + p.read(path) + if not p.has_section('chrome'): + p.add_section('chrome') + if not p.has_section('card_api'): + p.add_section('card_api') + if not p.has_section('server'): + p.add_section('server') + if not p.has_section('device'): + p.add_section('device') + if not p.has_section('meta'): + p.add_section('meta') + p.set('device', 'work_place', '{{ work_place_value }}') + # Reset last_synced so first startup pull from server does not + # overwrite the work_place we just set (server will return the + # correct device_name once this device checks in). + p.set('meta', 'last_synced', '1970-01-01T00:00:00') + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, 'w') as f: + p.write(f) + print('work_place set to: {{ work_place_value }}') + PYEOF - name: Confirm work_place change command: grep 'work_place' /home/pi/Desktop/WMT/data/config.txt diff --git a/app/web/ansible.py b/app/web/ansible.py index 68c2b60..fb03e46 100644 --- a/app/web/ansible.py +++ b/app/web/ansible.py @@ -129,10 +129,20 @@ def execute(): seen.add(h['hostname']) settings = ansible_service.load_settings() + + # Discover custom playbooks (exclude built-ins that have dedicated buttons) + _builtin_names = {'update_devices', 'restart_service', 'distribute_ssh_keys', 'system_health'} + custom_playbooks = [] + if ansible_service.playbook_dir.exists(): + for _f in sorted(ansible_service.playbook_dir.glob('*.yml')): + if _f.stem.lower() not in _builtin_names: + custom_playbooks.append({'name': _f.stem, 'filename': _f.name}) + return render_template('ansible/execute.html', inventory=inventory_data, all_inv_hosts=all_inv_hosts, preselect_playbook=preselect, + custom_playbooks=custom_playbooks, use_password_auth=settings.get('use_password_auth', False)) except Exception as e: logging.error(f"Error loading execute form: {e}") @@ -141,6 +151,7 @@ def execute(): inventory={'groups': {}}, all_inv_hosts=[], preselect_playbook='', + custom_playbooks=[], use_password_auth=False) elif request.method == 'POST': @@ -462,7 +473,7 @@ def playbook_content(): from pathlib import Path requested_path = Path(playbook_path) if not requested_path.is_absolute(): - requested_path = ansible_service.playbook_dir / requested_path + requested_path = Path.cwd() / requested_path # Ensure path is within playbook directory try: diff --git a/templates/ansible/execute.html b/templates/ansible/execute.html index ca0ac09..a7e2739 100644 --- a/templates/ansible/execute.html +++ b/templates/ansible/execute.html @@ -91,6 +91,12 @@
Custom Playbooks
diff --git a/templates/ansible/playbooks.html b/templates/ansible/playbooks.html index 7ebaebe..88f0c7f 100644 --- a/templates/ansible/playbooks.html +++ b/templates/ansible/playbooks.html @@ -21,12 +21,12 @@ background-color: #f8f9ff; } .code-editor-area { - min-height: 400px; + min-height: 600px; border: 1px solid #dee2e6; border-radius: 0.375rem; } .CodeMirror { - height: 400px; + height: 600px; border-radius: 0.375rem; } .playbook-actions { @@ -244,7 +244,7 @@