From cd43bd10bbf4401582ef2305dfc74286b9da05a2 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 9 Oct 2024 15:32:23 +0900 Subject: [PATCH 1/7] Revert "Merge pull request #556 from Akasurde/i350" This reverts commit 9a2ddcd713c9337ba70942028ff52bb868acfabd, reversing changes made to 7d219a7e05f8a748b984d2755dda8fb7ce8f8473. --- .github/BOTMETA.yml | 1 + meta/runtime.yml | 8 ++++++- plugins/callback/skippy.py | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 plugins/callback/skippy.py diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index ba8b798..60ae92a 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -40,6 +40,7 @@ files: labels: debug $plugins/patch.py: labels: patch + $plugins/skippy.py: $plugins/synchronize.py: labels: synchronize $plugins/timer.py: diff --git a/meta/runtime.yml b/meta/runtime.yml index 1e85b01..a96714c 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,2 +1,8 @@ --- -requires_ansible: ">=2.15.0" +requires_ansible: ">=2.14.0" +plugin_routing: + callback: + skippy: + deprecation: + removal_date: "2022-06-01" + warning_text: See the plugin documentation for more details diff --git a/plugins/callback/skippy.py b/plugins/callback/skippy.py new file mode 100644 index 0000000..ced28af --- /dev/null +++ b/plugins/callback/skippy.py @@ -0,0 +1,43 @@ +# (c) 2012-2014, Michael DeHaan +# (c) 2017 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = ''' + name: skippy + type: stdout + requirements: + - set as main display callback + short_description: Ansible screen output that ignores skipped status + deprecated: + why: The 'default' callback plugin now supports this functionality + removed_at_date: '2022-06-01' + alternative: "'default' callback plugin with 'display_skipped_hosts = no' option" + extends_documentation_fragment: + - default_callback + description: + - This callback does the same as the default except it does not output skipped host/task/item status +''' + +from ansible.plugins.callback.default import CallbackModule as CallbackModule_default + + +class CallbackModule(CallbackModule_default): + + ''' + This is the default callback interface, which simply prints messages + to stdout when new callback events are received. + ''' + + CALLBACK_VERSION = 2.0 + CALLBACK_TYPE = 'stdout' + CALLBACK_NAME = 'ansible.posix.skippy' + + def v2_runner_on_skipped(self, result): + pass + + def v2_runner_item_on_skipped(self, result): + pass From 3a085b0b10e33395630733d4368d408fc781a48d Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 9 Oct 2024 15:32:45 +0900 Subject: [PATCH 2/7] Revert "Merge pull request #387 from ansiblejunky/fix-callback-output" This reverts commit f4baa4c6d8e5ec989887a2b5f4abde24c9e12cbb, reversing changes made to 0821768bcbac58ace4fdf0c95b89007a925d6556. --- changelogs/fragments/387_callback_output_header.yml | 3 --- plugins/callback/profile_roles.py | 5 +---- plugins/callback/profile_tasks.py | 5 +---- plugins/callback/timer.py | 4 +--- 4 files changed, 3 insertions(+), 14 deletions(-) delete mode 100644 changelogs/fragments/387_callback_output_header.yml diff --git a/changelogs/fragments/387_callback_output_header.yml b/changelogs/fragments/387_callback_output_header.yml deleted file mode 100644 index 5eb8573..0000000 --- a/changelogs/fragments/387_callback_output_header.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -minor_changes: - - callback plugins - Add recap information to timer, profile_roles and profile_tasks callback outputs (https://github.com/ansible-collections/ansible.posix/pull/387). diff --git a/plugins/callback/profile_roles.py b/plugins/callback/profile_roles.py index 270a74f..59a437f 100644 --- a/plugins/callback/profile_roles.py +++ b/plugins/callback/profile_roles.py @@ -128,10 +128,7 @@ class CallbackModule(CallbackBase): self._display_tasktime() def playbook_on_stats(self, stats): - # Align summary report header with other callback plugin summary - self._display.banner("ROLES RECAP") - - self._display.display(tasktime()) + self._display_tasktime() self._display.display(filled("", fchar="=")) timestamp(self) diff --git a/plugins/callback/profile_tasks.py b/plugins/callback/profile_tasks.py index c5cc5fe..5fb7972 100644 --- a/plugins/callback/profile_tasks.py +++ b/plugins/callback/profile_tasks.py @@ -193,10 +193,7 @@ class CallbackModule(CallbackBase): self._display_tasktime() def playbook_on_stats(self, stats): - # Align summary report header with other callback plugin summary - self._display.banner("TASKS RECAP") - - self._display.display(tasktime()) + self._display_tasktime() self._display.display(filled("", fchar="=")) timestamp(self) diff --git a/plugins/callback/timer.py b/plugins/callback/timer.py index e2eca05..3ef9255 100644 --- a/plugins/callback/timer.py +++ b/plugins/callback/timer.py @@ -46,6 +46,4 @@ class CallbackModule(CallbackBase): def v2_playbook_on_stats(self, stats): end_time = datetime.utcnow() runtime = end_time - self.start_time - # Align summary report header with other callback plugin summary - self._display.banner("PLAYBOOK RECAP") - self._display.display("Playbook run took %s days, %s hours, %s minutes, %s seconds\n\r" % (self.days_hours_minutes_seconds(runtime))) + self._display.display("Playbook run took %s days, %s hours, %s minutes, %s seconds" % (self.days_hours_minutes_seconds(runtime))) From 098b5bee701554b0b533eb0d2ef8fca45b8ee456 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 9 Oct 2024 15:33:16 +0900 Subject: [PATCH 3/7] Revert "Merge pull request #568 from abakanovskii/feature/add_path_option_authorized_key" This reverts commit 0821768bcbac58ace4fdf0c95b89007a925d6556, reversing changes made to 5321a9ecb58a1b840a9256725ca45f35c28da8c4. --- .../fragments/568_update_authorized_key.yml | 3 -- plugins/modules/authorized_key.py | 23 +------------ .../targets/authorized_key/defaults/main.yml | 2 -- .../authorized_key/tasks/check_path.yml | 32 ------------------- .../targets/authorized_key/tasks/main.yml | 3 -- 5 files changed, 1 insertion(+), 62 deletions(-) delete mode 100644 changelogs/fragments/568_update_authorized_key.yml delete mode 100644 tests/integration/targets/authorized_key/tasks/check_path.yml diff --git a/changelogs/fragments/568_update_authorized_key.yml b/changelogs/fragments/568_update_authorized_key.yml deleted file mode 100644 index 7efa29c..0000000 --- a/changelogs/fragments/568_update_authorized_key.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -minor_changes: - - authorized_keys - allow using absolute path to a file as a SSH key(s) source (https://github.com/ansible-collections/ansible.posix/pull/568) diff --git a/plugins/modules/authorized_key.py b/plugins/modules/authorized_key.py index 1d68b4e..9fbc610 100644 --- a/plugins/modules/authorized_key.py +++ b/plugins/modules/authorized_key.py @@ -24,7 +24,6 @@ options: key: description: - The SSH public key(s), as a string or (since Ansible 1.9) url (https://github.com/username.keys). - - You can also use V(file://) prefix to search remote for a file with SSH key(s). type: str required: true path: @@ -97,12 +96,6 @@ EXAMPLES = r''' state: present key: https://github.com/charlie.keys -- name: Set authorized keys taken from path on controller node - ansible.posix.authorized_key: - user: charlie - state: present - key: file:///home/charlie/.ssh/id_rsa.pub - - name: Set authorized keys taken from url using lookup ansible.posix.authorized_key: user: charlie @@ -230,7 +223,6 @@ from operator import itemgetter from ansible.module_utils._text import to_native from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url -from ansible.module_utils.six.moves.urllib.parse import urlparse class keydict(dict): @@ -564,7 +556,7 @@ def enforce_state(module, params): follow = params.get('follow', False) error_msg = "Error getting key from: %s" - # if the key is a url or file, request it and use it as key source + # if the key is a url, request it and use it as key source if key.startswith("http"): try: resp, info = fetch_url(module, key) @@ -578,19 +570,6 @@ def enforce_state(module, params): # resp.read gives bytes on python3, convert to native string type key = to_native(key, errors='surrogate_or_strict') - if key.startswith("file"): - # if the key is an absolute path, check for existense and use it as a key source - key_path = urlparse(key).path - if not os.path.exists(key_path): - module.fail_json(msg="Path to a key file not found: %s" % key_path) - if not os.path.isfile(key_path): - module.fail_json(msg="Path to a key is a directory and must be a file: %s" % key_path) - try: - with open(key_path, 'r') as source_fh: - key = source_fh.read() - except OSError as e: - module.fail_json(msg="Failed to read key file %s : %s" % (key_path, to_native(e))) - # extract individual keys into an array, skipping blank lines and comments new_keys = [s for s in key.splitlines() if s and not s.startswith('#')] diff --git a/tests/integration/targets/authorized_key/defaults/main.yml b/tests/integration/targets/authorized_key/defaults/main.yml index 7ec99ca..1b60f8c 100644 --- a/tests/integration/targets/authorized_key/defaults/main.yml +++ b/tests/integration/targets/authorized_key/defaults/main.yml @@ -35,5 +35,3 @@ multiple_keys_comments: | ssh-rsa DATA_BASIC 1@testing # I like adding comments yo-dude-this-is-not-a-key INVALID_DATA 2@testing ecdsa-sha2-nistp521 ECDSA_DATA 4@testing - -key_path: /tmp/id_rsa.pub diff --git a/tests/integration/targets/authorized_key/tasks/check_path.yml b/tests/integration/targets/authorized_key/tasks/check_path.yml deleted file mode 100644 index df5d46e..0000000 --- a/tests/integration/targets/authorized_key/tasks/check_path.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- -- name: Create key file for test - ansible.builtin.copy: - dest: "{{ key_path }}" - content: "{{ rsa_key_basic }}" - mode: "0600" - -- name: Add key using path - ansible.posix.authorized_key: - user: root - key: file://{{ key_path }} - state: present - path: "{{ output_dir | expanduser }}/authorized_keys" - register: result - -- name: Assert that the key was added - ansible.builtin.assert: - that: - - result.changed == true - -- name: Add key using path again - ansible.posix.authorized_key: - user: root - key: file://{{ key_path }} - state: present - path: "{{ output_dir | expanduser }}/authorized_keys" - register: result - -- name: Assert that no changes were applied - ansible.builtin.assert: - that: - - result.changed == false diff --git a/tests/integration/targets/authorized_key/tasks/main.yml b/tests/integration/targets/authorized_key/tasks/main.yml index d687f17..6a22838 100644 --- a/tests/integration/targets/authorized_key/tasks/main.yml +++ b/tests/integration/targets/authorized_key/tasks/main.yml @@ -31,6 +31,3 @@ - name: Test for the management of comments with key ansible.builtin.import_tasks: comments.yml - -- name: Test for specifying key as a path - ansible.builtin.import_tasks: check_path.yml From 9df5aac2a55661147d541a5778cf8fa6127e0b8f Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 9 Oct 2024 15:36:53 +0900 Subject: [PATCH 4/7] Revert "Revert "Merge pull request #556 from Akasurde/i350"" This reverts commit cd43bd10bbf4401582ef2305dfc74286b9da05a2. --- .github/BOTMETA.yml | 1 - meta/runtime.yml | 8 +------ plugins/callback/skippy.py | 43 -------------------------------------- 3 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 plugins/callback/skippy.py diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 60ae92a..ba8b798 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -40,7 +40,6 @@ files: labels: debug $plugins/patch.py: labels: patch - $plugins/skippy.py: $plugins/synchronize.py: labels: synchronize $plugins/timer.py: diff --git a/meta/runtime.yml b/meta/runtime.yml index a96714c..1e85b01 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,8 +1,2 @@ --- -requires_ansible: ">=2.14.0" -plugin_routing: - callback: - skippy: - deprecation: - removal_date: "2022-06-01" - warning_text: See the plugin documentation for more details +requires_ansible: ">=2.15.0" diff --git a/plugins/callback/skippy.py b/plugins/callback/skippy.py deleted file mode 100644 index ced28af..0000000 --- a/plugins/callback/skippy.py +++ /dev/null @@ -1,43 +0,0 @@ -# (c) 2012-2014, Michael DeHaan -# (c) 2017 Ansible Project -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -DOCUMENTATION = ''' - name: skippy - type: stdout - requirements: - - set as main display callback - short_description: Ansible screen output that ignores skipped status - deprecated: - why: The 'default' callback plugin now supports this functionality - removed_at_date: '2022-06-01' - alternative: "'default' callback plugin with 'display_skipped_hosts = no' option" - extends_documentation_fragment: - - default_callback - description: - - This callback does the same as the default except it does not output skipped host/task/item status -''' - -from ansible.plugins.callback.default import CallbackModule as CallbackModule_default - - -class CallbackModule(CallbackModule_default): - - ''' - This is the default callback interface, which simply prints messages - to stdout when new callback events are received. - ''' - - CALLBACK_VERSION = 2.0 - CALLBACK_TYPE = 'stdout' - CALLBACK_NAME = 'ansible.posix.skippy' - - def v2_runner_on_skipped(self, result): - pass - - def v2_runner_item_on_skipped(self, result): - pass From 57be05289c71e09b71d3007107976b019ad4367b Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 9 Oct 2024 15:41:22 +0900 Subject: [PATCH 5/7] Revert "Revert "Merge pull request #387 from ansiblejunky/fix-callback-output"" This reverts commit 3a085b0b10e33395630733d4368d408fc781a48d. --- changelogs/fragments/387_callback_output_header.yml | 3 +++ plugins/callback/profile_roles.py | 5 ++++- plugins/callback/profile_tasks.py | 5 ++++- plugins/callback/timer.py | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/387_callback_output_header.yml diff --git a/changelogs/fragments/387_callback_output_header.yml b/changelogs/fragments/387_callback_output_header.yml new file mode 100644 index 0000000..5eb8573 --- /dev/null +++ b/changelogs/fragments/387_callback_output_header.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - callback plugins - Add recap information to timer, profile_roles and profile_tasks callback outputs (https://github.com/ansible-collections/ansible.posix/pull/387). diff --git a/plugins/callback/profile_roles.py b/plugins/callback/profile_roles.py index 59a437f..270a74f 100644 --- a/plugins/callback/profile_roles.py +++ b/plugins/callback/profile_roles.py @@ -128,7 +128,10 @@ class CallbackModule(CallbackBase): self._display_tasktime() def playbook_on_stats(self, stats): - self._display_tasktime() + # Align summary report header with other callback plugin summary + self._display.banner("ROLES RECAP") + + self._display.display(tasktime()) self._display.display(filled("", fchar="=")) timestamp(self) diff --git a/plugins/callback/profile_tasks.py b/plugins/callback/profile_tasks.py index 5fb7972..c5cc5fe 100644 --- a/plugins/callback/profile_tasks.py +++ b/plugins/callback/profile_tasks.py @@ -193,7 +193,10 @@ class CallbackModule(CallbackBase): self._display_tasktime() def playbook_on_stats(self, stats): - self._display_tasktime() + # Align summary report header with other callback plugin summary + self._display.banner("TASKS RECAP") + + self._display.display(tasktime()) self._display.display(filled("", fchar="=")) timestamp(self) diff --git a/plugins/callback/timer.py b/plugins/callback/timer.py index 3ef9255..e2eca05 100644 --- a/plugins/callback/timer.py +++ b/plugins/callback/timer.py @@ -46,4 +46,6 @@ class CallbackModule(CallbackBase): def v2_playbook_on_stats(self, stats): end_time = datetime.utcnow() runtime = end_time - self.start_time - self._display.display("Playbook run took %s days, %s hours, %s minutes, %s seconds" % (self.days_hours_minutes_seconds(runtime))) + # Align summary report header with other callback plugin summary + self._display.banner("PLAYBOOK RECAP") + self._display.display("Playbook run took %s days, %s hours, %s minutes, %s seconds\n\r" % (self.days_hours_minutes_seconds(runtime))) From 906bbb88b7388618c6736e40120795eb47352af2 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 9 Oct 2024 15:41:37 +0900 Subject: [PATCH 6/7] Revert "Revert "Merge pull request #568 from abakanovskii/feature/add_path_option_authorized_key"" This reverts commit 098b5bee701554b0b533eb0d2ef8fca45b8ee456. --- .../fragments/568_update_authorized_key.yml | 3 ++ plugins/modules/authorized_key.py | 23 ++++++++++++- .../targets/authorized_key/defaults/main.yml | 2 ++ .../authorized_key/tasks/check_path.yml | 32 +++++++++++++++++++ .../targets/authorized_key/tasks/main.yml | 3 ++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/568_update_authorized_key.yml create mode 100644 tests/integration/targets/authorized_key/tasks/check_path.yml diff --git a/changelogs/fragments/568_update_authorized_key.yml b/changelogs/fragments/568_update_authorized_key.yml new file mode 100644 index 0000000..7efa29c --- /dev/null +++ b/changelogs/fragments/568_update_authorized_key.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - authorized_keys - allow using absolute path to a file as a SSH key(s) source (https://github.com/ansible-collections/ansible.posix/pull/568) diff --git a/plugins/modules/authorized_key.py b/plugins/modules/authorized_key.py index 9fbc610..1d68b4e 100644 --- a/plugins/modules/authorized_key.py +++ b/plugins/modules/authorized_key.py @@ -24,6 +24,7 @@ options: key: description: - The SSH public key(s), as a string or (since Ansible 1.9) url (https://github.com/username.keys). + - You can also use V(file://) prefix to search remote for a file with SSH key(s). type: str required: true path: @@ -96,6 +97,12 @@ EXAMPLES = r''' state: present key: https://github.com/charlie.keys +- name: Set authorized keys taken from path on controller node + ansible.posix.authorized_key: + user: charlie + state: present + key: file:///home/charlie/.ssh/id_rsa.pub + - name: Set authorized keys taken from url using lookup ansible.posix.authorized_key: user: charlie @@ -223,6 +230,7 @@ from operator import itemgetter from ansible.module_utils._text import to_native from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url +from ansible.module_utils.six.moves.urllib.parse import urlparse class keydict(dict): @@ -556,7 +564,7 @@ def enforce_state(module, params): follow = params.get('follow', False) error_msg = "Error getting key from: %s" - # if the key is a url, request it and use it as key source + # if the key is a url or file, request it and use it as key source if key.startswith("http"): try: resp, info = fetch_url(module, key) @@ -570,6 +578,19 @@ def enforce_state(module, params): # resp.read gives bytes on python3, convert to native string type key = to_native(key, errors='surrogate_or_strict') + if key.startswith("file"): + # if the key is an absolute path, check for existense and use it as a key source + key_path = urlparse(key).path + if not os.path.exists(key_path): + module.fail_json(msg="Path to a key file not found: %s" % key_path) + if not os.path.isfile(key_path): + module.fail_json(msg="Path to a key is a directory and must be a file: %s" % key_path) + try: + with open(key_path, 'r') as source_fh: + key = source_fh.read() + except OSError as e: + module.fail_json(msg="Failed to read key file %s : %s" % (key_path, to_native(e))) + # extract individual keys into an array, skipping blank lines and comments new_keys = [s for s in key.splitlines() if s and not s.startswith('#')] diff --git a/tests/integration/targets/authorized_key/defaults/main.yml b/tests/integration/targets/authorized_key/defaults/main.yml index 1b60f8c..7ec99ca 100644 --- a/tests/integration/targets/authorized_key/defaults/main.yml +++ b/tests/integration/targets/authorized_key/defaults/main.yml @@ -35,3 +35,5 @@ multiple_keys_comments: | ssh-rsa DATA_BASIC 1@testing # I like adding comments yo-dude-this-is-not-a-key INVALID_DATA 2@testing ecdsa-sha2-nistp521 ECDSA_DATA 4@testing + +key_path: /tmp/id_rsa.pub diff --git a/tests/integration/targets/authorized_key/tasks/check_path.yml b/tests/integration/targets/authorized_key/tasks/check_path.yml new file mode 100644 index 0000000..df5d46e --- /dev/null +++ b/tests/integration/targets/authorized_key/tasks/check_path.yml @@ -0,0 +1,32 @@ +--- +- name: Create key file for test + ansible.builtin.copy: + dest: "{{ key_path }}" + content: "{{ rsa_key_basic }}" + mode: "0600" + +- name: Add key using path + ansible.posix.authorized_key: + user: root + key: file://{{ key_path }} + state: present + path: "{{ output_dir | expanduser }}/authorized_keys" + register: result + +- name: Assert that the key was added + ansible.builtin.assert: + that: + - result.changed == true + +- name: Add key using path again + ansible.posix.authorized_key: + user: root + key: file://{{ key_path }} + state: present + path: "{{ output_dir | expanduser }}/authorized_keys" + register: result + +- name: Assert that no changes were applied + ansible.builtin.assert: + that: + - result.changed == false diff --git a/tests/integration/targets/authorized_key/tasks/main.yml b/tests/integration/targets/authorized_key/tasks/main.yml index 6a22838..d687f17 100644 --- a/tests/integration/targets/authorized_key/tasks/main.yml +++ b/tests/integration/targets/authorized_key/tasks/main.yml @@ -31,3 +31,6 @@ - name: Test for the management of comments with key ansible.builtin.import_tasks: comments.yml + +- name: Test for specifying key as a path + ansible.builtin.import_tasks: check_path.yml From 4d928119de1ee5b7ff65218361e1f62ce460d2ab Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Fri, 11 Oct 2024 16:20:27 +0900 Subject: [PATCH 7/7] Bump version 2.0.0 for the next release * main branch Signed-off-by: Hideki Saito --- changelogs/fragments/576_bump_version_2.yml | 3 +++ galaxy.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/576_bump_version_2.yml diff --git a/changelogs/fragments/576_bump_version_2.yml b/changelogs/fragments/576_bump_version_2.yml new file mode 100644 index 0000000..a93dbf6 --- /dev/null +++ b/changelogs/fragments/576_bump_version_2.yml @@ -0,0 +1,3 @@ +--- +trivial: + - Bump ansible.posix version to 2.0.0. diff --git a/galaxy.yml b/galaxy.yml index 8565e64..01e619c 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: ansible name: posix -version: 1.6.1 +version: 2.0.0 readme: README.md authors: - Ansible (github.com/ansible)