mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-03 05:11:49 -05:00
Check the user's ansible.cfg for role/collection paths.
There's no other way to add our new paths reliably without breaking things.
This commit is contained in:
@@ -5,11 +5,15 @@
|
||||
import codecs
|
||||
import re
|
||||
import os
|
||||
import logging
|
||||
from itertools import islice
|
||||
from configparser import ConfigParser
|
||||
|
||||
# Django
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
logger = logging.getLogger('awx.main.utils.ansible')
|
||||
|
||||
|
||||
__all__ = ['skip_directory', 'could_be_playbook', 'could_be_inventory']
|
||||
|
||||
@@ -97,3 +101,20 @@ def could_be_inventory(project_path, dir_path, filename):
|
||||
except IOError:
|
||||
return None
|
||||
return inventory_rel_path
|
||||
|
||||
|
||||
def read_ansible_config(project_path, variables_of_interest):
|
||||
fnames = ['/etc/ansible/ansible.cfg']
|
||||
if project_path:
|
||||
fnames.insert(0, os.path.join(project_path, 'ansible.cfg'))
|
||||
values = {}
|
||||
try:
|
||||
parser = ConfigParser()
|
||||
parser.read(fnames)
|
||||
if 'defaults' in parser:
|
||||
for var in variables_of_interest:
|
||||
if var in parser['defaults']:
|
||||
values[var] = parser['defaults'][var]
|
||||
except Exception as e:
|
||||
logger.warn('Failed to read ansible configuration(s) {}: {}'.format(fnames, e))
|
||||
return values
|
||||
|
||||
Reference in New Issue
Block a user