diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:16:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:16:47 +0000 |
commit | 7a7fb74454bb3a169acecd30e87067502bfe3260 (patch) | |
tree | d684cbea7ffc70bd39a1e52bb65b0ea5ae156bda /lib/ansible/cli/galaxy.py | |
parent | Adding upstream version 2.16.6. (diff) | |
download | ansible-core-7a7fb74454bb3a169acecd30e87067502bfe3260.tar.xz ansible-core-7a7fb74454bb3a169acecd30e87067502bfe3260.zip |
Adding upstream version 2.17.0.upstream/2.17.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ansible/cli/galaxy.py')
-rwxr-xr-x | lib/ansible/cli/galaxy.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 334e4bf..805bd65 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -4,8 +4,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # PYTHON_ARGCOMPLETE_OK -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations # ansible.cli needs to be imported first, to ensure the source bin/* scripts run that code first from ansible.cli import CLI @@ -62,6 +61,7 @@ from ansible.template import Templar from ansible.utils.collection_loader import AnsibleCollectionConfig from ansible.utils.display import Display from ansible.utils.plugin_docs import get_versioned_doclink +from ansible.utils.vars import load_extra_vars display = Display() urlparse = six.moves.urllib.parse.urlparse @@ -367,6 +367,7 @@ class GalaxyCLI(CLI): init_parser.add_argument('--type', dest='role_type', action='store', default='default', help="Initialize using an alternate role type. Valid types include: 'container', " "'apb' and 'network'.") + opt_help.add_runtask_options(init_parser) def add_remove_options(self, parser, parents=None): remove_parser = parser.add_parser('remove', parents=parents, help='Delete roles from roles_path.') @@ -1172,6 +1173,7 @@ class GalaxyCLI(CLI): ) loader = DataLoader() + inject_data.update(load_extra_vars(loader)) templar = Templar(loader, variables=inject_data) # create role directory @@ -1215,7 +1217,11 @@ class GalaxyCLI(CLI): src_template = os.path.join(root, f) dest_file = os.path.join(obj_path, rel_root, filename) template_data = to_text(loader._get_file_contents(src_template)[0], errors='surrogate_or_strict') - b_rendered = to_bytes(templar.template(template_data), errors='surrogate_or_strict') + try: + b_rendered = to_bytes(templar.template(template_data), errors='surrogate_or_strict') + except AnsibleError as e: + shutil.rmtree(b_obj_path) + raise AnsibleError(f"Failed to create {galaxy_type.title()} {obj_name}. Templating {src_template} failed with the error: {e}") from e with open(dest_file, 'wb') as df: df.write(b_rendered) else: |