86 lines
2.6 KiB
YAML
86 lines
2.6 KiB
YAML
|
---
|
||
|
- name: Setup Factorio
|
||
|
hosts: all
|
||
|
remote_user: root
|
||
|
|
||
|
tasks:
|
||
|
- name: check if factorio download exists on the server
|
||
|
stat:
|
||
|
path: "/opt/factorio-{{ factorio_version }}.tar.gz"
|
||
|
register: factorio_download
|
||
|
|
||
|
- name: "Download Factorio Version {{ factorio_version }}"
|
||
|
get_url:
|
||
|
url: "https://www.factorio.com/get-download/{{ factorio_version }}/headless/linux64"
|
||
|
dest: "/opt/factorio-{{ factorio_version }}.tar.gz"
|
||
|
mode: '0440'
|
||
|
when: factorio_download.stat.exists == False
|
||
|
|
||
|
- name: check if factorio exists on the server
|
||
|
stat:
|
||
|
path: "/opt/factorio"
|
||
|
register: factorio
|
||
|
|
||
|
- name: Extract Factorio
|
||
|
ansible.builtin.unarchive:
|
||
|
src: "/opt/factorio-{{ factorio_version }}.tar.gz"
|
||
|
dest: "/opt/"
|
||
|
remote_src: yes
|
||
|
when: factorio.stat.exists == False
|
||
|
|
||
|
- name: Upload factorio-mod-downloader to server
|
||
|
ansible.builtin.copy:
|
||
|
src: ./factorio-mod-downloader/mod-downloader.py
|
||
|
dest: /opt/mod-downloader.py
|
||
|
mode: '0644'
|
||
|
|
||
|
- name: Create the mod directory
|
||
|
ansible.builtin.file:
|
||
|
path: /opt/factorio/mods
|
||
|
state: directory
|
||
|
mode: '0755'
|
||
|
|
||
|
- name: Download Mod
|
||
|
ansible.builtin.shell: "python3 /opt/mod-downloader.py \"{{ item }}\" latest {{ factorio_username }} {{ factorio_password }}"
|
||
|
args:
|
||
|
chdir: /opt/factorio/mods/
|
||
|
loop: "{{ mods }}"
|
||
|
|
||
|
- name: Check if Map exists on server
|
||
|
stat:
|
||
|
path: "/opt/factorio/saves/my-save.zip"
|
||
|
register: map
|
||
|
|
||
|
- name: Template a file to /opt/factorio/map-gen-settings.json
|
||
|
ansible.builtin.template:
|
||
|
src: map-gen-settings.json.j2
|
||
|
dest: /opt/factorio/map-gen-settings.json
|
||
|
when: map.stat.exists == False
|
||
|
|
||
|
- name: Template a file to /opt/factorio/map-settings.json
|
||
|
ansible.builtin.template:
|
||
|
src: map-settings.json.j2
|
||
|
dest: /opt/factorio/map-settings.json
|
||
|
when: map.stat.exists == False
|
||
|
|
||
|
- name: Generate new Map
|
||
|
ansible.builtin.shell: "./bin/x64/factorio --create saves/my-save.zip --map-gen-settings map-gen-settings.json --map-settings map-settings.json"
|
||
|
args:
|
||
|
chdir: /opt/factorio/
|
||
|
when: map.stat.exists == False
|
||
|
|
||
|
- name: Template a file to /opt/factorio/server-settings.json
|
||
|
ansible.builtin.template:
|
||
|
src: server-settings.json.j2
|
||
|
dest: /opt/factorio/server-settings.json
|
||
|
|
||
|
- name: Template a file to /etc/systemd/system/factorio.service
|
||
|
ansible.builtin.template:
|
||
|
src: factorio.service.j2
|
||
|
dest: /etc/systemd/system/factorio.service
|
||
|
|
||
|
- name: Restart factorio
|
||
|
ansible.builtin.systemd:
|
||
|
state: restarted
|
||
|
daemon_reload: yes
|
||
|
name: factorio
|