init main

This commit is contained in:
Super User
2025-07-20 09:58:36 +07:00
commit fb60c41aaa
6 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
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: "prodesk"
type: choice
options:
- "all"
- "prodesk"
jobs:
ansible-job:
runs-on: homelab
container:
image: dtrotskiy/ansible
steps:
- name: debug
run: |
echo "10.10.1.10 gitea.bwonsamdi.ru" >> /etc/hosts
- name: Test
run: |
curl -v https://gitea.bwonsamdi.ru/HomeLab/gonfig.git
- name: Checkout code
run: |
git clone https://gitea.bwonsamdi.ru/HomeLab/gonfig.git dump
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Run Ansible playbook
run: |
ansible-playbook ./dump/playbook.yml -i ./dump/hosts.yml -e "go_version=${{ inputs.version }} force=${{ inputs.force }} TARGET=prodesk"

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# gonfig
Gonfig — умный конфигуратор для Golang. Он заботится о проверке версии, установке Go и корректной настройке переменных окружения. Настрой Go, не отвлекаясь от кода.

8
group_vars/all.yml Normal file
View File

@@ -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"

2
host_vars/prodesk.yml Normal file
View File

@@ -0,0 +1,2 @@
go_version: "1.24.5"

4
hosts.yml Normal file
View File

@@ -0,0 +1,4 @@
all:
hosts:
prodesk:
ansible_host: 10.10.1.10

63
playbook.yml Normal file
View File

@@ -0,0 +1,63 @@
---
- name: Установка и настройка Golang
hosts: "{{ TARGET }}"
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'
notify:
- "update-go-env"
handlers:
- name: Применение переменных окружения
listen: update-go-env
shell: source {{ go_env_path }}
args:
executable: /bin/bash