Skip to content
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

Ansible 2.3 compatibility #813

Merged
merged 4 commits into from
Apr 15, 2017
Merged

Ansible 2.3 compatibility #813

merged 4 commits into from
Apr 15, 2017

Conversation

fullyint
Copy link
Contributor

Broken out into separate commits, each with a commit message explaining. One commit prevents Ansible's new dense.py callback from causing Trellis ssh connection tests to always show root as failing to connect. The other commits just prevent Ansible's new warning message about jinja delimiters.

[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}.

The commit Avoid single var containing jinja delimiters in when parameter deserves some explanation but don't expect this explanation to stand on its own without examining the commit's diff.

Consider a when parameter with a single var, e.g., when: site_uses_letsencrypt. The var will be expanded and the var's jinja delimiters will trigger related warnings. This PR's commit avoids the warnings by removing jinja delimiters from the var value/definition:

# roles/letsencrypt/defaults.main.yml
- site_uses_letsencrypt: "{{ ssl_enabled and item.value.ssl.provider | default('manual') == 'letsencrypt' }}"
+ site_uses_letsencrypt: ssl_enabled and item.value.ssl.provider | default('manual') == 'letsencrypt'

That change prevents the warnings, but makes the site_uses_letsencrypt var not function in contexts that aren't part of the when task parameter. This accounts for why the commit in question removes site_uses_letsencrypt from the definition of missing_hosts

# roles/letsencrypt/defaults.main.yml
- missing_hosts: "{{ site_uses_letsencrypt | ternary(site_hosts, []) | difference(... bunch of stuff
+ missing_hosts: "{{ site_hosts | difference(... bunch of stuff

This change to missing_hosts means its two appearances in the form
when: missing_hosts | count must be adjusted. However, it turns out that the lack of jinja delimiters in site_uses_letsencrypt causes this adjustment to be ineffective:

- when: missing_hosts | count
+ when: missing_hosts | count and site_uses_letsencrypt

This accounts for why the commit in question uses the strategy below, leaving the site_uses_letsencrypt alone in a single item (vs. the compound item in the diff above).

- when: missing_hosts | count
+ when:
+   - site_uses_letsencrypt
+   - missing_hosts | count

Tested on Ansible branch 2.3-stable as of 07ea6a6 and on Ansible 2.2.0.0. Tests included default configs and alternative configs such as Let's Encrypt enabled, nginx-includes, and root login disabled, on DigitalOcean and AWS EC2.

stdout_lines of whoami with -vvvv formerly included `root`
but now will include ansi code prefix: `\e[0;32mroot`.
Connection as root will always appear to have failed
unless Trellis checks for this revised string.
Prevents related warnings introduced in Ansible 2.3
ansible/ansible#ff20ab7
A single var in a `when` parameter will be expanded and the var's
jinja delimiters will trigger related warnings introduced in Ansible 2.3
ansible/ansible#ff20ab7
@fullyint
Copy link
Contributor Author

This PR works with today's official release of Ansible 2.3.

Installing Ansible 2.3 installs Jinja2 v2.9.6 (up from v2.8.1).
Jinja2 v 2.9.4 changed the truncate.leeway default from 0 to 5 chars,
resulting in no truncation for salts up to 21 characters, potentially causing
`salt too large (sha512_crypt requires <= 16 chars)` failure.
Adding a final parameter `0` (leeway) resolves the issue in Ansible 2.3,
but fails on earlier versions with Jinja2 < 2.9.4, causing the error
`do_truncate() takes at most 4 arguments (5 given)`.
This commit switches to python slice [:16] because it works in all contexts.
@fullyint fullyint merged commit 1f165ea into master Apr 15, 2017
@fullyint fullyint deleted the ansible-2.3 branch April 15, 2017 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant