bifrost-cli: fix relative paths in --extra-vars

Ansible accepts YAML files via the syntax `-e @path.yaml`. Since
bifrost-cli changes the working directory to "playbooks", relative paths
don't work as expected. Fix that by turning them into global paths.

Change-Id: I02ba2ac85c72362dbc424037c3d23231098e065b
This commit is contained in:
Dmitry Tantsur 2021-07-19 14:39:26 +02:00
parent 49fb766bbb
commit f0f6e6aa9e
1 changed files with 9 additions and 1 deletions

View File

@ -47,6 +47,14 @@ def log(*message, only_if=True):
print(*message, file=sys.stderr)
def process_extra_vars(extra_vars):
for item in extra_vars:
if item.startswith('@'):
# Make sure relative paths still work
item = '@' + os.path.abspath(item[1:])
yield ('-e', item)
def ansible(playbook, inventory, verbose=False, env=None, extra_vars=None,
**params):
extra = COMMON_PARAMS[:]
@ -55,7 +63,7 @@ def ansible(playbook, inventory, verbose=False, env=None, extra_vars=None,
if pair[1] is not None))
if extra_vars:
extra.extend(itertools.chain.from_iterable(
('-e', item) for item in extra_vars))
process_extra_vars(extra_vars)))
if verbose:
extra.append('-vvvv')
args = [ANSIBLE, playbook, '-i', inventory] + extra