check new version
Some checks failed
Ansible Minecraft Server CI/CD / lint (push) Failing after 21s
Ansible Minecraft Server CI/CD / test (push) Has been skipped
Ansible Minecraft Server CI/CD / deploy (push) Has been skipped

This commit is contained in:
2025-08-27 07:59:19 +02:00
parent 7a2ccb537b
commit 9ea9ac7254
125 changed files with 2696 additions and 1511 deletions

View File

@@ -0,0 +1,21 @@
---
- 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
ansible.posix.authorized_key:
user: ansible
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(''))

View File

@@ -1,16 +0,0 @@
---
- name: Check for new SSH keys to add
ansible.posix.authorized_key:
user: ansible
key: "{{ item.key }}"
comment: "{{ item.comment | default('') }}"
state: present
loop: "{{ admin_users }}"
when: admin_users is defined and admin_users | length > 0
notify: "reload ssh service"
register: ssh_keys_result
- name: Log SSH keys update
ansible.builtin.debug:
msg: "SSH keys updated for {{ ssh_keys_result.results | selectattr('changed', 'equalto', true) | list | length }} users"
when: ssh_keys_result is defined

View File

@@ -1,41 +1,26 @@
---
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
update_cache: yes
cache_valid_time: 3600
when: ansible_os_family == "Debian"
- name: Check for available system updates
ansible.builtin.shell: |
apt list --upgradable 2>/dev/null | grep -v "Listing..." | wc -l
register: available_updates_count
- name: Check for available updates
ansible.builtin.command: apt list --upgradable
register: apt_updates
changed_when: false
when: ansible_os_family == "Debian"
- name: Display available updates count
- name: Display available updates
ansible.builtin.debug:
msg: "{{ available_updates_count.stdout }} system updates available"
when: available_updates_count is defined
msg: "Available updates: {{ apt_updates.stdout_lines | length - 1 }} packages"
when: apt_updates is defined
- name: Apply system updates if auto-update enabled
- name: Perform system update if requested
ansible.builtin.apt:
upgrade: dist
autoremove: true
autoclean: true
upgrade: safe
autoremove: yes
autoclean: yes
when:
- system_update_auto | bool
- ansible_os_family == "Debian"
- available_updates_count.stdout | int > 0
register: system_update_result
- name: Check if reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_required_file
when: system_reboot_required_check | bool
- name: Warn about required reboot
ansible.builtin.debug:
msg: "ATTENTION: System reboot is required to complete updates"
when:
- reboot_required_file is defined
- reboot_required_file.stat.exists
- perform_system_update | default(false)

View File

@@ -1,27 +1,30 @@
---
- name: Check current Spigot version
- name: Get current Spigot version
ansible.builtin.slurp:
src: "{{ spigot_current_version_file }}"
register: current_version_file
failed_when: false
src: "{{ current_version_file }}"
register: current_version
ignore_errors: yes
- name: Set current version variable
- name: Set current version fact
ansible.builtin.set_fact:
current_spigot_version: "{{ (current_version_file.content | b64decode).strip() }}"
when: current_version_file.failed == false
current_spigot_version: "{{ (current_version.content | b64decode).strip() if current_version is succeeded else 'unknown' }}"
- name: Set default current version if file doesn't exist
- name: Check latest Spigot version
ansible.builtin.uri:
url: "https://hub.spigotmc.org/versions/{{ minecraft_version }}.json"
method: GET
return_content: yes
register: latest_version_info
ignore_errors: yes
- name: Compare versions
ansible.builtin.set_fact:
current_spigot_version: "unknown"
when: current_version_file.failed == true
spigot_needs_update: "{{ current_spigot_version != minecraft_version }}"
when: latest_version_info is succeeded
- name: Check if new version is available
ansible.builtin.set_fact:
spigot_update_available: "{{ minecraft_version != current_spigot_version }}"
- name: Display version information
- name: Display version status
ansible.builtin.debug:
msg:
- "Current Spigot version: {{ current_spigot_version }}"
- "Target Spigot version: {{ minecraft_version }}"
- "Update available: {{ spigot_update_available }}"
- "Current version: {{ current_spigot_version }}"
- "Target version: {{ minecraft_version }}"
- "Update needed: {{ spigot_needs_update | default(false) }}"

View File

@@ -1,18 +0,0 @@
---
- name: Create new version directory
ansible.builtin.file:
path: "{{ spigot_new_version_dir }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Download BuildTools for new version
ansible.builtin.get_url:
url: "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
dest: "{{ spigot_new_version_dir }}/BuildTools.jar"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'
timeout: 300
force: true

View File

@@ -0,0 +1,22 @@
---
- 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

@@ -1,17 +0,0 @@
---
- name: Compile new Spigot version
ansible.builtin.shell: |
cd {{ spigot_new_version_dir }}
java -jar BuildTools.jar --rev {{ minecraft_version }}
become_user: "{{ minecraft_user }}"
register: new_spigot_compilation
failed_when: new_spigot_compilation.rc != 0
timeout: 1800
- name: Set compilation success flag
ansible.builtin.set_fact:
spigot_compilation_successful: "{{ new_spigot_compilation.rc == 0 }}"
- name: Display compilation result
ansible.builtin.debug:
msg: "New Spigot compilation {{ 'successful' if spigot_compilation_successful else 'failed' }}"

View File

@@ -0,0 +1,25 @@
---
- 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 +1,27 @@
06-configure-new-version.yml
---
- 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

@@ -1,8 +1,8 @@
---
- name: Create version backup directory
ansible.builtin.file:
path: "{{ spigot_backup_dir }}"
state: directory
- 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'
@@ -13,39 +13,22 @@
state: stopped
- name: Backup current version
ansible.builtin.shell: |
BACKUP_NAME="version_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "{{ spigot_backup_dir }}/$BACKUP_NAME"
cp -r "{{ minecraft_server_dir }}"/* "{{ spigot_backup_dir }}/$BACKUP_NAME/"
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: Copy world data to new version
ansible.builtin.shell: |
if [ -d "{{ minecraft_server_dir }}/world" ]; then
cp -r "{{ minecraft_server_dir }}/world" "{{ spigot_new_version_dir }}/"
fi
if [ -d "{{ minecraft_server_dir }}/world_nether" ]; then
cp -r "{{ minecraft_server_dir }}/world_nether" "{{ spigot_new_version_dir }}/"
fi
if [ -d "{{ minecraft_server_dir }}/world_the_end" ]; then
cp -r "{{ minecraft_server_dir }}/world_the_end" "{{ spigot_new_version_dir }}/"
fi
if [ -d "{{ minecraft_server_dir }}/plugins" ]; then
cp -r "{{ minecraft_server_dir }}/plugins" "{{ spigot_new_version_dir }}/"
fi
become_user: "{{ minecraft_user }}"
- name: Replace server directory with new version
ansible.builtin.shell: |
rm -rf "{{ minecraft_server_dir }}.old"
mv "{{ minecraft_server_dir }}" "{{ minecraft_server_dir }}.old"
mv "{{ spigot_new_version_dir }}" "{{ minecraft_server_dir }}"
- 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: "{{ spigot_current_version_file }}"
dest: "{{ current_version_file }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0644'
@@ -54,30 +37,13 @@
ansible.builtin.systemd:
name: minecraft
state: started
notify: "restart minecraft after version change"
- name: Wait for server to start
- name: Verify server is running
ansible.builtin.wait_for:
port: "{{ minecraft_port }}"
delay: 30
timeout: 300
port: "{{ server_port }}"
timeout: 60
state: started
- name: Verify server is running new version
ansible.builtin.shell: |
sleep 10
/usr/local/bin/mcrcon -H 127.0.0.1 -P {{ rcon_port }} -p "{{ rcon_password }}" "version"
register: version_check
failed_when: false
- name: Display version switch result
- name: Display update result
ansible.builtin.debug:
msg:
- "Version switch completed successfully"
- "Server response: {{ version_check.stdout | default('No response') }}"
- "Old version backed up to: {{ minecraft_server_dir }}.old"
- name: Clean up old version after successful switch
ansible.builtin.file:
path: "{{ minecraft_server_dir }}.old"
state: absent
when: version_check.rc == 0
msg: "Successfully updated to Spigot {{ minecraft_version }}"

View File

@@ -1,46 +1,28 @@
---
- name: Include SSH keys update tasks
ansible.builtin.include_tasks: 01-update-ssh-keys.yml
when: update_check_ssh_keys | bool
- name: Include check SSH keys tasks
ansible.builtin.include_tasks: 01-check-ssh-keys.yml
when: update_check_ssh_keys
- name: Include system updates check tasks
- name: Include check system updates tasks
ansible.builtin.include_tasks: 02-check-system-updates.yml
when: update_check_system | bool
when: update_check_system
- name: Include Spigot version check tasks
- name: Include check Spigot version tasks
ansible.builtin.include_tasks: 03-check-spigot-version.yml
when: update_check_spigot | bool
when: update_check_spigot
- name: Include new Spigot download tasks
ansible.builtin.include_tasks: 04-download-new-spigot.yml
when:
- update_check_spigot | bool
- spigot_update_available is defined
- spigot_update_available | bool
- name: Include download new version tasks
ansible.builtin.include_tasks: 04-download-new-version.yml
when: spigot_needs_update | default(false)
- name: Include new Spigot compilation tasks
ansible.builtin.include_tasks: 05-compile-new-spigot.yml
when:
- update_check_spigot | bool
- spigot_update_available is defined
- spigot_update_available | bool
- name: Include compile new version tasks
ansible.builtin.include_tasks: 05-compile-new-version.yml
when: spigot_needs_update | default(false)
- name: Include new version configuration tasks
- name: Include configure new version tasks
ansible.builtin.include_tasks: 06-configure-new-version.yml
when:
- update_check_spigot | bool
- spigot_update_available is defined
- spigot_update_available | bool
- spigot_compilation_successful is defined
- spigot_compilation_successful | bool
when: spigot_needs_update | default(false)
- name: Include version switching tasks
- name: Include switch versions tasks
ansible.builtin.include_tasks: 07-switch-versions.yml
when:
- update_check_spigot | bool
- spigot_update_available is defined
- spigot_update_available | bool
- spigot_compilation_successful is defined
- spigot_compilation_successful | bool
- spigot_configuration_successful is defined
- spigot_configuration_successful | bool
when: spigot_update_ready | default(false)