-
-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use lists for hooks #815
Use lists for hooks #815
Conversation
deploy.yml
Outdated
deploy_finalize_before: "{{ playbook_dir }}/roles/deploy/hooks/finalize-before.yml" | ||
deploy_finalize_after: "{{ playbook_dir }}/roles/deploy/hooks/finalize-after.yml" | ||
|
||
deploy_before: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need all these defaults set right? They already have | default([])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it useful to leave them commented out with comments from the documentation about when each hook is called?
roles/deploy/tasks/build.yml
Outdated
tags: deploy-build-after | ||
- include: "{{ item }}" | ||
with_items: "{{ deploy_build_after | default([]) }}" | ||
tags: deploy-build-after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add back the ending newline for these various files?
@swalkinshaw: The yet empty hooks are now shown as commented out examples. @fullyint: Learned something :) |
deploy.yml
Outdated
|
||
#deploy_after: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strarsis Your adjustments to these vars
in deploy.yml
were helpful in initiating internal discussion and the decision to move the deploy role's vars into roles/deploy/defaults/main.yml
. This will help deploy.yml
be more concise. It will be more consistent with how other roles have their vars in their respective defaults/main.yml
files.
Could you help us take the first step toward this goal in this PR by moving just the deploy hook vars out of deploy.yml
to a new section at the end of roles/deploy/defaults/main.yml
? I think you could start the section with a link to the deploy hooks docs, where all hooks are listed in sequence. Then I think it would be preferable to omit the unused/commented hook variables here in roles/deploy/defaults/main.yml
, unless there's a strong argument for duplication.
Example
# roles/deploy/defaults/main.yml
...
# 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"
Remove unused hook variable lines. Add hook related comments.
@fullyint: Done |
Looks great 🚀 |
Great work @strarsis. Thank you! My prior test was with the
As the warning suggests, it goes away after using a custom # roles/deploy/tasks/finalize.yml
- - include: "{{ item }}"
+ - include: "{{ include_path }}"
with_items: "{{ deploy_finalize_after | default([]) }}"
+ loop_control:
+ loop_var: include_path
tags: deploy-finalize-after Although there may be some setting to disable the warning, it looks like we should add the custom I created #817 to fix the new warning caused by using
|
@strarsis Thank you for all your work and patience making this great improvement to Trellis! |
per-site hooks aren't working as expected. in order to make it work you need to define hook for each and every website, otherwise it fails |
@pySilver Given that there are no per-site hooks by default, could you help me try to replicate the issue by posting the steps you've taken in setting up your per-site hook? Could you post your definition of the hook (example) and mention in which file you defined it? Also, post the filepath to the file you want included. Do the included tasks never run or do they show errors? If errors, could you post your tasks for review? |
@pySilver: From the related discussion on [...]
deploy_build_before:
- "{{ playbook_dir }}/deploy-hooks/build-before/{{ site }}.yml"
[...] So in this example, |
@fullyint @strarsis ok to simplify things I'll break down the issue to an example. Typically you might want a per-site hook for some websites. Let's say you have There is no way to handle this easily at the moment. deploy_build_before:
- "{{ playbook_dir }}/deploy-hooks/build-before.yml" # works for b.com
- "{{ playbook_dir }}/deploy-hooks/build-before/{{ site }}.yml" # works for a.com you need to create both hook files:
and one of them would be empty, since it's not required. If you omit any of them – your deployment playbook would fail once it will try to include non-existence yml. It would be much easier if we first check file presence before inclusion. I did handle it this way: - name: Validate build before hooks
local_action: "stat path={{ item }}"
register: deploy_build_before_hooks
with_items: "{{ deploy_build_before | default([]) }}"
tags: deploy-build-before
- include: "{{ item.item }}"
with_items: "{{ deploy_build_before_hooks.results | default([]) }}"
when: item.stat.exists
tags: deploy-build-before I imagine this could be accomplished to all hooks at once using some custom plugin.. which I had no time to create. |
@pySilver Thanks for the clear example. 👍 This raises the question of whether in this context we should override Ansible's default behavior of failing when a specified include file is missing. I tend to think the default behavior is worth keeping. I certainly understand the desire to only include files if they exist, particularly in this context. I wish there were such an option built-in as standard in Ansible (not requiring the extra Your approach above is very straightforward. Here are a few alternatives that would avoid modifying Trellis core files. These ideas build on the fact that Ansible's
Specify include in
|
This PR adds functionality that allows using lists for hooks, including the built-in Trellis hooks.