add ANSIBLE_PLAYBOOK_DIR envvar support (#63220)
* add ANSIBLE_PLAYBOOK_DIR envvar support * allows `ANSIBLE_PLAYBOOK_DIR` envvar as a fallback on CLI types that support `--playbook-dir`. This should have been implemented with #59464, but was missed due to an oversight. * added basic integration test * make first-class PLAYBOOK_DIR config entry * update changelog
This commit is contained in:
parent
bad72693e4
commit
fd229dcbb5
5 changed files with 22 additions and 1 deletions
2
changelogs/fragments/59464-playbook-dir-envvar.yml
Normal file
2
changelogs/fragments/59464-playbook-dir-envvar.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- CLI - the `ANSIBLE_PLAYBOOK_DIR` envvar or `playbook_dir` config can now substitute for the --playbook-dir arg on CLIs that support it (https://github.com/ansible/ansible/issues/59464)
|
|
@ -223,7 +223,7 @@ def add_async_options(parser):
|
|||
|
||||
def add_basedir_options(parser):
|
||||
"""Add options for commands which can set a playbook basedir"""
|
||||
parser.add_argument('--playbook-dir', default=None, dest='basedir', action='store',
|
||||
parser.add_argument('--playbook-dir', default=C.config.get_config_value('PLAYBOOK_DIR'), dest='basedir', action='store',
|
||||
help="Since this tool does not use playbooks, use this as a substitute playbook directory."
|
||||
"This sets the relative path for many features including roles/ group_vars/ etc.")
|
||||
|
||||
|
|
|
@ -1680,6 +1680,14 @@ PERSISTENT_COMMAND_TIMEOUT:
|
|||
ini:
|
||||
- {key: command_timeout, section: persistent_connection}
|
||||
type: int
|
||||
PLAYBOOK_DIR:
|
||||
name: playbook dir override for non-playbook CLIs (ala --playbook-dir)
|
||||
version_added: "2.9"
|
||||
description:
|
||||
- A number of non-playbook CLIs have a ``--playbook-dir`` argument; this sets the default value for it.
|
||||
env: [{name: ANSIBLE_PLAYBOOK_DIR}]
|
||||
ini: [{key: playbook_dir, section: defaults}]
|
||||
type: path
|
||||
PLAYBOOK_VARS_ROOT:
|
||||
name: playbook vars files root
|
||||
default: top
|
||||
|
|
2
test/integration/targets/ansible/playbookdir_cfg.ini
Normal file
2
test/integration/targets/ansible/playbookdir_cfg.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
[defaults]
|
||||
playbook_dir = /tmp
|
|
@ -18,6 +18,15 @@ ansible-config view -c ./ansible-non-existent.cfg 2> err1.txt || grep -Eq 'ERROR
|
|||
ansible-config view -c ./no-extension 2> err2.txt || grep -q 'Unsupported configuration file extension' err2.txt || (cat err2.txt; rm -f err*.txt; exit 1)
|
||||
rm -f err*.txt
|
||||
|
||||
# test setting playbook_dir via envvar
|
||||
ANSIBLE_PLAYBOOK_DIR=/tmp ansible localhost -m debug -a var=playbook_dir | grep '"playbook_dir": "/tmp"'
|
||||
|
||||
# test setting playbook_dir via cmdline
|
||||
ansible localhost -m debug -a var=playbook_dir --playbook-dir=/tmp | grep '"playbook_dir": "/tmp"'
|
||||
|
||||
# test setting playbook dir via ansible.cfg
|
||||
ANSIBLE_CONFIG=./playbookdir_cfg.ini ansible localhost -m debug -a var=playbook_dir | grep '"playbook_dir": "/tmp"'
|
||||
|
||||
# Test that no tmp dirs are left behind when running ansible-config
|
||||
TMP_DIR=~/.ansible/tmptest
|
||||
if [[ -d "$TMP_DIR" ]]; then
|
||||
|
|
Loading…
Reference in a new issue