Skip to content

Instantly share code, notes, and snippets.

@goffinet
Forked from ErisDS/README.md
Last active September 14, 2017 17:08
Show Gist options
  • Save goffinet/5151e2e778b5a6cd3c8c030c64dbf2d3 to your computer and use it in GitHub Desktop.
Save goffinet/5151e2e778b5a6cd3c8c030c64dbf2d3 to your computer and use it in GitHub Desktop.
Ansible tips for Ghost-Cli TODO: make this a proper repo

This assumes that you have already installed:

  • mariadb/mysql (no example provided)
  • node v6 (see node-install.yml)
  • ghost-cli latest (see ghost-cli-install.yml)
  • nginx (see nginx-install-config.yml)

After that, running install-ghost.yml will:

  • create you a db user (ghost cli may take this over in future)
  • optionally create a record in CloudFlare, if you don't do this, point your domain at the server before running this
  • install ghost with full SSL, which will handle all nginx and letsencrypt setup
- name: Ghost CLI | Install "ghost-cli" node.js package globally.
npm:
name: ghost-cli
global: yes
- name: Ghost CLI | Create directory
file:
name: /var/www/ghost
owner: admin
group: admin
state: directory
---
- name: Install Ghost
hosts: ghost
remote_user: admin
gather_facts: false
become: true
tasks:
- name: MariaDB | Create ghost database
mysql_db:
name: ghost
state: present
# This assumes that the root password is set in /root/.my.cnf
# else add login_password: "{{ mysql_ghost_password }}"
# and pass the password in
- name: MariaDB | Create ghost MySQL user
mysql_user:
login_user: root
user: ghost
password: "{{ mysql_ghost_password }}"
host: "{{ item }}"
priv: ghost.*:ALL
state: present
with_items:
- 127.0.0.1
- ::1
- localhost
- name: CloudFlare | Register A record
cloudflare_dns:
zone: "{{ base_domain }}"
record: "{{ server_hostname }}"
state: present
type: A
value: "{{ inventory_hostname }}"
proxied: True
solo: True
account_email: "{{ cloudflare_account_email }}"
account_api_token: "{{ cloudflare_api_token }}"
register: record
when: register_cf_record
# Install Ghost without the interactive setup
- name: Ghost | Install Ghost
shell: ghost install --no-setup
args:
chdir: /var/www/ghost
# Setup Ghost - needs to not be interactive
- name: Ghost | Configure & Setup Ghost
shell: "ghost setup --url=https://{{ server_domain }} --db=mysql --dbhost=localhost --dbuser=ghost --dbpass={{ mysql_ghost_password }} --dbname=ghost --sslemail={{ ssl_email }} --start"
args:
chdir: /var/www/ghost
- name: Nginx | Install
apt:
name: nginx
state: present
update_cache: yes
# Allow SSH connections over ufw
- name: Nginx | Allow Nginx HTTPS in UFW
ufw:
rule: allow
name: 'Nginx Full'
- name: Nginx | Ensure default nginx virtual host is removed.
file:
path: /etc/nginx/sites-enabled/default
state: absent
notify: restart nginx
# Set client_max_body_size 50m; in nginx.conf
- name: Nginx | Set client_max_body_size
lineinfile:
path: /etc/nginx/nginx.conf
line: "\tclient_max_body_size 50m;"
regexp: "^\tclient_max_body_size"
insertafter: "\ttypes_hash_max_size 2048;"
notify: restart nginx
- stat:
path: /tmp/nodesource_setup.sh
register: script
- name: Download the nodesource setup script
get_url:
url: https://deb.nodesource.com/setup_6.x
dest: /tmp/nodesource_setup.sh
when: script.stat.exists == False
- name: Execute the nodesource install script
shell: bash nodesource_setup.sh
args:
chdir: /tmp
executable: /bin/bash
when: script.stat.exists == False
- name: Install dependencies
apt:
name: "{{ item }}"
state: latest
update_cache: yes
with_items:
- nodejs
- build-essential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment