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
pull/63265/head
Matt Davis 5 years ago committed by GitHub
parent bad72693e4
commit fd229dcbb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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): def add_basedir_options(parser):
"""Add options for commands which can set a playbook basedir""" """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." 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.") "This sets the relative path for many features including roles/ group_vars/ etc.")

@ -1680,6 +1680,14 @@ PERSISTENT_COMMAND_TIMEOUT:
ini: ini:
- {key: command_timeout, section: persistent_connection} - {key: command_timeout, section: persistent_connection}
type: int 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: PLAYBOOK_VARS_ROOT:
name: playbook vars files root name: playbook vars files root
default: top default: top

@ -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) 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 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 # Test that no tmp dirs are left behind when running ansible-config
TMP_DIR=~/.ansible/tmptest TMP_DIR=~/.ansible/tmptest
if [[ -d "$TMP_DIR" ]]; then if [[ -d "$TMP_DIR" ]]; then

Loading…
Cancel
Save