Adjust ansible_user and reload_nginx handler for Ansible 2.1 #631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR updates Trellis to accommodate two changes in Ansible 2.1.1.0
Handlers
The Trellis
reload nginx
handler is an include file with two tasks. A discourse thread revealed that Ansible 2.1.1.0 was only running the second of these two tasks. The second task fails without the var that should have been registered in the first task.As far as I can tell, Ansible 2.0.2.0 treated the
include
task as a single handler task, but 2.1.1.0 reads into the include file, seeing two potential handler tasks. In this latter case, only the second task uses the notified handler name (reload nginx
) so only this second task runs.This change in 2.1.1.0 jeopardizes the strategy of using an
include
to run multiple tasks via a single handler name. Once Trellis requires Ansible >= 2.2, these two tasks in question can be run under a single name via the cominglisten
parameter.In the meantime, this PR gives the first task the handler name that will be notified (
reload nginx
) and lets that first task notify the second task as another handler.The challenge is that when the first task in
reload_nginx.yml
is used as an included task (vs. as a handler) -- always the case in 2.0.2.0 and once in 2.1.1.0 -- it results in the second task being run twice. The second task runs once in its role as a task in theinclude
, then again in its role as a notified handler. This isn't a huge problem but it is unnecessary repetition. The PR avoids the unnecessary repetition by making the first task'snotify
parameter conditional on when the task is running as a handler (vs. included task).ansible_user
Previously the
ansible_user
variable defaulted toundefined
, even onlocal_action
tasks. In Ansible 2.1.1.0 (or in some version since 2.0.2.0),ansible_user
forlocal_action
tasks defaults to the username active on the control machine.This causes a problem to the
remote-user
role'sblock
conditionalwhen: ansible_user is not defined
. When Ansible interprets the "Check whether Ansible can connect as root" task,ansible_user
is in fact now defined because the task uses alocal_action
. Thus the task doesn't run and doesn't register the variable needed in the following task, so the playbook fails.This PR distributes the
block
's conditionalwhen
to the separate tasks. The "Check whether Ansible can connect as root" task is no longer conditional onansible_user is undefined
because then it would never run. There is no problem to have this task always run because of itsfailed_when: false
andchanged_when: false
.