aboutsummaryrefslogtreecommitdiff
path: root/roles/factorio/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/factorio/tasks')
-rw-r--r--roles/factorio/tasks/main.yml96
-rw-r--r--roles/factorio/tasks/update.yml23
2 files changed, 119 insertions, 0 deletions
diff --git a/roles/factorio/tasks/main.yml b/roles/factorio/tasks/main.yml
new file mode 100644
index 0000000..da1b9fd
--- /dev/null
+++ b/roles/factorio/tasks/main.yml
@@ -0,0 +1,96 @@
+---
+- name: create user
+ user:
+ name: factorio
+ home: /opt/factorio
+ create_home: yes
+ shell: /bin/bash
+ state: present
+ become: yes
+
+- name: Get Version
+ uri:
+ url: https://factorio.com/api/latest-releases
+ method: GET
+ return_content: yes
+ delegate_to: localhost
+ register: factorio_api_latest
+ when: factorio_version is not defined
+
+- name: Set Version
+ set_fact:
+ factorio_version: '{{ (factorio_api_latest.content | from_json).stable.headless }}'
+ cachaeble: no
+ when: factorio_version is not defined
+
+- name: Install runscript
+ copy:
+ src: run.sh
+ dest: /opt/factorio/run.sh
+ mode: '750'
+ owner: factorio
+ group: factorio
+ become: yes
+ notify:
+ - Handle systemd
+
+- name: Install running config
+ copy:
+ content: |
+ SAVEFILE={{ factorio_save }}
+ dest: /opt/factorio/cfg.sh
+ owner: factorio
+ group: factorio
+ become: yes
+ notify:
+ - Handle systemd
+
+- name: Install JSON configs
+ copy:
+ content: '{{ factorio_config[item] | to_json }}'
+ dest: '/opt/factorio/{{ item }}-config.json'
+ owner: factorio
+ group: factorio
+ become: yes
+ notify:
+ - Handle systemd
+ loop:
+ - mapgen
+ - map
+ - server
+
+- name: Install admin file
+ copy:
+ content: '{{ factorio_admins | to_json }}'
+ dest: '/opt/factorio/factorio/server-adminlist.json'
+ owner: factorio
+ group: factorio
+ become: yes
+ notify:
+ - Handle systemd
+
+- name: systemd units
+ copy:
+ dest: '/etc/systemd/system/factorio.service'
+ src: factorio.service
+ become: yes
+ notify:
+ - Handle systemd
+
+- name: Determine factorio version
+ slurp:
+ src: /opt/factorio/factorio/data/base/info.json
+ register: factorio_current_version
+ ignore_errors: yes
+
+- name: assert version
+ assert:
+ that:
+ - not factorio_current_version.failed
+ - (factorio_current_version.content | b64decode | from_json).version is version( factorio_version, '>=')
+ ignore_errors: yes
+ register: version_check
+
+- name: Install new factorio version
+ include: update.yml
+ when: version_check.failed
diff --git a/roles/factorio/tasks/update.yml b/roles/factorio/tasks/update.yml
new file mode 100644
index 0000000..4f4c4d3
--- /dev/null
+++ b/roles/factorio/tasks/update.yml
@@ -0,0 +1,23 @@
+---
+- name: Stop factorio
+ systemd:
+ name: factorio.service
+ state: stopped
+ become: yes
+
+- name: Download factorio
+ get_url:
+ url: "https://factorio.com/get-download/stable/headless/linux64"
+ dest: /opt/factorio/factorio.tar.gz
+ become_user: factorio
+ become: yes
+
+- name: Unpack factorio
+ unarchive:
+ src: /opt/factorio/factorio.tar.gz
+ dest: /opt/factorio/
+ remote_src: yes
+ become_user: factorio
+ become: yes
+ notify:
+ - Handle systemd