From c57f87870b3422c5782a45fd6740fd0f2ce6c307 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 28 Jan 2020 14:48:38 -0600 Subject: [PATCH] Add kwarg to set an ansible.cfg file This change implements the ability to set the file path for an ansible configuration file. If no option is provide a default ansible.cfg file will be generated in the artifact path. This default ansible.cfg file will, at this time, contain one tunable which will improve CPU availability by reducing the internal polling interval. While most of the ansible configuration is performned though the use of environment variables, not all options have an exposed environment variable or playbook tunable. By having the ability to define an ansible configuration file, or generate one when needed, we should be able to accomodate any configuration required. Change-Id: Ic2ae04daf81f19afa763c2f6b1c0ae5e6467324b Signed-off-by: Kevin Carter --- tripleoclient/utils.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index cd08540f1..cd0a3cb5a 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -207,7 +207,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None, limit_hosts=None, tags=None, skip_tags=None, verbosity=0, quiet=False, extra_vars=None, plan='overcloud', gathering_policy='smart', - extra_env_variables=None): + extra_env_variables=None, ansible_cfg=None): """Simple wrapper for ansible-playbook. :param playbook: Playbook filename. @@ -267,6 +267,10 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None, :param extra_env_variables: Dict option to extend or override any of the default environment variables. :type extra_env_variables: Dict + + :param ansible_cfg: Path to an ansible configuration file. One will be + generated in the artifact path if this option is None. + :type ansible_cfg: String """ def _playbook_check(play): @@ -460,6 +464,17 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None, env.update(extra_env_variables) with TempDirs(chdir=False) as ansible_artifact_path: + if 'ANSIBLE_CONFIG' not in env and not ansible_cfg: + ansible_cfg = os.path.join(ansible_artifact_path, 'ansible.cfg') + config = configparser.ConfigParser() + config.add_section('defaults') + config.set('defaults', 'internal_poll_interval', '0.05') + with open(ansible_cfg, 'w') as f: + config.write(f) + env['ANSIBLE_CONFIG'] = ansible_cfg + elif 'ANSIBLE_CONFIG' not in env and ansible_cfg: + env['ANSIBLE_CONFIG'] = ansible_cfg + r_opts = { 'private_data_dir': workdir, 'project_dir': playbook_dir,