Skip to content

Instantly share code, notes, and snippets.

@ErisDS
Last active May 12, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErisDS/1cc8e3bd65b648263cbf6cec27fef6dc to your computer and use it in GitHub Desktop.
Save ErisDS/1cc8e3bd65b648263cbf6cec27fef6dc to your computer and use it in GitHub Desktop.
Provision Ghost using the DO image & login to get the bash script to run
[defaults]
host_key_checking = False
- name: Provision new server
hosts: localhost
connection: local
gather_facts: false
vars:
ssh_key_ids: ["7690887"]
# Digital Ocean config
do_image: ghost-16-04
do_size: 1gb
do_region: ams3
tasks:
- name: Provision | Digital Ocean
digital_ocean:
state: present
command: droplet
name: "{{prefix}}-{{ server_hostname }}"
size_id: "{{ do_size }}"
region_id: "{{ do_region }}"
image_id: "{{ do_image }}"
unique_name: true
# We use the SSH key we loaded, and checked for presence in the last task
ssh_key_ids: "{{ ssh_key_ids }}"
wait: yes
wait_timeout: 600
register: server
- name: DO | Output the server IP
debug:
msg: "IP:{{ server.droplet.ip_address }}:END"
- name: DO | Output the server ID
debug:
msg: "ID:{{ server.droplet.id }}:END"
- name: DO | Tag server with rogue & trial
digital_ocean_tag:
name: "{{ item }}"
resource_id: "{{ server.droplet.id }}"
state: present
with_items:
- rogue
- trial
- name: Store | Add host to in-memory inventory
add_host:
hostname: "{{ server.droplet.ip_address }}"
groupname: "server"
- name: DO | Wait for droplet to listen on port 22
wait_for:
state: started
host: "{{ server.droplet.ip_address }}"
port: 22
- hosts: server
remote_user: root
gather_facts: false
tasks:
- name: cp /etc/skel/.bashrc /root
command: cp /etc/skel/.bashrc /root
- name: Remove default nginx config (rm -rf /etc/nginx/sites-enabled/default)
file:
path: /etc/nginx/sites-enabled/default
state: absent
- name: Link to new Ghost config (ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/default)
file:
src: /etc/nginx/sites-available/ghost
dest: /etc/nginx/sites-enabled/default
state: link
owner: root
group: root
- name: systemctl enable ghost
systemd:
name: ghost
enabled: yes
- name: systemctl restart ghost
systemd:
name: ghost
state: restarted
- name: systemctl restart nginx
systemd:
name: nginx
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment