Merge pull request #7224 from john-westcott-iv/utilize_has_yaml

Now respecting the HAS_YAML variable

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-06-02 20:32:32 +00:00
committed by GitHub

View File

@@ -153,13 +153,20 @@ class TowerModule(AnsibleModule):
config_string = f.read() config_string = f.read()
# First try to yaml load the content (which will also load json) # First try to yaml load the content (which will also load json)
try:
try_config_parsing = True
if HAS_YAML:
try: try:
config_data = yaml.load(config_string, Loader=yaml.SafeLoader) config_data = yaml.load(config_string, Loader=yaml.SafeLoader)
# If this is an actual ini file, yaml will return the whole thing as a string instead of a dict # If this is an actual ini file, yaml will return the whole thing as a string instead of a dict
if type(config_data) is not dict: if type(config_data) is not dict:
raise AssertionError("The yaml config file is not properly formatted as a dict.") raise AssertionError("The yaml config file is not properly formatted as a dict.")
try_config_parsing = False
except(AttributeError, yaml.YAMLError, AssertionError): except(AttributeError, yaml.YAMLError, AssertionError):
try_config_parsing = True
if try_config_parsing:
# TowerCLI used to support a config file with a missing [general] section by prepending it if missing # TowerCLI used to support a config file with a missing [general] section by prepending it if missing
if '[general]' not in config_string: if '[general]' not in config_string:
config_string = '[general]{0}'.format(config_string) config_string = '[general]{0}'.format(config_string)
@@ -180,7 +187,7 @@ class TowerModule(AnsibleModule):
for honorred_setting in self.honorred_settings: for honorred_setting in self.honorred_settings:
try: try:
config_data[honorred_setting] = config.get('general', honorred_setting) config_data[honorred_setting] = config.get('general', honorred_setting)
except (NoOptionError): except NoOptionError:
pass pass
except Exception as e: except Exception as e: