-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_minecraft.yaml
More file actions
67 lines (57 loc) · 1.68 KB
/
run_minecraft.yaml
File metadata and controls
67 lines (57 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
- name: Install Docker and Run Minecraft Server
hosts: launched
become: yes
tasks:
- name: Install required packages for Docker
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
state: present
update_cache: yes
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu bionic stable
state: present
- name: Install Docker
apt:
name: docker-ce
state: present
- name: Start Docker service
systemd:
name: docker
state: started
enabled: yes
- name: Create systemd service file for Minecraft Docker container
copy:
content: |
[Unit]
Description=Minecraft Server Container
After=docker.service
Requires=docker.service
[Service]
Restart=always
ExecStartPre=/usr/bin/docker pull itzg/minecraft-server
ExecStart=/usr/bin/docker run --rm --name minecraft -p 25565:25565 -e EULA=TRUE itzg/minecraft-server
ExecStop=/usr/bin/docker stop minecraft
[Install]
WantedBy=multi-user.target
dest: /etc/systemd/system/minecraft.service
owner: root
group: root
mode: '0644'
- name: Reload systemd to apply the new service
systemd:
daemon_reload: yes
- name: Enable and start the Minecraft service
systemd:
name: minecraft
state: started
enabled: yes