commit fb60c41aaaf7681ec85620b5fe42daf22c174f63 Author: Super User Date: Sun Jul 20 09:58:36 2025 +0700 init main diff --git a/.gitea/workflows/update.yml b/.gitea/workflows/update.yml new file mode 100644 index 0000000..cdfdb11 --- /dev/null +++ b/.gitea/workflows/update.yml @@ -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" \ No newline at end of file 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/group_vars/all.yml b/group_vars/all.yml new file mode 100644 index 0000000..09ab348 --- /dev/null +++ b/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/host_vars/prodesk.yml b/host_vars/prodesk.yml new file mode 100644 index 0000000..e29f6e3 --- /dev/null +++ b/host_vars/prodesk.yml @@ -0,0 +1,2 @@ + +go_version: "1.24.5" diff --git a/hosts.yml b/hosts.yml new file mode 100644 index 0000000..81a47c2 --- /dev/null +++ b/hosts.yml @@ -0,0 +1,4 @@ +all: + hosts: + prodesk: + ansible_host: 10.10.1.10 \ No newline at end of file diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..19bf9e7 --- /dev/null +++ b/playbook.yml @@ -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