aboutsummaryrefslogblamecommitdiffstats
path: root/roles/factorio/tasks/main.yml
blob: 548d7def2ff29cdfb3e13db53a7ce316e5004e41 (plain) (tree)


























                                           
                             





                                              





                                             



                                             


                                 

                            

                       


                                









                                                        
                                                                            

                               

                                    





                                                 
                                                                                              


                                                       

# factorio ~~ roles/factorio/tasks/main.yml
# factorio gameserver

---

- name: create factorio group
  group:
    name: "{{ factorio_group }}"
    state: present

- name: create factorio user
  user:
    name: "{{ factorio_user }}"
    group: "{{ factorio_group }}"
    state: present

- name: create factorio directory
  file:
    path: "{{ factorio_dir }}"
    owner: "{{ factorio_user }}"
    group: "{{ factorio_group }}"
    state: directory
    mode: 0700

- name: download latest factorio server
  get_url:
    url: "{{ factorio_url }}"
    dest: "{{ factorio_dir }}/factorio.tar.gz"
    owner: "{{ factorio_user }}"
    group: "{{ factorio_group }}"
    mode: 0600
  register: archive

- name: ensure GNU tar is present for busybox
  package:
    name: tar
    state: present
  when: ansible_distribution == "Alpine"

- name: untar factorio server
  unarchive:
    src: "{{ factorio_dir }}/factorio.tar.gz"
    dest: "{{ factorio_dir }}"
    owner: "{{ factorio_user }}"
    group: "{{ factorio_group }}"
    remote_src: true
    extra_opts:
      - --strip-components=1
  when: archive.changed

- name: generate server setting
  template:
    src: server-settings.json.j2
    dest: "{{ factorio_dir }}/data/server-settings.json"
    owner: "{{ factorio_user }}"
    group: "{{ factorio_group }}"
    mode: 0600

- name: ensure default world does not exist
  stat: path="{{ factorio_dir }}/{{ factorio_world }}"
  register: world

- name: create default world
  shell: "{{ factorio_dir }}/bin/x64/factorio --create {{ factorio_world }}"
  args:
    chdir: "{{ factorio_dir }}"
  become: true
  become_user: "{{ factorio_user }}"
  when: world.stat.islnk is not defined

- name: enable and start rc script
  include_role: name=rc
  vars:
    rc_cmd: "{{ factorio_dir }}/bin/x64/factorio"
    rc_args: "--server-settings data/server-settings.json --start-server {{ factorio_world }}"
    rc_user: "{{ factorio_user }}:{{ factorio_group }}"
    rc_dir: "{{ factorio_dir }}"
    rc_name: factorio
remember that computers suck.