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 <kecarter@redhat.com>
This commit is contained in:
parent
d8e0c5389c
commit
c57f87870b
@ -207,7 +207,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
|
|||||||
limit_hosts=None, tags=None, skip_tags=None,
|
limit_hosts=None, tags=None, skip_tags=None,
|
||||||
verbosity=0, quiet=False, extra_vars=None,
|
verbosity=0, quiet=False, extra_vars=None,
|
||||||
plan='overcloud', gathering_policy='smart',
|
plan='overcloud', gathering_policy='smart',
|
||||||
extra_env_variables=None):
|
extra_env_variables=None, ansible_cfg=None):
|
||||||
"""Simple wrapper for ansible-playbook.
|
"""Simple wrapper for ansible-playbook.
|
||||||
|
|
||||||
:param playbook: Playbook filename.
|
: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
|
:param extra_env_variables: Dict option to extend or override any of the
|
||||||
default environment variables.
|
default environment variables.
|
||||||
:type extra_env_variables: Dict
|
: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):
|
def _playbook_check(play):
|
||||||
@ -460,6 +464,17 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
|
|||||||
env.update(extra_env_variables)
|
env.update(extra_env_variables)
|
||||||
|
|
||||||
with TempDirs(chdir=False) as ansible_artifact_path:
|
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 = {
|
r_opts = {
|
||||||
'private_data_dir': workdir,
|
'private_data_dir': workdir,
|
||||||
'project_dir': playbook_dir,
|
'project_dir': playbook_dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user