From c3fd14e18f7ced21df42abc4e9f310f070ad7a55 Mon Sep 17 00:00:00 2001 From: Gustav Alerby Date: Wed, 20 Sep 2023 19:28:32 +0200 Subject: [PATCH 1/6] Ignore similar chars in random_string (#7242) * Added the option to ignore certain characters This can be usefull for eliminating confusion. * Removed the loop and added each char_sets The variable name is not known inside the loop so updating it does not work. * Changelog fragment file * Forgot the file extention for the fragment yaml file * Update plugins/lookup/random_string.py Co-authored-by: Felix Fontein * Update plugins/lookup/random_string.py Co-authored-by: Felix Fontein * Update plugins/lookup/random_string.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- .../fragments/7242_ignore_similar_chars.yml | 2 ++ plugins/lookup/random_string.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 changelogs/fragments/7242_ignore_similar_chars.yml diff --git a/changelogs/fragments/7242_ignore_similar_chars.yml b/changelogs/fragments/7242_ignore_similar_chars.yml new file mode 100644 index 00000000000..5b65a123d9a --- /dev/null +++ b/changelogs/fragments/7242_ignore_similar_chars.yml @@ -0,0 +1,2 @@ +minor_changes: + - random_string - added new ``ignore_similar_chars`` and ``similar_chars`` option to ignore certain chars (https://github.com/ansible-collections/community.general/pull/7242). diff --git a/plugins/lookup/random_string.py b/plugins/lookup/random_string.py index 3e873e1cf10..d810f593660 100644 --- a/plugins/lookup/random_string.py +++ b/plugins/lookup/random_string.py @@ -80,6 +80,19 @@ - Override all values of O(numbers), O(upper), O(lower), and O(special) with the given list of characters. type: str + ignore_similar_chars: + description: + - Ignore similar characters, such as V(l) and V(1), or V(O) and V(0). + - These characters can be configured in O(similar_chars). + default: false + type: bool + version_added: 7.5.0 + similar_chars: + description: + - Overide a list of characters not to be use in the string. + default: "il1LoO0" + type: str + version_added: 7.5.0 base64: description: - Returns base64 encoded string. @@ -173,9 +186,17 @@ def run(self, terms, variables=None, **kwargs): length = self.get_option("length") base64_flag = self.get_option("base64") override_all = self.get_option("override_all") + ignore_similar_chars = self.get_option("ignore_similar_chars") + similar_chars = self.get_option("similar_chars") values = "" available_chars_set = "" + if ignore_similar_chars: + number_chars = "".join([sc for sc in number_chars if sc not in similar_chars]) + lower_chars = "".join([sc for sc in lower_chars if sc not in similar_chars]) + upper_chars = "".join([sc for sc in upper_chars if sc not in similar_chars]) + special_chars = "".join([sc for sc in special_chars if sc not in similar_chars]) + if override_all: # Override all the values available_chars_set = override_all From 9489a1ea1cc5a19184109243deb76ff646df4876 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Thu, 21 Sep 2023 05:29:05 +1200 Subject: [PATCH 2/6] New Module: gio_mime (#7271) * gio_mime: new module * multiple changes - fixed gio_mime module utils handler detection - add message to test helper assertion - add unit test * gio mime output uses unicode smart quotes * test helper: do not use skip/xfail reason messages - break in old pytest * Update plugins/modules/gio_mime.py Co-authored-by: Felix Fontein * change exist variables to meet standards --------- Co-authored-by: Felix Fontein --- .github/BOTMETA.yml | 4 + plugins/module_utils/gio_mime.py | 32 ++++++ plugins/modules/gio_mime.py | 108 ++++++++++++++++++ tests/sanity/ignore-2.11.txt | 1 + tests/sanity/ignore-2.12.txt | 1 + tests/sanity/ignore-2.13.txt | 1 + tests/sanity/ignore-2.14.txt | 1 + tests/sanity/ignore-2.15.txt | 1 + tests/sanity/ignore-2.16.txt | 1 + tests/unit/plugins/modules/helper.py | 6 +- tests/unit/plugins/modules/test_gio_mime.py | 16 +++ tests/unit/plugins/modules/test_gio_mime.yaml | 70 ++++++++++++ 12 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 plugins/module_utils/gio_mime.py create mode 100644 plugins/modules/gio_mime.py create mode 100644 tests/unit/plugins/modules/test_gio_mime.py create mode 100644 tests/unit/plugins/modules/test_gio_mime.yaml diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 4088a7cc3bd..5c21e0b556d 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -278,6 +278,8 @@ files: $module_utils/gconftool2.py: labels: gconftool2 maintainers: russoz + $module_utils/gio_mime.py: + maintainers: russoz $module_utils/gitlab.py: keywords: gitlab source_control labels: gitlab @@ -517,6 +519,8 @@ files: $modules/gem.py: labels: gem maintainers: $team_ansible_core johanwiren + $modules/gio_mime.py: + maintainers: russoz $modules/git_config.py: maintainers: djmattyg007 mgedmin $modules/github_: diff --git a/plugins/module_utils/gio_mime.py b/plugins/module_utils/gio_mime.py new file mode 100644 index 00000000000..e01709487d1 --- /dev/null +++ b/plugins/module_utils/gio_mime.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2022, Alexei Znamensky +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt + + +def gio_mime_runner(module, **kwargs): + return CmdRunner( + module, + command=['gio', 'mime'], + arg_formats=dict( + mime_type=cmd_runner_fmt.as_list(), + handler=cmd_runner_fmt.as_list(), + ), + **kwargs + ) + + +def gio_mime_get(runner, mime_type): + def process(rc, out, err): + if err.startswith("No default applications for"): + return None + out = out.splitlines()[0] + return out.split()[-1] + + with runner("mime_type", output_process=process) as ctx: + return ctx.run(mime_type=mime_type) diff --git a/plugins/modules/gio_mime.py b/plugins/modules/gio_mime.py new file mode 100644 index 00000000000..27f90581efb --- /dev/null +++ b/plugins/modules/gio_mime.py @@ -0,0 +1,108 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright (c) 2022, Alexei Znamensky +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: gio_mime +author: + - "Alexei Znamensky (@russoz)" +short_description: Set default handler for MIME type, for applications using Gnome GIO +version_added: 7.5.0 +description: + - This module allows configuring the default handler for a specific MIME type, to be used by applications built with th Gnome GIO API. +extends_documentation_fragment: + - community.general.attributes +attributes: + check_mode: + support: full + diff_mode: + support: full +options: + mime_type: + description: + - MIME type for which a default handler will be set. + type: str + required: true + handler: + description: + - Default handler will be set for the MIME type. + type: str + required: true +notes: + - This module is a thin wrapper around the C(gio mime) command (and subcommand). + - See man gio(1) for more details. +seealso: + - name: GIO Documentation + description: Reference documentation for the GIO API.. + link: https://docs.gtk.org/gio/ +''' + +EXAMPLES = """ +- name: Set chrome as the default handler for https + community.general.gio_mime: + mime_type: x-scheme-handler/https + handler: google-chrome.desktop + register: result +""" + +RETURN = ''' + handler: + description: + - The handler set as default. + returned: success + type: str + sample: google-chrome.desktop + stdout: + description: + - The output of the C(gio) command. + returned: success + type: str + sample: Set google-chrome.desktop as the default for x-scheme-handler/https + stderr: + description: + - The error output of the C(gio) command. + returned: failure + type: str + sample: 'gio: Failed to load info for handler "never-existed.desktop"' +''' + +from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper +from ansible_collections.community.general.plugins.module_utils.gio_mime import gio_mime_runner, gio_mime_get + + +class GioMime(ModuleHelper): + output_params = ['handler'] + module = dict( + argument_spec=dict( + mime_type=dict(type='str', required=True), + handler=dict(type='str', required=True), + ), + supports_check_mode=True, + ) + + def __init_module__(self): + self.runner = gio_mime_runner(self.module, check_rc=True) + self.vars.set_meta("handler", initial_value=gio_mime_get(self.runner, self.vars.mime_type), diff=True, change=True) + + def __run__(self): + check_mode_return = (0, 'Module executed in check mode', '') + if self.vars.has_changed("handler"): + with self.runner.context(args_order=["mime_type", "handler"], check_mode_skip=True, check_mode_return=check_mode_return) as ctx: + rc, out, err = ctx.run() + self.vars.stdout = out + self.vars.stderr = err + if self.verbosity >= 4: + self.vars.run_info = ctx.run_info + + +def main(): + GioMime.execute() + + +if __name__ == '__main__': + main() diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 730c978bff2..964831eeedc 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -26,3 +26,4 @@ plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/xfconf.py validate-modules:return-syntax-error tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.6 # django generated code tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.7 # django generated code +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 801a80d592e..d082211c90d 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -19,3 +19,4 @@ plugins/modules/rax.py use-argspec-type-path plugins/modules/read_csv.py validate-modules:invalid-documentation plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/xfconf.py validate-modules:return-syntax-error +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes diff --git a/tests/sanity/ignore-2.13.txt b/tests/sanity/ignore-2.13.txt index e5799d312b6..8dae95713cf 100644 --- a/tests/sanity/ignore-2.13.txt +++ b/tests/sanity/ignore-2.13.txt @@ -21,3 +21,4 @@ plugins/modules/rax.py use-argspec-type-path plugins/modules/read_csv.py validate-modules:invalid-documentation plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/xfconf.py validate-modules:return-syntax-error +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 390270caa1a..135d5260e5a 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -23,3 +23,4 @@ plugins/modules/read_csv.py validate-modules:invalid-documentation plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt' plugins/modules/xfconf.py validate-modules:return-syntax-error +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index f94c184eed1..ebb9af9aebc 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -20,3 +20,4 @@ plugins/modules/rax.py use-argspec-type-path plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt' plugins/modules/xfconf.py validate-modules:return-syntax-error +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index a364d8dc0f1..fb940fbb514 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -21,3 +21,4 @@ plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt' plugins/modules/udm_user.py import-3.12 # Uses deprecated stdlib library 'crypt' plugins/modules/xfconf.py validate-modules:return-syntax-error +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes diff --git a/tests/unit/plugins/modules/helper.py b/tests/unit/plugins/modules/helper.py index 94ccfb4f385..db9ebe39818 100644 --- a/tests/unit/plugins/modules/helper.py +++ b/tests/unit/plugins/modules/helper.py @@ -51,9 +51,9 @@ def run(self): test_flags = self.test_flags() if test_flags.get("skip"): - pytest.skip(reason=test_flags["skip"]) + pytest.skip() if test_flags.get("xfail"): - pytest.xfail(reason=test_flags["xfail"]) + pytest.xfail() func() @@ -90,7 +90,7 @@ def check_results(self, results): print("call args list =\n%s" % call_args_list) print("expected args list =\n%s" % expected_call_args_list) - assert self.mock_run_cmd.call_count == len(self.run_cmd_calls) + assert self.mock_run_cmd.call_count == len(self.run_cmd_calls), "{0} != {1}".format(self.mock_run_cmd.call_count, len(self.run_cmd_calls)) if self.mock_run_cmd.call_count: assert call_args_list == expected_call_args_list diff --git a/tests/unit/plugins/modules/test_gio_mime.py b/tests/unit/plugins/modules/test_gio_mime.py new file mode 100644 index 00000000000..664a4290c8f --- /dev/null +++ b/tests/unit/plugins/modules/test_gio_mime.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright (c) Alexei Znamensky (russoz@gmail.com) +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.community.general.plugins.modules import gio_mime +from .helper import Helper + + +helper = Helper.from_file(gio_mime.main, "tests/unit/plugins/modules/test_gio_mime.yaml") +patch_bin = helper.cmd_fixture +test_module = helper.test_module diff --git a/tests/unit/plugins/modules/test_gio_mime.yaml b/tests/unit/plugins/modules/test_gio_mime.yaml new file mode 100644 index 00000000000..d9e47a60ead --- /dev/null +++ b/tests/unit/plugins/modules/test_gio_mime.yaml @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Copyright (c) Alexei Znamensky (russoz@gmail.com) +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +--- +- id: test_set_handler + input: + handler: google-chrome.desktop + mime_type: x-scheme-handler/http + output: + handler: google-chrome.desktop + changed: true + run_command_calls: + - command: [/testbin/gio, mime, x-scheme-handler/http] + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + rc: 0 + out: "" + err: > + No default applications for “x-scheme-handler/http” + - command: [/testbin/gio, mime, x-scheme-handler/http, google-chrome.desktop] + environ: *env-def + rc: 0 + out: "Set google-chrome.desktop as the default for x-scheme-handler/http\n" + err: "" +- id: test_set_handler_check + input: + handler: google-chrome.desktop + mime_type: x-scheme-handler/http + output: + handler: google-chrome.desktop + changed: true + flags: + skip: test helper does not support check mode yet + run_command_calls: + - command: [/testbin/gio, mime, x-scheme-handler/http] + environ: *env-def + rc: 0 + out: "" + err: > + No default applications for “x-scheme-handler/http” + - command: [/testbin/gio, mime, x-scheme-handler/http, google-chrome.desktop] + environ: *env-def + rc: 0 + out: "Set google-chrome.desktop as the default for x-scheme-handler/http\n" + err: "" +- id: test_set_handler_idempot + input: + handler: google-chrome.desktop + mime_type: x-scheme-handler/http + output: + handler: google-chrome.desktop + changed: false + run_command_calls: + - command: [/testbin/gio, mime, x-scheme-handler/http] + environ: *env-def + rc: 0 + out: | + Default application for “x-scheme-handler/https”: google-chrome.desktop + Registered applications: + brave-browser.desktop + firefox.desktop + google-chrome.desktop + firefox_firefox.desktop + Recommended applications: + brave-browser.desktop + firefox.desktop + google-chrome.desktop + firefox_firefox.desktop + err: "" From fc2e6c4b45840165b13468c3d1d5a237aa839909 Mon Sep 17 00:00:00 2001 From: MaxBidlingmaier <103562872+MaxBidlingmaier@users.noreply.github.com> Date: Wed, 20 Sep 2023 19:37:27 +0200 Subject: [PATCH 3/6] Fixed gitlab_*_variable when using purge (#7251) * Fixed gitlab_*_variable when using purge, see issue #7250 * Update changelogs/fragments/7251-gitlab-variables-deleteing-all-variables.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- .../7251-gitlab-variables-deleteing-all-variables.yml | 3 +++ plugins/module_utils/gitlab.py | 2 +- plugins/modules/gitlab_group_variable.py | 2 ++ plugins/modules/gitlab_project_variable.py | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/7251-gitlab-variables-deleteing-all-variables.yml diff --git a/changelogs/fragments/7251-gitlab-variables-deleteing-all-variables.yml b/changelogs/fragments/7251-gitlab-variables-deleteing-all-variables.yml new file mode 100644 index 00000000000..1c8650edae9 --- /dev/null +++ b/changelogs/fragments/7251-gitlab-variables-deleteing-all-variables.yml @@ -0,0 +1,3 @@ +bugfixes: + - gitlab_project_variable - deleted all variables when used with ``purge=true`` due to missing ``raw`` property in KNOWN attributes (https://github.com/ansible-collections/community.general/issues/7250). + - gitlab_group_variable - deleted all variables when used with ``purge=true`` due to missing ``raw`` property in KNOWN attributes (https://github.com/ansible-collections/community.general/issues/7250). diff --git a/plugins/module_utils/gitlab.py b/plugins/module_utils/gitlab.py index e1786c613e9..8c8aab420af 100644 --- a/plugins/module_utils/gitlab.py +++ b/plugins/module_utils/gitlab.py @@ -116,7 +116,7 @@ def gitlab_authentication(module): def filter_returned_variables(gitlab_variables): # pop properties we don't know existing_variables = [dict(x.attributes) for x in gitlab_variables] - KNOWN = ['key', 'value', 'masked', 'protected', 'variable_type', 'environment_scope'] + KNOWN = ['key', 'value', 'masked', 'protected', 'variable_type', 'environment_scope', 'raw'] for item in existing_variables: for key in list(item.keys()): if key not in KNOWN: diff --git a/plugins/modules/gitlab_group_variable.py b/plugins/modules/gitlab_group_variable.py index 60bdc889b39..23591c3d906 100644 --- a/plugins/modules/gitlab_group_variable.py +++ b/plugins/modules/gitlab_group_variable.py @@ -381,6 +381,8 @@ def main(): group=dict(type='str', required=True), purge=dict(type='bool', required=False, default=False), vars=dict(type='dict', required=False, default=dict(), no_log=True), + # please mind whenever changing the variables dict to also change module_utils/gitlab.py's + # KNOWN dict in filter_returned_variables or bad evil will happen variables=dict(type='list', elements='dict', required=False, default=list(), options=dict( name=dict(type='str', required=True), value=dict(type='str', no_log=True), diff --git a/plugins/modules/gitlab_project_variable.py b/plugins/modules/gitlab_project_variable.py index 5b3b9396ded..a7fd90b347b 100644 --- a/plugins/modules/gitlab_project_variable.py +++ b/plugins/modules/gitlab_project_variable.py @@ -404,6 +404,8 @@ def main(): project=dict(type='str', required=True), purge=dict(type='bool', required=False, default=False), vars=dict(type='dict', required=False, default=dict(), no_log=True), + # please mind whenever changing the variables dict to also change module_utils/gitlab.py's + # KNOWN dict in filter_returned_variables or bad evil will happen variables=dict(type='list', elements='dict', required=False, default=list(), options=dict( name=dict(type='str', required=True), value=dict(type='str', no_log=True), From c4009deeb1bf617bfb4fd48a9419e87e8f8efa7b Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 20 Sep 2023 19:39:24 +0200 Subject: [PATCH 4/6] Add ignore for 2.17. --- tests/sanity/ignore-2.17.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt index a364d8dc0f1..fb940fbb514 100644 --- a/tests/sanity/ignore-2.17.txt +++ b/tests/sanity/ignore-2.17.txt @@ -21,3 +21,4 @@ plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice plugins/modules/udm_user.py import-3.11 # Uses deprecated stdlib library 'crypt' plugins/modules/udm_user.py import-3.12 # Uses deprecated stdlib library 'crypt' plugins/modules/xfconf.py validate-modules:return-syntax-error +tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes From 12b48aaa2d946eca5f8dbc8ad47c1bce0971842a Mon Sep 17 00:00:00 2001 From: TSKushal <44438079+TSKushal@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:32:42 +0530 Subject: [PATCH 5/6] Adding SetSecureBoot to redfish_config (#7129) * Changing EnableSecureBoot to SetSecureBoot * Sanity Fix * Adding changelog fragment * Update plugins/modules/redfish_config.py Agreed Co-authored-by: Felix Fontein * Updating PR to just add SetSecureBoot command * Update plugins/modules/redfish_config.py Agreed Co-authored-by: Felix Fontein --------- Co-authored-by: Kushal Co-authored-by: Felix Fontein --- ..._secure_boot_command_to_redfish_config.yml | 2 ++ plugins/module_utils/redfish_utils.py | 19 ++++++++++++++ plugins/modules/redfish_config.py | 26 +++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/7129-adding_set_secure_boot_command_to_redfish_config.yml diff --git a/changelogs/fragments/7129-adding_set_secure_boot_command_to_redfish_config.yml b/changelogs/fragments/7129-adding_set_secure_boot_command_to_redfish_config.yml new file mode 100644 index 00000000000..195dd7df5ae --- /dev/null +++ b/changelogs/fragments/7129-adding_set_secure_boot_command_to_redfish_config.yml @@ -0,0 +1,2 @@ +minor_changes: + - redfish_config - adding ``SetSecureBoot`` command (https://github.com/ansible-collections/community.general/pull/7129). diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 6557dac5bda..fc6e11b3e77 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3432,6 +3432,25 @@ def enable_secure_boot(self): return self.patch_request(self.root_uri + secure_boot_url, body, check_pyld=True) + def set_secure_boot(self, secure_boot_enable): + # This function enable Secure Boot on an OOB controller + + response = self.get_request(self.root_uri + self.systems_uri) + if response["ret"] is False: + return response + + server_details = response["data"] + secure_boot_url = server_details["SecureBoot"]["@odata.id"] + + response = self.get_request(self.root_uri + secure_boot_url) + if response["ret"] is False: + return response + + body = {} + body["SecureBootEnable"] = secure_boot_enable + + return self.patch_request(self.root_uri + secure_boot_url, body, check_pyld=True) + def get_hpe_thermal_config(self): result = {} key = "Thermal" diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index c17dabe0e74..65d933bdbd2 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -145,6 +145,13 @@ default: [] elements: str version_added: '7.3.0' + secure_boot_enable: + required: false + description: + - Setting parameter to enable or disable SecureBoot. + type: bool + default: True + version_added: '7.5.0' author: - "Jose Delarosa (@jose-delarosa)" - "T S Kushal (@TSKushal)" @@ -287,6 +294,15 @@ username: "{{ username }}" password: "{{ password }}" + - name: Set SecureBoot + community.general.redfish_config: + category: Systems + command: SetSecureBoot + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + secure_boot_enable: True + - name: Delete All Volumes community.general.redfish_config: category: Systems @@ -314,7 +330,7 @@ # More will be added as module features are expanded CATEGORY_COMMANDS_ALL = { "Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder", - "SetDefaultBootOrder", "EnableSecureBoot", "DeleteVolumes"], + "SetDefaultBootOrder", "EnableSecureBoot", "SetSecureBoot", "DeleteVolumes"], "Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"], "Sessions": ["SetSessionService"], } @@ -348,7 +364,8 @@ def main(): hostinterface_id=dict(), sessions_config=dict(type='dict', default={}), storage_subsystem_id=dict(type='str', default=''), - volume_ids=dict(type='list', default=[], elements='str') + volume_ids=dict(type='list', default=[], elements='str'), + secure_boot_enable=dict(type='bool', default=True) ), required_together=[ ('username', 'password'), @@ -402,6 +419,9 @@ def main(): storage_subsystem_id = module.params['storage_subsystem_id'] volume_ids = module.params['volume_ids'] + # Set SecureBoot options + secure_boot_enable = module.params['secure_boot_enable'] + # Build root URI root_uri = "https://" + module.params['baseuri'] rf_utils = RedfishUtils(creds, root_uri, timeout, module, @@ -435,6 +455,8 @@ def main(): result = rf_utils.set_default_boot_order() elif command == "EnableSecureBoot": result = rf_utils.enable_secure_boot() + elif command == "SetSecureBoot": + result = rf_utils.set_secure_boot(secure_boot_enable) elif command == "DeleteVolumes": result = rf_utils.delete_volumes(storage_subsystem_id, volume_ids) From 756e8f5cca2a1d150ec7af237f93c082fe679c4b Mon Sep 17 00:00:00 2001 From: bontreger Date: Wed, 20 Sep 2023 16:02:54 -0400 Subject: [PATCH 6/6] Update from_csv.py docs (#7296) Typo fix --- plugins/filter/from_csv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/filter/from_csv.py b/plugins/filter/from_csv.py index 7af655d6f73..310138d496e 100644 --- a/plugins/filter/from_csv.py +++ b/plugins/filter/from_csv.py @@ -56,7 +56,7 @@ - name: Parse a CSV file's contents ansible.builtin.debug: msg: >- - {{ csv_data | community.genera.from_csv(dialect='unix') }} + {{ csv_data | community.general.from_csv(dialect='unix') }} vars: csv_data: | Column 1,Value