Skip to content

Commit

Permalink
(Almost) Correctly write variables into Ansible inventory.
Browse files Browse the repository at this point in the history
Inventory variables with embedded spaces need quoting -- or Ansible
will not be able to parse the file.  This commit (ab)uses Python's
`%r` to provide quotes around a value and \-escape any embedded
quotes; a better fix would definitely be to switch to YAML inventory
files.
  • Loading branch information
riccardomurri committed May 10, 2019
1 parent e0937b6 commit cf7f84f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions elasticluster/providers/ansible_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,16 @@ def _build_inventory(self, cluster):
.format(
python=ansible_python_interpreter,
eatmydata=('+eatmydata' if self.use_eatmydata else '')))
extra_vars.extend('%s=%s' % (k, v) for k, v in
# abuse Python's %r fomat to provide quotes around the
# value, and \-escape any embedded quote chars
extra_vars.extend('%s=%r' % (k, str(v)) for k, v in
extra_conf.items()
if k.startswith('ansible_'))

if node.kind in self.environment:
extra_vars.extend('%s=%s' % (k, v) for k, v in
# abuse Python's %r fomat to provide quotes around the
# value, and \-escape any embedded quote chars
extra_vars.extend('%s=%r' % (k, str(v)) for k, v in
self.environment[node.kind].items())

for group in self.groups[node.kind]:
Expand Down

0 comments on commit cf7f84f

Please sign in to comment.