Skip to content

Instantly share code, notes, and snippets.

@rdhyee
Last active June 9, 2020 03:44
Show Gist options
  • Save rdhyee/7047660 to your computer and use it in GitHub Desktop.
Save rdhyee/7047660 to your computer and use it in GitHub Desktop.
Ansible playbook to launch a digitalocean droplet and then configure it to run Minecraft based on instructions from https://www.digitalocean.com/community/articles/how-to-set-up-a-minecraft-server-on-linux Note that some things are hardwired: the name of the droplet, the version of minecraft
# http://www.ansibleworks.com/docs/modules.html#digital-ocean
# Create a new Droplet
# Will return the droplet details including the droplet id (used for idempotence)
- name: launch DO droplet
hosts: local
gather_facts: False
tasks:
- name: pwd
local_action: command pwd
- name: spin up DO droplet
local_action:
module: digital_ocean
state=present
command=droplet
name=minecraft1
client_id={{ansible_client_id}}
api_key={{ansible_api_key}}
ssh_key_ids={{ssh_key_id}}
size_id={{size_id}}
region_id={{region_id}}
image_id={{image_id}}
wait_timeout=500
register: my_droplet
- name: print info about my_droplet
local_action:
module: debug
msg="ID is {{ my_droplet.droplet.id }} IP is {{ my_droplet.droplet.ip_address }}"
- name: Add new droplet to host group
local_action: add_host hostname={{ my_droplet.droplet.ip_address }} groupname=launched
- name: Wait for SSH to come up
local_action: wait_for host={{ my_droplet.droplet.ip_address }} port=22 delay=60 timeout=320 state=started
- name: Configure droplet for minecraft
hosts: launched
gather_facts: True
tasks:
- name: apply apt-get update --fix-missing
command: apt-get update --fix-missing
sudo: yes
- name: install java
apt: pkg=default-jdk
sudo: yes
- name: install screen
apt: pkg=screen
sudo: yes
- name: make the minecraft directory
file: state=directory path=/root/minecraft
- name: download minecraft (1.6.4)
command: wget https://s3.amazonaws.com/Minecraft.Download/versions/1.6.4/minecraft_server.1.6.4.jar chdir=/root/minecraft creates=/root/minecraft/minecraft_server.1.6.4.jar
sudo: yes
- name: run minecraft
command: screen -S minecraft -d -m java -Xmx512M -Xms512M -jar /root/minecraft/minecraft_server.1.6.4.jar
sudo: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment