new version
Some checks failed
Ansible Minecraft CI/CD / Ansible Lint (push) Successful in 8s
Ansible Minecraft CI/CD / Syntax Check (push) Failing after 7s
Ansible Minecraft CI/CD / Deploy to Staging (push) Has been skipped
Ansible Minecraft CI/CD / Deploy to Production (push) Has been skipped

This commit is contained in:
2025-08-27 15:11:08 +02:00
parent 3e64946953
commit 8f0877cd53
105 changed files with 911 additions and 2540 deletions

View File

@@ -1,21 +1,9 @@
---
- name: Check for new SSH keys in repository
ansible.builtin.set_fact:
ssh_keys_to_add: "{{ admin_ssh_keys | default([]) }}"
- name: Get current authorized keys
ansible.builtin.slurp:
src: /home/ansible/.ssh/authorized_keys
register: current_keys
ignore_errors: yes
- name: Add new SSH keys if found
- name: Vérification des nouvelles clés SSH
ansible.posix.authorized_key:
user: ansible
user: "{{ item.user }}"
state: present
key: "{{ item.key }}"
comment: "{{ item.name }}"
loop: "{{ ssh_keys_to_add }}"
when:
- ssh_keys_to_add | length > 0
- item.key not in (current_keys.content | b64decode | default(''))
comment: "{{ item.comment | default('Admin key') }}"
with_items: "{{ admin_ssh_keys | default([]) }}"
when: admin_ssh_keys is defined

View File

@@ -1,26 +1,23 @@
---
- name: Update apt cache
- name: Vérification des mises à jour système disponibles
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
when: ansible_os_family == "Debian"
- name: Check for available updates
ansible.builtin.command: apt list --upgradable
register: apt_updates
changed_when: false
- name: Liste des paquets à mettre à jour
ansible.builtin.apt:
upgrade: dist
dry_run: yes
register: system_updates_check
when: ansible_os_family == "Debian"
- name: Display available updates
ansible.builtin.debug:
msg: "Available updates: {{ apt_updates.stdout_lines | length - 1 }} packages"
when: apt_updates is defined
- name: Perform system update if requested
- name: Application des mises à jour système si nécessaire
ansible.builtin.apt:
upgrade: safe
upgrade: dist
autoremove: yes
autoclean: yes
when:
- ansible_os_family == "Debian"
- perform_system_update | default(false)
- update_system_packages | default(false)
- system_updates_check.changed

View File

@@ -1,30 +1,22 @@
---
- name: Get current Spigot version
- name: Lecture de la version actuelle
ansible.builtin.slurp:
src: "{{ current_version_file }}"
register: current_version
ignore_errors: yes
register: current_version_content
failed_when: false
- name: Set current version fact
ansible.builtin.set_fact:
current_spigot_version: "{{ (current_version.content | b64decode).strip() if current_version is succeeded else 'unknown' }}"
- name: Définition de la version actuelle
set_fact:
current_spigot_version: "{{ (current_version_content.content | b64decode).strip() if current_version_content.content is defined else 'unknown' }}"
- name: Check latest Spigot version
- name: Vérification de la dernière version Spigot disponible
ansible.builtin.uri:
url: "https://hub.spigotmc.org/versions/{{ minecraft_version }}.json"
url: "{{ spigot_update_check_url }}{{ minecraft_version }}.json"
method: GET
return_content: yes
register: latest_version_info
ignore_errors: yes
register: spigot_version_check
failed_when: false
- name: Compare versions
ansible.builtin.set_fact:
spigot_needs_update: "{{ current_spigot_version != minecraft_version }}"
when: latest_version_info is succeeded
- name: Display version status
ansible.builtin.debug:
msg:
- "Current version: {{ current_spigot_version }}"
- "Target version: {{ minecraft_version }}"
- "Update needed: {{ spigot_needs_update | default(false) }}"
- name: Détermination si une mise à jour est disponible
set_fact:
spigot_update_available: "{{ minecraft_version != current_spigot_version }}"

View File

@@ -0,0 +1,16 @@
---
- name: Création du répertoire de build temporaire
ansible.builtin.file:
path: "{{ temp_build_dir }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Téléchargement de BuildTools pour la nouvelle version
ansible.builtin.get_url:
url: "{{ spigot_build_tools_url }}"
dest: "{{ temp_build_dir }}/BuildTools.jar"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'

View File

@@ -1,22 +0,0 @@
---
- name: Create update directory
ansible.builtin.file:
path: "{{ spigot_update_dir }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Download latest BuildTools
ansible.builtin.get_url:
url: "{{ minecraft_build_tools_url }}"
dest: "{{ spigot_update_dir }}/BuildTools.jar"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'
force: yes
- name: Clean update directory
ansible.builtin.file:
path: "{{ spigot_update_dir }}/work"
state: absent

View File

@@ -0,0 +1,13 @@
---
- name: Compilation de la nouvelle version Spigot
ansible.builtin.command:
cmd: "java -jar BuildTools.jar --rev {{ minecraft_version }}"
chdir: "{{ temp_build_dir }}"
creates: "{{ temp_build_dir }}/spigot-{{ minecraft_version }}.jar"
become_user: "{{ minecraft_user }}"
timeout: 1800
register: spigot_compile_result
- name: Marquage du succès de compilation
set_fact:
spigot_compilation_success: "{{ spigot_compile_result.rc == 0 }}"

View File

@@ -1,25 +0,0 @@
---
- name: Compile new Spigot version
ansible.builtin.command:
cmd: "java -jar BuildTools.jar --rev {{ minecraft_version }}"
chdir: "{{ spigot_update_dir }}"
become_user: "{{ minecraft_user }}"
register: compile_result
- name: Verify compilation success
ansible.builtin.stat:
path: "{{ spigot_update_dir }}/spigot-{{ minecraft_version }}.jar"
register: new_jar
- name: Set update ready flag
ansible.builtin.set_fact:
spigot_update_ready: "{{ new_jar.stat.exists }}"
- name: Create staging directory
ansible.builtin.file:
path: "{{ update_staging_dir }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
when: spigot_update_ready

View File

@@ -1,27 +0,0 @@
---
- name: Copy new jar to staging
ansible.builtin.copy:
src: "{{ spigot_update_dir }}/spigot-{{ minecraft_version }}.jar"
dest: "{{ update_staging_dir }}/spigot-{{ minecraft_version }}.jar"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'
remote_src: yes
- name: Copy current configuration to staging
ansible.builtin.synchronize:
src: "{{ minecraft_server_dir }}/"
dest: "{{ update_staging_dir }}/"
rsync_opts:
- "--exclude=*.jar"
- "--exclude=world*"
- "--exclude=logs"
- "--exclude=crash-reports"
delegate_to: "{{ inventory_hostname }}"
- name: Update jar reference in staging
ansible.builtin.replace:
path: "{{ update_staging_dir }}/start.sh"
regexp: 'spigot-.*\.jar'
replace: 'spigot-{{ minecraft_version }}.jar'
when: spigot_update_ready

View File

@@ -0,0 +1,31 @@
---
- name: Sauvegarde avant mise à jour
ansible.builtin.command:
cmd: "{{ backup_script_path }}/minecraft-backup-daily.sh"
when: update_backup_before | default(true)
- name: Génération du script de changement de version
ansible.builtin.template:
src: version-switch.sh.j2
dest: "{{ update_script_path }}/minecraft-version-switch.sh"
owner: root
group: root
mode: '0755'
- name: Exécution du changement de version
ansible.builtin.command:
cmd: "{{ update_script_path }}/minecraft-version-switch.sh {{ minecraft_version }}"
notify: restart minecraft
- name: Mise à jour du fichier de version
ansible.builtin.copy:
content: "{{ minecraft_version }}"
dest: "{{ current_version_file }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'
- name: Nettoyage du répertoire temporaire
ansible.builtin.file:
path: "{{ temp_build_dir }}"
state: absent

View File

@@ -1,49 +0,0 @@
---
- name: Create version switch script
ansible.builtin.template:
src: version-switch.sh.j2
dest: "{{ minecraft_base_dir }}/switch_version.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Stop Minecraft server
ansible.builtin.systemd:
name: minecraft
state: stopped
- name: Backup current version
ansible.builtin.command:
cmd: |
tar -czf {{ spigot_previous_dir }}/backup_$(date +%Y%m%d_%H%M%S).tar.gz \
-C {{ minecraft_server_dir }} .
become_user: "{{ minecraft_user }}"
- name: Switch to new version
ansible.builtin.command:
cmd: "{{ minecraft_base_dir }}/switch_version.sh"
become_user: "{{ minecraft_user }}"
register: switch_result
- name: Update version file
ansible.builtin.copy:
content: "{{ minecraft_version }}"
dest: "{{ current_version_file }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'
- name: Start Minecraft server with new version
ansible.builtin.systemd:
name: minecraft
state: started
- name: Verify server is running
ansible.builtin.wait_for:
port: "{{ server_port }}"
timeout: 60
state: started
- name: Display update result
ansible.builtin.debug:
msg: "Successfully updated to Spigot {{ minecraft_version }}"

View File

@@ -1,28 +1,23 @@
---
- name: Include check SSH keys tasks
ansible.builtin.include_tasks: 01-check-ssh-keys.yml
when: update_check_ssh_keys
# Tâches principales mises à jour
- import_tasks: 01-check-ssh-keys.yml
tags: [update, ssh-keys]
- name: Include check system updates tasks
ansible.builtin.include_tasks: 02-check-system-updates.yml
when: update_check_system
- import_tasks: 02-check-system-updates.yml
tags: [update, system]
when: update_system_packages | default(false)
- name: Include check Spigot version tasks
ansible.builtin.include_tasks: 03-check-spigot-version.yml
when: update_check_spigot
- import_tasks: 03-check-spigot-version.yml
tags: [update, spigot-version]
- name: Include download new version tasks
ansible.builtin.include_tasks: 04-download-new-version.yml
when: spigot_needs_update | default(false)
- import_tasks: 04-download-new-spigot.yml
tags: [update, spigot-download]
when: spigot_update_available | default(false)
- name: Include compile new version tasks
ansible.builtin.include_tasks: 05-compile-new-version.yml
when: spigot_needs_update | default(false)
- import_tasks: 05-compile-new-spigot.yml
tags: [update, spigot-compile]
when: spigot_update_available | default(false)
- name: Include configure new version tasks
ansible.builtin.include_tasks: 06-configure-new-version.yml
when: spigot_needs_update | default(false)
- name: Include switch versions tasks
ansible.builtin.include_tasks: 07-switch-versions.yml
when: spigot_update_ready | default(false)
- import_tasks: 06-switch-versions.yml
tags: [update, spigot-switch]
when: spigot_update_available | default(false) and spigot_compilation_success | default(false)