mirror of
https://github.com/ublue-os/forge.git
synced 2025-07-02 07:51:17 +03:00
wip - load ansible settings from VARS and not from ansible.cfg
This commit is contained in:
parent
50395caec7
commit
aa5377e6d7
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,3 +1,8 @@
|
|||
## Ansible
|
||||
**/collections
|
||||
!**/collections/requirements.yml
|
||||
|
||||
## Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
|
|
@ -2,19 +2,31 @@
|
|||
FROM docker.io/library/python:3.11-alpine3.19
|
||||
|
||||
# Environment vars
|
||||
ENV PROJECT_DIR="/anvil"
|
||||
ENV ANSIBLE_DIR="${PROJECT_DIR}/ansible"
|
||||
ENV NICEGUI_DIR="${PROJECT_DIR}/nicegui"
|
||||
ENV PIPX_BIN_DIR="/usr/local/py-utils"
|
||||
ENV PIPX_HOME="/usr/local/pipx"
|
||||
ENV POETRY_VERSION="1.8.2"
|
||||
ENV POETRY_VIRTUALENVS_CREATE="true"
|
||||
ENV POETRY_VIRTUALENVS_IN_PROJECT="true"
|
||||
ENV PATH="${PATH}:${PIPX_BIN_DIR}:${PIPX_HOME}/venvs/poetry/bin:/anvil/.venv/bin"
|
||||
ENV PATH="${PATH}:${PIPX_BIN_DIR}:${PIPX_HOME}/venvs/poetry/bin:/${PROJECT_DIR}/.venv/bin"
|
||||
## Ansible settings
|
||||
ENV ANSIBLE_INVENTORY="${ANSIBLE_DIR}/inventory.yml"
|
||||
ENV ANSIBLE_ROLES_PATH="${ANSIBLE_DIR}/roles"
|
||||
ENV ANSIBLE_COLLECTIONS_PATH="${ANSIBLE_DIR}/collections"
|
||||
ENV ANSIBLE_PRIVATE_KEY_FILE="/certs/ssh/ublue-os_forge-id_ed25519"
|
||||
ENV ANSIBLE_DISPLAY_SKIPPED_HOSTS="False"
|
||||
ENV ANSIBLE_STDOUT_CALLBACK="yaml"
|
||||
ENV ANSIBLE_CALLBACKS_ENABLED="ansible.posix.profile_tasks"
|
||||
ENV ANSIBLE_HOST_KEY_CHECKING="False"
|
||||
|
||||
# Install system dependencies
|
||||
RUN apk --no-cache add pipx openssh bash
|
||||
RUN pipx install poetry==${POETRY_VERSION}
|
||||
|
||||
# Install ansible and dependencies
|
||||
WORKDIR /anvil
|
||||
WORKDIR ${PROJECT_DIR}
|
||||
COPY . .
|
||||
RUN poetry install --no-root
|
||||
CMD poetry env use .venv/bin/python && \
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
- name: DEBUG | forge variables
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ item }}: {{ lookup('ansible.builtin.vars', item) }}"
|
||||
verbosity: 1
|
||||
# verbosity: 1
|
||||
loop: "{{ __forge_vars_used }}"
|
||||
loop_control:
|
||||
extended: true
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#! /bin/bash
|
||||
## Start nicegui
|
||||
poetry env use .venv/bin/python && poetry run python nicegui/main.py
|
||||
poetry env use .venv/bin/python && poetry run python ${NICEGUI_DIR}/main.py
|
|
@ -1,10 +1,10 @@
|
|||
from nicegui import ui
|
||||
from utils import get_project_root
|
||||
import os
|
||||
|
||||
|
||||
def content() -> None:
|
||||
project_root = str(get_project_root())
|
||||
project_root = os.environ['NICEGUI_DIR']
|
||||
ui.label("Work in progress...").classes("text-h6")
|
||||
ui.image(project_root + "/nicegui/pages/assets/work-in-progress.png").classes(
|
||||
ui.image(project_root + "/pages/assets/work-in-progress.png").classes(
|
||||
"w-[200%]"
|
||||
)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import ansible_runner
|
||||
import re
|
||||
import asyncio
|
||||
import os
|
||||
from nicegui import ui
|
||||
from theme import GuiProgressSpinner
|
||||
from utils import get_project_root, local_file_picker
|
||||
from utils import local_file_picker
|
||||
|
||||
ANSIBLE_EXTRA_VARS = None
|
||||
|
||||
|
@ -11,6 +12,7 @@ ANSIBLE_EXTRA_VARS = None
|
|||
# Ansible integration
|
||||
@ui.refreshable # https://www.reddit.com/r/nicegui/comments/1bphjk5/comment/kx7l5kj/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
|
||||
async def load_configuration_file() -> None:
|
||||
global ANSIBLE_EXTRA_VARS
|
||||
result = await local_file_picker(
|
||||
directory="/data", multiple=False, file_name_filter=".yml"
|
||||
)
|
||||
|
@ -22,7 +24,7 @@ async def load_configuration_file() -> None:
|
|||
## Display content
|
||||
ui.code(content=data, language="yaml")
|
||||
## Preserve configuration file path for ansible-playbook --extra-vars
|
||||
ANSIBLE_EXTRA_VARS = f'"@{file_path}"'
|
||||
ANSIBLE_EXTRA_VARS = f"@{file_path}"
|
||||
|
||||
|
||||
async def run_ansible_playbook(playbook_name: str, gui_log: ui.log, gui_spinner: GuiProgressSpinner) -> None:
|
||||
|
@ -31,16 +33,14 @@ async def run_ansible_playbook(playbook_name: str, gui_log: ui.log, gui_spinner:
|
|||
# Enable spinner
|
||||
gui_spinner.enable()
|
||||
# Run ansible playbook
|
||||
project_root = str(get_project_root())
|
||||
playbook_path = project_root + "/ansible/playbooks/"
|
||||
inventory_path = project_root + "/ansible/inventory.yml"
|
||||
extra_vars_file = str(ANSIBLE_EXTRA_VARS)
|
||||
project_root = os.environ['ANSIBLE_DIR']
|
||||
playbook_path = f"{project_root}/playbooks/"
|
||||
extra_vars_file = ANSIBLE_EXTRA_VARS
|
||||
thread, runner = ansible_runner.interface.run_command_async(
|
||||
executable_cmd="ansible-playbook",
|
||||
cmdline_args=[
|
||||
playbook_path + playbook_name,
|
||||
"-i",
|
||||
inventory_path,
|
||||
f"{playbook_path}/{playbook_name}",
|
||||
# playbook_path + playbook_name,
|
||||
"--extra-vars",
|
||||
extra_vars_file,
|
||||
],
|
||||
|
@ -89,7 +89,7 @@ def content() -> None:
|
|||
text="Clone project",
|
||||
on_click=lambda: run_ansible_playbook(
|
||||
playbook_name="project_clone.yml",
|
||||
gui_log=playbook_log,
|
||||
gui_log=gui_playbook_log,
|
||||
gui_spinner=gui_build_progress,
|
||||
),
|
||||
)
|
||||
|
@ -97,7 +97,7 @@ def content() -> None:
|
|||
text="Build project",
|
||||
on_click=lambda: run_ansible_playbook(
|
||||
"project_build.yml",
|
||||
gui_log=playbook_log,
|
||||
gui_log=gui_playbook_log,
|
||||
gui_spinner=gui_build_progress,
|
||||
),
|
||||
)
|
||||
|
@ -114,6 +114,6 @@ def content() -> None:
|
|||
with ui.row().classes("w-full"):
|
||||
with ui.card().classes("w-full"):
|
||||
ui.label("Playbook Log").classes("text-h6")
|
||||
ui.button("Clear Log", on_click=lambda: playbook_log.clear())
|
||||
ui.button("Clear Log", on_click=lambda: gui_playbook_log.clear())
|
||||
|
||||
playbook_log = ui.log().classes("w-full h-full")
|
||||
gui_playbook_log = ui.log().classes("w-full h-full")
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from nicegui import ui
|
||||
from utils import get_project_root
|
||||
import os
|
||||
|
||||
|
||||
def content() -> None:
|
||||
project_root = str(get_project_root())
|
||||
project_root = os.environ['NICEGUI_DIR']
|
||||
ui.label("Work in progress...").classes("text-h6")
|
||||
ui.image(project_root + "/nicegui/pages/assets/work-in-progress.png").classes(
|
||||
ui.image(project_root + "/pages/assets/work-in-progress.png").classes(
|
||||
"w-[200%]"
|
||||
)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from nicegui import ui
|
||||
from utils import get_project_root
|
||||
import os
|
||||
|
||||
|
||||
def content() -> None:
|
||||
project_root = str(get_project_root())
|
||||
project_root = os.environ['NICEGUI_DIR']
|
||||
ui.label("Work in progress...").classes("text-h6")
|
||||
ui.image(project_root + "/nicegui/pages/assets/work-in-progress.png").classes(
|
||||
ui.image(project_root + "/pages/assets/work-in-progress.png").classes(
|
||||
"w-[200%]"
|
||||
)
|
||||
|
|
|
@ -114,7 +114,3 @@ class local_file_picker(ui.dialog):
|
|||
f"getElement({self.grid.id}).gridOptions.api.getSelectedRows()"
|
||||
)
|
||||
self.submit([r["path"] for r in rows])
|
||||
|
||||
|
||||
def get_project_root() -> Path:
|
||||
return Path(__file__).parent.parent
|
||||
|
|
Loading…
Reference in a new issue