Skip to content

Commit 11065c8

Browse files
committed
Escape salts and keys to avoid templating errors
1 parent b2b57d1 commit 11065c8

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### HEAD
2+
* Escape salts and keys to avoid templating errors ([#548](https://github.com/roots/trellis/pull/548))
23
* Add plugin to pretty print Ansible msg output ([#544](https://github.com/roots/trellis/pull/544))
34
* Fix #482 - Multisite is-installed deploy check ([#543](https://github.com/roots/trellis/pull/543))
45
* Skip setting permalink for multisite installs ([#546](https://github.com/roots/trellis/pull/546))

ansible.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ force_handlers = True
66
inventory = hosts
77
library = /usr/share/ansible:lib/trellis/modules
88
roles_path = vendor/roles
9+
vars_plugins = ~/.ansible/plugins/vars_plugins/:/usr/share/ansible_plugins/vars_plugins:lib/trellis/plugins/vars
910

1011
[ssh_connection]
1112
ssh_args = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s

group_vars/production/vault.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ vault_wordpress_sites:
1212
env:
1313
db_password: example_dbpassword
1414
# Generate your keys here: https://api.wordpress.org/secret-key/1.1/salt/
15-
# These CANNOT contain the characters "{%" or "{{" in succession
1615
auth_key: "generateme"
1716
secure_auth_key: "generateme"
1817
logged_in_key: "generateme"

group_vars/staging/vault.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ vault_wordpress_sites:
1212
env:
1313
db_password: example_dbpassword
1414
# Generate your keys here: https://api.wordpress.org/secret-key/1.1/salt/
15-
# These CANNOT contain the characters "{%" or "{{" in succession
1615
auth_key: "generateme"
1716
secure_auth_key: "generateme"
1817
logged_in_key: "generateme"

lib/trellis/plugins/vars/vars.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from __future__ import (absolute_import, division, print_function)
2+
__metaclass__ = type
3+
4+
class VarsModule(object):
5+
''' Creates and modifies host variables '''
6+
7+
def __init__(self, inventory):
8+
self.inventory = inventory
9+
self.inventory_basedir = inventory.basedir()
10+
11+
# Wrap salts and keys variables in {% raw %} to prevent jinja templating errors
12+
def wrap_salts_in_raw(self, host, hostvars):
13+
if 'vault_wordpress_sites' in hostvars:
14+
for name, site in hostvars['vault_wordpress_sites'].iteritems():
15+
for key, value in site['env'].iteritems():
16+
if key.endswith(('_key', '_salt')) and not value.startswith(('{% raw', '{%raw')):
17+
hostvars['vault_wordpress_sites'][name]['env'][key] = ''.join(['{% raw %}', value, '{% endraw %}'])
18+
host.vars['vault_wordpress_sites'] = hostvars['vault_wordpress_sites']
19+
20+
def get_host_vars(self, host, vault_password=None):
21+
self.wrap_salts_in_raw(host, host.get_group_vars())
22+
return {}

0 commit comments

Comments
 (0)