Unfrack extra vars (#75127)

* Ensure we keep teh original path as per cli

  fixes #75126

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/75151/head
Brian Coca 3 years ago committed by GitHub
parent d9eb846534
commit 60c9f045cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Ensure we get full path for extra vars into cliargs to avoid realpath issues after initial load.

@ -100,6 +100,15 @@ def unfrack_path(pathsep=False):
return inner
def maybe_unfrack_path(beacon):
def inner(value):
if value.startswith(beacon):
return beacon + unfrackpath(value[1:])
return value
return inner
def _git_repo_info(repo_path):
""" returns a string containing git branch, commit id and commit date """
result = None
@ -340,7 +349,7 @@ def add_runas_prompt_options(parser, runas_group=None):
def add_runtask_options(parser):
"""Add options for commands that run a task"""
parser.add_argument('-e', '--extra-vars', dest="extra_vars", action="append",
parser.add_argument('-e', '--extra-vars', dest="extra_vars", action="append", type=maybe_unfrack_path('@'),
help="set additional variables as key=value or YAML/JSON, if filename prepend with @", default=[])

@ -0,0 +1,19 @@
- hosts: localhost
gather_facts: false
vars:
conditions:
- my is defined
- my == 'var'
- "'webservers' in groups"
- "'web_host.example.com' in groups['webservers']"
tasks:
- name: Make sure all is loaded
assert:
that: '{{conditions}}'
- name: Reload inventory, forces extra vars re-eval from diff basedir
meta: refresh_inventory
- name: Make sure all is loaded, again
assert:
that: '{{conditions}}'

@ -0,0 +1,3 @@
plugin: constructed
groups:
webservers: inventory_hostname.startswith('web')

@ -88,3 +88,9 @@ fi
# ensure we don't traceback on inventory due to variables with int as key
ansible-inventory -i inv_with_int.yml --list "$@"
# test in subshell relative paths work mid play for extra vars in inventory refresh
{
cd 1/2
ansible-playbook -e @../vars.yml -i 'web_host.example.com,' -i inventory.yml 3/extra_vars_relative.yml "$@"
}

Loading…
Cancel
Save