brahmlower / ansible-factorio

A role for creating Factorio servers
https://galaxy.ansible.com/bplower/factorio/
4 stars 6 forks source link

Factorio

Install from Ansible Galaxy Ansible Lint

A role for creating Factorio servers https://galaxy.ansible.com/bplower/factorio/

Requirements

No requirements

Role Variables

Variables can be roughly divided into two groups: deployment configurations and Factorio configurations.

Deployment Configurations

The deployment configurations are all related to the way in which ansible installs the factorio server. These should be abstracted enough to allow multiple factorio servers to be run simultaneously.

server_sources: "/opt/games/sources/factorio"
server_version: "0.17.79"
download_url: "https://www.factorio.com/get-download/{{ server_version }}/headless/linux64"
service_name: "factorio-server"
service_user: "factorio"
service_group: "factorio"
service_root: "/home/{{ service_user }}"
service_port: 34197
service_restart_permitted: true
factorio_default_save: "{{ service_root }}/factorio/saves/default-save.zip"
factorio_target_save: "{{ factorio_default_save }}"

More detailed information about these variables is as follows:

Factorio Configurations

Settings for various config files can be set in dictionaries loosely named after the file. Each dictionary starts with factorio_ followed by the filename (excluding the filetype extension) where hyphens ( - ) are replaced by underscores ( _ ). For example, the server-settings.json file is associated with the dictionary variable factorio_server_settings.

The default/ folder contains serveral files showing example dictionaries representing the values provided by the Factorio servers various examples JSON files.

The following is a list of config files that have been implemented:

Example Playbooks

An out of the box example might look as follows:

---
- name: Create a default factorio server
  hosts: localhost
  roles:
  - role: bplower.factorio

An example with a non-default port, and customized name:

---
- name: My slightly changed factorio server
  hosts: localhost
  roles:
  - role: bplower.factorio
    service_port: 12345
    factorio_server_settings:
      name: "My factorio server"

An example of multiple servers on a single host:

---
- name: Factorio farm
  hosts: localhost
  roles:
  - role: bplower.factorio
    service_port: 50001
    service_name: factorio_1
    service_root: /home/{{ service_user }}/{{ service_name }}
  - role: bplower.factorio
    service_port: 50002
    service_name: factorio_2
    service_root: /home/{{ service_user }}/{{ service_name }}

License

GNU GPLv3

Development & Contributions

I don't use this project regularly anymore, but I try to keep it up to date when possible. If you have any issues or questions about it, I encourage you to open a PR or issue.

Testing

This role uses yamllint for yaml validation, and molecule + docker for testing. Both tools can be installed using the dev-requirements.txt file. You will need to install docker separately.

pip install -r dev-requirements.txt`

Grouping all supported platforms together caused issues for CI, so the test are split into 3 scenarios based on the platforms being tested.

The makefile can be used to start each of the tests, and supports a helpmenu with descriptions for each target:

$ make help

Usage:
  make

Targets:
  help        Display this help
  lint        Lint yaml files
  test_all    Run all molecule tests
  test_centos  Run molecule centos tests
  test_debian  Run molecule debian tests
  test_ubuntu  Run molecule ubuntu tests