From 0f505b0134dc195fe1e5ec3aa6aea319ff9a633c Mon Sep 17 00:00:00 2001 From: Super User Date: Sun, 20 Jul 2025 09:58:36 +0700 Subject: [PATCH] init main --- .gitea/workflows/homelab.yml | 75 +++++++++++++++++++++++++++++++++++ README.md | 3 ++ homelab/group_vars/all.yml | 8 ++++ homelab/host_vars/homelab.yml | 1 + homelab/hosts.yml | 4 ++ playbook.yml | 66 ++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+) create mode 100644 .gitea/workflows/homelab.yml create mode 100644 README.md create mode 100644 homelab/group_vars/all.yml create mode 100644 homelab/host_vars/homelab.yml create mode 100644 homelab/hosts.yml create mode 100644 playbook.yml diff --git a/.gitea/workflows/homelab.yml b/.gitea/workflows/homelab.yml new file mode 100644 index 0000000..abc9371 --- /dev/null +++ b/.gitea/workflows/homelab.yml @@ -0,0 +1,75 @@ +name: Run Ansible Playbook + +on: + workflow_dispatch: + inputs: + force: + type: boolean + description: "Force re-install" + required: true + default: false + version: + description: "Golang version" + required: true + target: + description: "Target hosts" + required: true + default: "homelab" + type: choice + options: + - "all" + - "homelab" + +jobs: + ansible-job: + runs-on: homelab + container: + image: dtrotskiy/ansible + + steps: + - name: 🔑 Configure SSH access + run: | + set -e + echo "🧰 Setting up SSH key for Ansible connection..." + mkdir -p ~/.ssh + echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + echo "✅ SSH key configured successfully." + + - name: 📦 Install required packages + run: | + set -e + echo "📦 Installing required packages: git, openssh, nodejs, npm..." + apk add --no-cache git openssh nodejs npm > /dev/null + echo "" + echo "🟢 Versions summary:" + echo " • Git: $(git --version)" + echo " • Node.js: $(node -v)" + echo " • npm: $(npm -v)" + echo " • Ansible: $(ansible --version | head -n1)" + echo "" + echo "✅ Environment setup complete." + + - name: 🌀 Clone repository + run: | + set -e + echo "⬇️ Cloning repository from Gitea..." + git clone https://gitea.bwonsamdi.ru/HomeLab/gonfig.git temp + echo "✅ Repository cloned into ./temp" + + - name: 🔍 Verify Ansible connectivity + run: | + set -e + echo "🔍 Checking connection to target '${{ inputs.target }}'..." + ansible all -m ping -i ./temp/homelab --limit "${{ inputs.target }}" + echo "✅ Ansible connectivity check passed." + + - name: 🚀 Execute Ansible playbook + run: | + set -e + echo "🚀 Running Ansible playbook for target '${{ inputs.target }}'..." + ansible-playbook ./temp/playbook.yml \ + -i ./temp/homelab \ + --limit "${{ inputs.target }}" \ + -e "go_version=${{ inputs.version }} force=${{ inputs.force }}" + echo "🎉 Playbook execution completed successfully!" diff --git a/README.md b/README.md new file mode 100644 index 0000000..b41a93c --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# gonfig + +Gonfig — умный конфигуратор для Golang. Он заботится о проверке версии, установке Go и корректной настройке переменных окружения. Настрой Go, не отвлекаясь от кода. \ No newline at end of file diff --git a/homelab/group_vars/all.yml b/homelab/group_vars/all.yml new file mode 100644 index 0000000..09ab348 --- /dev/null +++ b/homelab/group_vars/all.yml @@ -0,0 +1,8 @@ +ansible_python_interpreter: /usr/bin/python3 + +force: false + +go_tar: "go{{ go_version }}.linux-amd64.tar.gz" +go_url: "https://go.dev/dl/{{ go_tar }}" +go_install_path: "/usr/local" +go_env_path: "/etc/profile.d/go.sh" diff --git a/homelab/host_vars/homelab.yml b/homelab/host_vars/homelab.yml new file mode 100644 index 0000000..129ff17 --- /dev/null +++ b/homelab/host_vars/homelab.yml @@ -0,0 +1 @@ +go_version: "1.25.0" diff --git a/homelab/hosts.yml b/homelab/hosts.yml new file mode 100644 index 0000000..70f6010 --- /dev/null +++ b/homelab/hosts.yml @@ -0,0 +1,4 @@ +all: + hosts: + homelab: + ansible_host: 10.10.0.2 diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..569155f --- /dev/null +++ b/playbook.yml @@ -0,0 +1,66 @@ +--- +- name: Установка и настройка Golang + hosts: all + + pre_tasks: + - name: Проверка, установлен ли Go + command: go version + register: go_check + failed_when: false + changed_when: false + + - name: Извлечение версии Go из stdout + set_fact: + current_go_version: "{{ (go_check.stdout | regex_findall('go([0-9.]+)')) | first | default('') }}" + + - name: Отладка — текущая версия Go + debug: + msg: + - "Требуется версия Go: {{ go_version }}" + - "Установленная версия Go: {{ current_go_version }}" + - "Принудительная установка Go: {{ force }}" + + - name: Проверка, нужно ли обновлять Go + set_fact: + go_update_needed: "{{ force | bool or current_go_version != go_version }}" + + tasks: + - block: + - name: Удаление старой установки Go + file: + path: "{{ go_install_path }}/go" + state: absent + + - name: Загрузка архива Go + get_url: + url: "{{ go_url }}" + dest: "/tmp/{{ go_tar }}" + + - name: Распаковка Go + unarchive: + src: "/tmp/{{ go_tar }}" + dest: "{{ go_install_path }}" + remote_src: yes + when: go_update_needed + + post_tasks: + - name: Настройка переменных окружения для Go + copy: + dest: "{{ go_env_path }}" + content: | + export GOROOT={{ go_install_path }}/go + export GOPATH=$HOME/go + export PATH=$PATH:$GOROOT/bin:$GOPATH/bin + mode: '0644' + + - name: Применение переменных окружения + shell: source {{ go_env_path }} + args: + executable: /bin/bash + + - name: Добавляем CLI утилиты + shell: GOBIN=$GOROOT/bin go install {{ item }} + args: + executable: /bin/bash + loop: + - github.com/pressly/goose/cmd/goose@latest