Skip to content

Commit

Permalink
Refactor hosts files
Browse files Browse the repository at this point in the history
  • Loading branch information
fullyint committed Dec 28, 2015
1 parent 270f793 commit 40cdb5e
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### HEAD
* Refactor hosts files ([#313](https://github.com/roots/trellis/pull/313))
* Fixes #436 - Let WP handle 404s for PHP files ([#448](https://github.com/roots/trellis/pull/448))
* Fixes #297 - Use `php_flag` vs `php_admin_flag` ([#447](https://github.com/roots/trellis/pull/447))
* Fixes #316 - Set WP permalink structure during install ([#316](https://github.com/roots/trellis/pull/316))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ For remote servers, you'll need to have a base Ubuntu 14.04 server already creat
2. Add your server IP/hostnames to `hosts/<environment>`.
3. Specify public SSH keys for `users` in `group_vars/all/users.yml`. See the [SSH Keys docs](https://roots.io/trellis/docs/ssh-keys/).
4. Consider setting `sshd_permit_root_login: false` in `group_vars/all/security.yml`. See the [Security docs](https://roots.io/trellis/docs/security/).
5. Run `ansible-playbook -i hosts/<environment> server.yml`.
5. Run `ansible-playbook server.yml -e env=<environment>`

## Deploying to remote servers

Expand All @@ -84,7 +84,7 @@ Full documentation: https://roots.io/trellis/docs/deploys/
1. Add the `repo` (Git URL) of your Bedrock WordPress project in the corresponding `group_vars/<environment>/wordpress_sites.yml` file.
2. Set the `branch` you want to deploy (optional - defaults to `master`).
3. Run `./deploy.sh <environment> <site name>`
4. To rollback a deploy, run `ansible-playbook -i hosts/<environment> rollback.yml --extra-vars="site=<site name>"`
4. To rollback a deploy, run `ansible-playbook rollback.yml -e "site=<site name> env=<environment>"`

## Configuration

Expand Down
1 change: 1 addition & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[defaults]
roles_path = vendor/roles
force_handlers = True
inventory = hosts

[ssh_connection]
ssh_args = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
shopt -s nullglob

DEPLOY_CMD="ansible-playbook -i hosts/$1 deploy.yml --extra-vars="site=$2""
DEPLOY_CMD="ansible-playbook deploy.yml -e env=$1 -e site=$2"
ENVIRONMENTS=( hosts/* )
ENVIRONMENTS=( "${ENVIRONMENTS[@]##*/}" )
NUM_ARGS=2
Expand Down
6 changes: 5 additions & 1 deletion deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
- include: variable-check.yml
vars:
playbook: deploy.yml

- name: Deploy WP site
hosts: web
hosts: web:&{{ env }}
remote_user: "{{ web_user }}"

vars:
Expand Down
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: "WordPress Server: Install LEMP Stack with PHP 5.6 and MariaDB MySQL"
hosts: web
hosts: web:&development
sudo: yes
remote_user: vagrant

Expand Down
9 changes: 5 additions & 4 deletions hosts/development
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Not used. Vagrant generates its own hosts file automatically and uses it
[web]
# No edits are necessary

[development]
127.0.0.1

[development:children]
web
[web]
127.0.0.1
11 changes: 7 additions & 4 deletions hosts/production
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[web]
192.168.50.5
# Add each host to the [production] group and to a "type" group such as [web] or [db].
# List each machine only once per [group], even if it will host multiple sites.

[production]
your_server_ip

[production:children]
web
[web]
your_server_ip
11 changes: 7 additions & 4 deletions hosts/staging
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[web]
192.168.50.5
# Add each host to the [staging] group and to a "type" group such as [web] or [db].
# List each machine only once per [group], even if it will host multiple sites.

[staging]
your_server_ip

[staging:children]
web
[web]
your_server_ip
6 changes: 5 additions & 1 deletion rollback.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
- include: variable-check.yml
vars:
playbook: rollback.yml

- name: Rollback a Deploy
hosts: web
hosts: web:&{{ env }}
remote_user: "{{ web_user }}"

vars:
Expand Down
8 changes: 6 additions & 2 deletions server.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
---
- include: variable-check.yml
vars:
playbook: server.yml

- name: Determine Remote User
hosts: web
hosts: web:&{{ env }}
gather_facts: false
roles:
- { role: remote-user, tags: [remote-user, always] }

- name: WordPress Server - Install LEMP Stack with PHP 5.6 and MariaDB MySQL
hosts: web
hosts: web:&{{ env }}
sudo: yes
vars_files:
- vars/sudoer_passwords.yml
Expand Down
13 changes: 13 additions & 0 deletions variable-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Ensure necessary variables are defined
hosts: localhost
gather_facts: false
vars:
extra_vars_command: "{{ (playbook == 'server.yml') | ternary('env=<environment>', '\"site=<domain> env=<environment>\"') }}"
tasks:
- name: Ensure environment is defined
fail:
msg: |
Environment missing. Use `-e` to define `env`:
ansible-playbook {{ playbook }} -e {{ extra_vars_command }}
when: env is not defined

0 comments on commit 40cdb5e

Please sign in to comment.