Skip to content

Commit

Permalink
Accommodate deploy hook vars formatted as lists of includes (#815)
Browse files Browse the repository at this point in the history
* Use lists for hooks.
* Move deploy hook variables to defaults/.
* Add loop_control/loop_var to hooks.
  • Loading branch information
strarsis authored and fullyint committed Apr 5, 2017
1 parent bb52547 commit 7c159ff
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### HEAD
* Accommodate deploy hook vars formatted as lists of includes ([#815](https://github.com/roots/trellis/pull/815))
* Check Ansible version before Ansible validates task attributes ([#797](https://github.com/roots/trellis/pull/797))
* Add additional Nginx sites configurations support ([#793](https://github.com/roots/trellis/pull/793))
* Change `remote-user` role to `connection` role: tests host key, user ([#745](https://github.com/roots/trellis/pull/745))
Expand Down
4 changes: 0 additions & 4 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
remote_user: "{{ web_user }}"

vars:
deploy_build_before: "{{ playbook_dir }}/deploy-hooks/build-before.yml"
deploy_build_after: "{{ playbook_dir }}/roles/deploy/hooks/build-after.yml"
deploy_finalize_before: "{{ playbook_dir }}/roles/deploy/hooks/finalize-before.yml"
deploy_finalize_after: "{{ playbook_dir }}/roles/deploy/hooks/finalize-after.yml"
project: "{{ wordpress_sites[site] }}"
project_root: "{{ www_root }}/{{ site }}"
wordpress_env_defaults:
Expand Down
16 changes: 16 additions & 0 deletions roles/deploy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,19 @@ project_environment:
# The project_current_path is the symlink used for the latest or active deployment
# - default is 'current'
project_current_path: "{{ project.current_path | default('current') }}"


# Deploy hooks
# For list of hooks and explanation, see https://roots.io/trellis/docs/deploys/#hooks
deploy_build_before:
- "{{ playbook_dir }}/deploy-hooks/build-before.yml"

deploy_build_after:
- "{{ playbook_dir }}/roles/deploy/hooks/build-after.yml"
# - "{{ playbook_dir }}/deploy-hooks/sites/{{ site }}-build-after.yml"

deploy_finalize_before:
- "{{ playbook_dir }}/roles/deploy/hooks/finalize-before.yml"

deploy_finalize_after:
- "{{ playbook_dir }}/roles/deploy/hooks/finalize-after.yml"
10 changes: 8 additions & 2 deletions roles/deploy/tasks/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: "{{ deploy_build_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_build_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-build-before

- name: Copy project templates
Expand All @@ -20,5 +23,8 @@
with_items: "{{ project_folder_paths.results }}"
when: item.stat.exists

- include: "{{ deploy_build_after | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_build_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-build-after
10 changes: 8 additions & 2 deletions roles/deploy/tasks/finalize.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: "{{ deploy_finalize_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_finalize_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-finalize-before

- name: Finalize the deploy
Expand All @@ -9,7 +12,10 @@
release: "{{ deploy_helper.new_release }}"
state: finalize

- include: "{{ deploy_finalize_after | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_finalize_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-finalize-after

- debug:
Expand Down
10 changes: 8 additions & 2 deletions roles/deploy/tasks/initialize.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: "{{ deploy_initialize_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_initialize_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-initialize-before

- name: Initialize
Expand All @@ -8,5 +11,8 @@
path: "{{ project_root }}"
state: present

- include: "{{ deploy_initialize_after | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_initialize_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-initialize-after
12 changes: 10 additions & 2 deletions roles/deploy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
---
- include: "{{ deploy_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-before

- include: initialize.yml
- include: update.yml
- include: prepare.yml
- include: build.yml
- include: share.yml
- include: finalize.yml
- include: "{{ deploy_after | default('../hooks/example.yml') }}"

- include: "{{ include_path }}"
with_items: "{{ deploy_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-after
10 changes: 8 additions & 2 deletions roles/deploy/tasks/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: "{{ deploy_prepare_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_prepare_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-prepare-before

- name: write unfinished file
Expand Down Expand Up @@ -35,5 +38,8 @@
chdir: "{{ project_source_path }}"
when: project.repo_subtree_path is defined

- include: "{{ deploy_prepare_after | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_prepare_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-prepare-after
10 changes: 8 additions & 2 deletions roles/deploy/tasks/share.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: "{{ deploy_share_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_share_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-share-before

- name: Ensure shared sources are present -- directories
Expand Down Expand Up @@ -45,5 +48,8 @@
state: link
with_items: "{{ project_shared_children }}"

- include: "{{ deploy_share_after | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_share_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-share-after
10 changes: 8 additions & 2 deletions roles/deploy/tasks/update.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: "{{ deploy_update_before | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_update_before | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-update-before

- name: Add known_hosts
Expand Down Expand Up @@ -48,5 +51,8 @@
> https://roots.io/trellis/docs/ssh-keys/#cloning-remote-repo-using-ssh-agent-forwarding
when: git_clone | failed

- include: "{{ deploy_update_after | default('../hooks/example.yml') }}"
- include: "{{ include_path }}"
with_items: "{{ deploy_update_after | default([]) }}"
loop_control:
loop_var: include_path
tags: deploy-update-after

0 comments on commit 7c159ff

Please sign in to comment.