diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2022-04-06 11:54:21 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2022-04-06 11:54:21 +0200 |
commit | 736ffc77f09a8e238e63a9819d19fe41e7c523d4 (patch) | |
tree | c4c3d4e36865c0ef63f33af71a2edf2857e0312b /roles | |
parent | e835ea003eb91a534bfcead68062562e6ed1e665 (diff) | |
download | ansible_collection-736ffc77f09a8e238e63a9819d19fe41e7c523d4.tar.gz |
factorio
Diffstat (limited to 'roles')
-rw-r--r-- | roles/factorio/defaults/main.yml | 195 | ||||
-rw-r--r-- | roles/factorio/files/factorio.service | 17 | ||||
-rw-r--r-- | roles/factorio/files/run.sh | 14 | ||||
-rw-r--r-- | roles/factorio/handlers/main.yml | 7 | ||||
-rw-r--r-- | roles/factorio/tasks/main.yml | 96 | ||||
-rw-r--r-- | roles/factorio/tasks/update.yml | 23 |
6 files changed, 352 insertions, 0 deletions
diff --git a/roles/factorio/defaults/main.yml b/roles/factorio/defaults/main.yml new file mode 100644 index 0000000..e14eafc --- /dev/null +++ b/roles/factorio/defaults/main.yml @@ -0,0 +1,195 @@ +--- +# Only use to pin to specific version +# factorio_version: '' +factorio_save: 'gamesave' + +factorio_admins: [] + +# Server configuration. consult the example json files for reference +factorio_config: + mapgen: + terrain_segmentation: 1 + water: 1 + width: 0 + height: 0 + starting_area: 1 + peaceful_mode: false + autoplace_controls: + coal: + frequency: 1 + size: 1 + richness: 1 + stone: + frequency: 1 + size: 1 + richness: 1 + copper-ore: + frequency: 1 + size: 1 + richness: 1 + iron-ore: + frequency: 1 + size: 1 + richness: 1 + uranium-ore: + frequency: 1 + size: 1 + richness: 1 + crude-oil: + frequency: 1 + size: 1 + richness: 1 + trees: + frequency: 1 + size: 1 + richness: 1 + enemy-base: + frequency: 1 + size: 1 + richness: 1 + cliff_settings: + name: cliff + cliff_elevation_0: 10 + cliff_elevation_interval: 40 + richness: 1 + property_expression_names: + control-setting:moisture:frequency:multiplier: '1' + control-setting:moisture:bias: '0' + control-setting:aux:frequency:multiplier: '1' + starting_points: + - x: 0 + y: 0 + seed: null + + map: + difficulty_settings: + recipe_difficulty: 0 + technology_difficulty: 0 + technology_price_multiplier: 1 + research_queue_setting: after-victory + pollution: + enabled: true + diffusion_ratio: 0.02 + min_to_diffuse: 15 + ageing: 1 + expected_max_per_chunk: 150 + min_to_show_per_chunk: 50 + min_pollution_to_damage_trees: 60 + pollution_with_max_forest_damage: 150 + pollution_per_tree_damage: 50 + pollution_restored_per_tree_damage: 10 + max_pollution_to_restore_trees: 20 + enemy_attack_pollution_consumption_modifier: 1 + enemy_evolution: + enabled: true + time_factor: 4.0e-06 + destroy_factor: 0.002 + pollution_factor: 9.0e-07 + enemy_expansion: + enabled: true + min_base_spacing: 3 + max_expansion_distance: 7 + friendly_base_influence_radius: 2 + enemy_building_influence_radius: 2 + building_coefficient: 0.1 + other_base_coefficient: 2 + neighbouring_chunk_coefficient: 0.5 + neighbouring_base_chunk_coefficient: 0.4 + max_colliding_tiles_coefficient: 0.9 + settler_group_min_size: 5 + settler_group_max_size: 20 + min_expansion_cooldown: 14400 + max_expansion_cooldown: 216000 + unit_group: + min_group_gathering_time: 3600 + max_group_gathering_time: 36000 + max_wait_time_for_late_members: 7200 + max_group_radius: 30 + min_group_radius: 5 + max_member_speedup_when_behind: 1.4 + max_member_slowdown_when_ahead: 0.6 + max_group_slowdown_factor: 0.3 + max_group_member_fallback_factor: 3 + member_disown_distance: 10 + tick_tolerance_when_member_arrives: 60 + max_gathering_unit_groups: 30 + max_unit_group_size: 200 + steering: + default: + radius: 1.2 + separation_force: 0.005 + separation_factor: 1.2 + force_unit_fuzzy_goto_behavior: false + moving: + radius: 3 + separation_force: 0.01 + separation_factor: 3 + force_unit_fuzzy_goto_behavior: false + path_finder: + fwd2bwd_ratio: 5 + goal_pressure_ratio: 2 + max_steps_worked_per_tick: 100 + max_work_done_per_tick: 8000 + use_path_cache: true + short_cache_size: 5 + long_cache_size: 25 + short_cache_min_cacheable_distance: 10 + short_cache_min_algo_steps_to_cache: 50 + long_cache_min_cacheable_distance: 30 + cache_max_connect_to_cache_steps_multiplier: 100 + cache_accept_path_start_distance_ratio: 0.2 + cache_accept_path_end_distance_ratio: 0.15 + negative_cache_accept_path_start_distance_ratio: 0.3 + negative_cache_accept_path_end_distance_ratio: 0.3 + cache_path_start_distance_rating_multiplier: 10 + cache_path_end_distance_rating_multiplier: 20 + stale_enemy_with_same_destination_collision_penalty: 30 + ignore_moving_enemy_collision_distance: 5 + enemy_with_different_destination_collision_penalty: 30 + general_entity_collision_penalty: 10 + general_entity_subsequent_collision_penalty: 3 + extended_collision_penalty: 3 + max_clients_to_accept_any_new_request: 10 + max_clients_to_accept_short_new_request: 100 + direct_distance_to_consider_short_request: 100 + short_request_max_steps: 1000 + short_request_ratio: 0.5 + min_steps_to_check_path_find_termination: 2000 + start_to_goal_cost_multiplier_to_terminate_path_find: 500 + overload_levels: + - 0 + - 100 + - 500 + overload_multipliers: + - 2 + - 3 + - 4 + negative_path_cache_delay_interval: 20 + max_failed_behavior_count: 3 + + server: + name: Factorio + description: Factorio local server + tags: [] + max_players: 0 + visibility: + public: false + lan: true + game_password: '' + require_user_verification: false + max_upload_in_kilobytes_per_second: 0 + max_upload_slots: 5 + minimum_latency_in_ticks: 0 + ignore_player_limit_for_returning_players: false + allow_commands: 'admins-only' + autosave_interval: 10 + autosave_slots: 5 + afk_autokick_interval: 0 + auto_pause: true + only_admins_can_pause_the_game: true + autosave_only_on_server: true + non_blocking_saving: false + minimum_segment_size: 25 + minimum_segment_size_peer_count: 20 + maximum_segment_size: 100 + maximum_segment_size_peer_count: 10 diff --git a/roles/factorio/files/factorio.service b/roles/factorio/files/factorio.service new file mode 100644 index 0000000..f7f53bb --- /dev/null +++ b/roles/factorio/files/factorio.service @@ -0,0 +1,17 @@ +# vi: ft=systemd +[Unit] +Description=Factorio dedicated server +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=factorio +Group=factorio +Restart=on-failure +RestartSec=30s +WorkingDirectory=/opt/factorio +ExecStart=/opt/factorio/run.sh + +[Install] +WantedBy=multi-user.target diff --git a/roles/factorio/files/run.sh b/roles/factorio/files/run.sh new file mode 100644 index 0000000..d5eeacc --- /dev/null +++ b/roles/factorio/files/run.sh @@ -0,0 +1,14 @@ +#!/bin/bash +trap '' TERM + +source cfg.sh || exit 1 + +mkdir -p ./saves + +if [ ! -f "./saves/$SAVEFILE.zip" ]; then + factorio/bin/x64/factorio --create "./saves/$SAVEFILE.zip" \ + --map-gen-settings ./mapgen-config.json \ + --map-settings ./map-config.json || exit 1 +fi + +factorio/bin/x64/factorio --start-server "./saves/$SAVEFILE.zip" --server-settings server-config.json diff --git a/roles/factorio/handlers/main.yml b/roles/factorio/handlers/main.yml new file mode 100644 index 0000000..9dc2690 --- /dev/null +++ b/roles/factorio/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: Handle systemd + systemd: + name: factorio.service + state: restarted + enabled: yes + become: yes 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 |