diff --git a/plugins/module_utils/tripleo_repos/yum_config/__main__.py b/plugins/module_utils/tripleo_repos/yum_config/__main__.py index 8d445e5..6ab8f11 100644 --- a/plugins/module_utils/tripleo_repos/yum_config/__main__.py +++ b/plugins/module_utils/tripleo_repos/yum_config/__main__.py @@ -15,6 +15,7 @@ import argparse import logging +import os import sys from tripleo_repos.utils import load_logging @@ -277,7 +278,16 @@ def main(): override_repos=args.disable_conflicting) if args.disable_repos: for file in args.disable_repos: - repo_obj.update_all_sections(file, enabled=False) + valid_path = None + rel_path = os.path.join(args.config_dir_path, file) + + if cfg.validated_file_path(file): + valid_path = file + elif cfg.validated_file_path(rel_path): + valid_path = rel_path + + if valid_path is not None: + repo_obj.update_all_sections(valid_path, enabled=False) def cli_entrypoint(): diff --git a/plugins/module_utils/tripleo_repos/yum_config/compose_repos.py b/plugins/module_utils/tripleo_repos/yum_config/compose_repos.py index 6fc273e..75d5e2c 100644 --- a/plugins/module_utils/tripleo_repos/yum_config/compose_repos.py +++ b/plugins/module_utils/tripleo_repos/yum_config/compose_repos.py @@ -159,7 +159,10 @@ class TripleOYumComposeRepoConfig(TripleOYumConfig): self.add_section(var.lower(), add_dict, file_path) except TripleOYumConfigInvalidSection: logging.debug("Section '%s' that already exists in this file. " - "Skipping...", var) + "Trying to update it...", var) + self.update_section(var.lower(), + set_dict=add_dict, + file_path=file_path) # needed to override other repos updated_repos[var.lower()] = file_path diff --git a/plugins/modules/yum_config.py b/plugins/modules/yum_config.py index fd7fabc..9799152 100644 --- a/plugins/modules/yum_config.py +++ b/plugins/modules/yum_config.py @@ -6,6 +6,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type + DOCUMENTATION = r''' --- module: yum_config @@ -178,6 +179,8 @@ EXAMPLES = r''' RETURN = r''' # ''' +import os # noqa: E402 + from ansible.module_utils import six # noqa: E402 from ansible.module_utils.basic import AnsibleModule # noqa: E402 @@ -316,7 +319,16 @@ def run_module(): override_repos=module.params['disable_conflicting_variants']) # 3. Disable all repos provided in disable_repos for file in module.params['disable_repos']: - repo_obj.update_all_sections(file, enabled=False) + valid_path = None + rel_path = os.path.join(module.params['dir_path'], file) + + if cfg.validated_file_path(file): + valid_path = file + elif cfg.validated_file_path(rel_path): + valid_path = rel_path + + if valid_path is not None: + repo_obj.update_all_sections(valid_path, enabled=False) elif module.params['type'] == 'module': try: diff --git a/tests/unit/yum_config/test_main.py b/tests/unit/yum_config/test_main.py index 521ccd9..f24989b 100644 --- a/tests/unit/yum_config/test_main.py +++ b/tests/unit/yum_config/test_main.py @@ -181,6 +181,8 @@ class TestTripleoYumConfigMain(TestTripleoYumConfigBase): repos_obj, 'enable_compose_repos') mock_update_all = self.mock_object( repos_obj, 'update_all_sections') + self.mock_object(yum_cfg, 'validated_file_path', + mock.Mock(return_value=True)) main.main()