-
-
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
Normalize apt
tasks
#881
Normalize apt
tasks
#881
Conversation
e254ec7
to
e57df9a
Compare
Thanks for this! I agree that for new servers, we essentially always want the latest version. However, always updating existing servers' packages to the latest version could be an unwanted surprise, particularly in the rare case that the updates break something (like this thread about php?). Ok, package updates rarely break things, but if playbooks occasionally update packages, users could develop general unease around the unpredictability of what may happen when they run Trellis playbooks. For instance, a user could modify one php param in How about making
It would get a little more complicated for
Then the related "Checking essentials" install task would use
Edit: Changing the various
|
Agree
Disagree. Main reason: We haven't taught developers to update with roots/Trellis (this repo).
Agree: Bumping Ansible requirement to v2.3 and fail if old old list format detected. |
e57df9a
to
c5c7727
Compare
8eb99f1
to
72e8a70
Compare
Normalize - name: Install XXX
apt:
name: XXX
state: "{{ XXX_package_state | default(apt_package_state) }}"
update_cache: yes
cache_valid_time: "{{ apt_cache_valid_time }}"
- name: Install XXX
apt:
name: "{{ item.key }}"
state: "{{ item.value }}"
update_cache: yes
cache_valid_time: "{{ apt_cache_valid_time }}"
with_dict: "{{ XXX_packages }}"
# varaiables
XXX_packages_default:
YYY: "{{ apt_package_state }}"
ZZZ: "{{ apt_package_state }}"
XXX_packages_custom: {}
XXX_packages: "{{ XXX_packages_default | combine(XXX_packages_custom) }}" Check whether
It doesn't change package versions, except:
Update: Also checks Question: When does a |
apt
tasks
Commenting on the PHP issue, is there a reason we use 7.1 instead of official 7? |
best I could find on it: https://forums.solydxk.com/viewtopic.php?t=6148. Still not exactly sure when we have to use it though. |
Looks good overall. My only question is if we should keep the memcached and SSH related packages as a list? Maybe we should just split them out into individual tasks. It's only two packages each. Not sure we need to have them with the treatment of default + custom. |
Imo replace memcached with redis and/or APCu.
|
default + custom for memcached and SSH related packagesThere is a actual use case for this: To do so, I have to run With this patch, we can:
|
Interesting benefit with this is we get granular statuses per package. Before:
After:
|
@tangrufus Thanks again for all your work on this! This PR adds to the I tried to produce a single task to verify the dict format of all the vars at once, but it wasn't as simple as I hoped. I think I see why you used a second separate task to validate vars like Just for brainstorming sake...
The example above checks a few more vars. Your validations checked the vars that were essential to check. My extra vars shouldn't need to be checked, but I've learned to never assume what users will and won't do. Still, maybe it's overkill to check all the vars I listed above. |
Correct! Move checking to Extra vars checks: Also good idea! Question: How to ensure |
Solution found: Run the checks twice. About that ugly fileglob with_items: ansible/ansible#23265 When required variable is undefined, error message is also ugly. Tried adding
|
If we want the two validation tasks I proposed in the The simplicity of two new
Given that all these vars are defined in role defaults, it seems very unlikely any of these vars would ever be undefined. Although users sometimes fail to update
I'm skeptical that we must be ready for undefined in this case, but here's an adjustment to the example tasks I posted (untested). # roles/common/tasks/main.yml
- name: Verify dict format for apt package component variables
fail:
- msg: "{{ package_vars_wrong_format_msg }}"
+ msg: |
+ The following variables must be formatted as dicts:
+ {{ package_vars_wrong_format | to_nice_yaml | indent(2) }}
+
+ See: https://github.com/roots/trellis/pull/881
when: package_vars_wrong_format | count
vars:
package_vars:
- apt_packages_default: "{{ apt_packages_default }}"
+ apt_packages_default: "{{ apt_packages_default | default({}) }}"
- apt_packages_custom: "{{ apt_packages_custom }}"
+ apt_packages_custom: "{{ apt_packages_custom | default({}) }}"
... (etc.)
package_vars_wrong_format: "[{% for k,v in package_vars.iteritems() if v | type_debug != 'dict' %}'{{ k }}',{% endfor %}]"
- name: Verify dict format for apt package combined variables
fail:
- msg: "{{ package_vars_wrong_format_msg }}"
+ msg: |
+ The following variables must be defined and formatted as dicts:
+ {{ package_vars_wrong_format | to_nice_yaml | indent(2) }}
+
+ See: https://github.com/roots/trellis/pull/881
when: package_vars_wrong_format | count
vars:
package_vars:
- apt_packages: "{{ apt_packages }}"
+ apt_packages: "{{ apt_packages | default({}) }}"
- memcached_packages: "{{ memcached_packages }}"
+ memcached_packages: "{{ memcached_packages | default({}) }}"
... (etc.)
- package_vars_wrong_format: "[{% for k,v in package_vars.iteritems() if v | type_debug != 'dict' %}'{{ k }}',{% endfor %}]"
+ package_vars_wrong_format: "[{% for k,v in package_vars.iteritems() if v | type_debug != 'dict' or vars[k] is not defined %}'{{ k }}',{% endfor %}]" |
@tangrufus I actually don't use Redis. I use wp-lcache. |
019f587
to
a1e8b23
Compare
|
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.
I'm good with this 👍
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.
This looks good to me, with a couple minor nits. 👍 from me if you've tested that this current iteration runs without error.
I think this PR should also add a CHANGELOG.md
entry prefixed by [BREAKING] <msg>
, given that this changes the format of some vars from list to dict.
roles/common/tasks/main.yml
Outdated
- name: Verify role requirements are fulfilled | ||
include_tasks: "{{ item }}" | ||
with_items: "{{ (playbook_dir + '/roles/*/tasks/validate.yml') | fileglob }}" | ||
|
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.
I think this include_tasks
is no longer needed, right? (there's no more validate.yml
)
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.
Removed
group_vars/all/main.yml
Outdated
The following variables must be formatted as dicts: | ||
{{ package_vars_wrong_format | to_nice_yaml | indent(2) }} | ||
|
||
See: https://github.com/roots/trellis/pull/881 |
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.
I'd prefer that this package_vars_wrong_format_msg
var were defined in roles/common/defaults/main.yml
, where users won't have to think about it unless they are really digging in. I think of this var as more of a helper/utility than a variable users are likely to want to modify. This change would keep group_vars/all/main.yml
more streamlined.
An alternative that may be more consistent with other validation tasks could be to put the message in a template lookup (example).
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.
Moved into roles/common/templates/package_vars_wrong_format_msg.j2
|
roles/common/tasks/main.yml
Outdated
|
||
- name: Verify dict format for apt package combined variables | ||
fail: | ||
msg: "{{ package_vars_wrong_format_msg }}" |
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.
this one should be lookup('template'...
too?
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.
done
@tangrufus Let me say again, THANK YOU for all your patient work on this! 💚 As I scrutinize it a bit more, I have a couple more comments. update_cache parameterThis PR normalizes the
As I tested with Given the recent Trellis requirement of Ansible 2.4, I think we can drop all instances of package name indicates package versionThe dict format for vars such as
The above formatting takes advantage of how the apt module uses the
However, some the
I honestly don't know the answer to the following question: Would it be desirable to make vars such as |
Ansible 2.4 implicitly sets `update_cache` when `cache_valid_time` is defined.
All set. |
Awesome, @tangrufus! Looks good to me! 👍 |
Because we always want the latest version.