Skip to content

Commit

Permalink
lib/hardware: allow files for ansible extra vars
Browse files Browse the repository at this point in the history
This change makes it possible to override ansible variables
via ROOKCHECK_ANSIBLE_EXTRA_VARS environment variable
using files instead plain json data.

Signed-off-by: Kyr Shatskyy <[email protected]>
  • Loading branch information
Kyr Shatskyy committed Oct 28, 2020
1 parent 4dc5510 commit f04029f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/lib/hardware/hardware_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@ def ansible_run_playbook(self, playbook: str,
else:
limit = ""

extra_vars_files=""
# Supplied extra_vars from settings always take precedence
if settings.ANSIBLE_EXTRA_VARS:
extra_vars.update(json.loads(settings.ANSIBLE_EXTRA_VARS))
if settings.ANSIBLE_EXTRA_VARS.startswith('@'):
extra_vars_files=settings.ANSIBLE_EXTRA_VARS
else:
extra_vars.update(json.loads(settings.ANSIBLE_EXTRA_VARS))
if extra_vars:
extra_vars_param = f"--extra-vars '{json.dumps(extra_vars)}'"
else:
extra_vars_param = ""
if extra_vars_files:
extra_vars_param += f" --extra-vars '{extra_vars_files}'"

logger.info(f'Running playbook {path} ({limit})')
logger.info(f'Using extra vars: {extra_vars_param}')
self.workspace.execute(
f"ansible-playbook -i {self._ansible_inventory_dir} "
f"{limit} {extra_vars_param} {path}",
Expand Down

0 comments on commit f04029f

Please sign in to comment.