forked from debops/debops
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'drybjed-debops-playbook-sets'
- Loading branch information
Showing
4 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
{# Copyright (C) 2023 Maciej Delmanowski <[email protected]> | ||
# Copyright (C) 2023 DebOps <https://debops.org/> | ||
{# Copyright (C) 2023-2024 Maciej Delmanowski <[email protected]> | ||
# Copyright (C) 2023-2024 DebOps <https://debops.org/> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
#} | ||
# Configuration for the '{{ view_name }}' view | ||
|
@@ -13,6 +13,9 @@ views: | |
playbook_collections: | ||
- 'debops.debops' | ||
|
||
# YAML dictionary which defines lists of "playbook sets" to use in this view | ||
playbook_sets: {} | ||
|
||
# Configuration options for Ansible, will be included in the 'ansible.cfg' | ||
# file generated by DebOps. | ||
# Ref: https://docs.ansible.com/ansible/latest/reference_appendices/config.html | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Copyright (C) 2020-2021 Maciej Delmanowski <[email protected]> | ||
# Copyright (C) 2020-2021 DebOps <https://debops.org/> | ||
# Copyright (C) 2020-2024 Maciej Delmanowski <[email protected]> | ||
# Copyright (C) 2020-2024 DebOps <https://debops.org/> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from .utils import unexpanduser | ||
|
@@ -108,18 +108,46 @@ def __init__(self, project, *args, **kwargs): | |
self._parsed_args.append(index) | ||
else: | ||
# Most likely a name of a playbook which we can expand | ||
self._ansible_command.append(self._quote_spaces( | ||
self._expand_playbook(project, argument))) | ||
self._found_playbooks.append(self._quote_spaces( | ||
self._expand_playbook(project, argument))) | ||
self._parsed_args.append(index) | ||
|
||
# Check the arguments for possible playbook sets and expand them | ||
# if they're found | ||
parsed_set = self._expand_playbook_set(project, argument) | ||
|
||
for element in parsed_set: | ||
self._ansible_command.append(self._quote_spaces( | ||
self._expand_playbook(project, element))) | ||
self._found_playbooks.append(self._quote_spaces( | ||
self._expand_playbook(project, element))) | ||
self._parsed_args.append(index) | ||
|
||
def _quote_spaces(self, string): | ||
if ' ' in string: | ||
return '"{}"'.format(string) | ||
else: | ||
return string | ||
|
||
def _expand_playbook_set(self, project, argument): | ||
logger.debug('Checking if playbook "{}" is a playbook set' | ||
.format(argument)) | ||
try: | ||
playbook_set = (project.config.raw['views'] | ||
[project.view] | ||
['playbook_sets'] | ||
[argument]) | ||
logger.notice('Found playbook set "{}" in view "{}"' | ||
.format(argument, project.view)) | ||
if isinstance(playbook_set, list): | ||
logger.debug('Playbook set "{}" expanded to: {}' | ||
.format(argument, ' '.join(playbook_set))) | ||
return playbook_set | ||
else: | ||
logger.error('Incorrect definition of playbook set', | ||
extra={'block': 'stderr'}) | ||
raise ValueError('Incorrect definition of playbook set') | ||
except KeyError: | ||
logger.debug('No playbook set found') | ||
return [argument] | ||
|
||
def _ring_bell(self): | ||
# Notify user at end of execution | ||
if self.kwargs.get('bell', False): | ||
|