From 18469dbb3e3bf92492c141e8f685fc495f05111a Mon Sep 17 00:00:00 2001 From: dkjii Date: Fri, 2 Apr 2021 09:50:36 -0400 Subject: [PATCH 001/109] ansible.posix.mount: add absent_from_fstab option --- plugins/modules/mount.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index e7ce7ee..31ea269 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -78,9 +78,12 @@ options: if I(opts) is set, and the remount command fails, the module will error to prevent unexpected mount changes. Try using C(mounted) instead to work around this issue. + - C(absent_from_fstab) specifies that the device mount's entry will be + removed from I(fstab). This option does not unmount it or delete the + mountpoint. type: str required: true - choices: [ absent, mounted, present, unmounted, remounted ] + choices: [ absent, absent_from_fstab, mounted, present, unmounted, remounted ] fstab: description: - File to use instead of C(/etc/fstab). @@ -651,7 +654,7 @@ def main(): passno=dict(type='str', no_log=False), src=dict(type='path'), backup=dict(type='bool', default=False), - state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted']), + state=dict(type='str', required=True, choices=['absent', 'absent_from_fstab', 'mounted', 'present', 'unmounted', 'remounted']), ), supports_check_mode=True, required_if=( @@ -734,7 +737,9 @@ def main(): name = module.params['path'] changed = False - if state == 'absent': + if state == 'absent_from_fstab': + name, changed = unset_mount(module, args) + elif state == 'absent': name, changed = unset_mount(module, args) if changed and not module.check_mode: From 20e294e0264647f4aa2078ad0eaf320ba2ee1879 Mon Sep 17 00:00:00 2001 From: dkjii Date: Fri, 2 Apr 2021 12:33:58 -0400 Subject: [PATCH 002/109] add changelog --- changelogs/fragments/166_mount_absent_fstab.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/166_mount_absent_fstab.yml diff --git a/changelogs/fragments/166_mount_absent_fstab.yml b/changelogs/fragments/166_mount_absent_fstab.yml new file mode 100644 index 0000000..2f7400c --- /dev/null +++ b/changelogs/fragments/166_mount_absent_fstab.yml @@ -0,0 +1,2 @@ +minor_changes: +- mount - Add absent_from_fstab state From 553b0ea4f74c2c4e0d0d3252bc57b1dabed54913 Mon Sep 17 00:00:00 2001 From: dkjii-g <41760646+dkjii-g@users.noreply.github.com> Date: Fri, 2 Apr 2021 21:00:51 -0400 Subject: [PATCH 003/109] Update changelogs/fragments/166_mount_absent_fstab.yml Co-authored-by: Amin Vakil --- changelogs/fragments/166_mount_absent_fstab.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/166_mount_absent_fstab.yml b/changelogs/fragments/166_mount_absent_fstab.yml index 2f7400c..be11324 100644 --- a/changelogs/fragments/166_mount_absent_fstab.yml +++ b/changelogs/fragments/166_mount_absent_fstab.yml @@ -1,2 +1,2 @@ minor_changes: -- mount - Add absent_from_fstab state + - mount - Add ``absent_from_fstab`` state (https://github.com/ansible-collections/ansible.posix/pull/166). From 373250a0ce1f873192a96898c6dcee259ca0f57c Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Thu, 31 Mar 2022 11:33:51 +0900 Subject: [PATCH 004/109] Copy ignore-2.13.txt to ignore-2.14.txt - Relates to ansible-collections/news-for-maintainers#13 Signed-off-by: Hideki Saito --- changelogs/fragments/346_copy_ignore_txt_for_devel.yml | 3 +++ tests/sanity/ignore-2.14.txt | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/346_copy_ignore_txt_for_devel.yml create mode 100644 tests/sanity/ignore-2.14.txt diff --git a/changelogs/fragments/346_copy_ignore_txt_for_devel.yml b/changelogs/fragments/346_copy_ignore_txt_for_devel.yml new file mode 100644 index 0000000..053d865 --- /dev/null +++ b/changelogs/fragments/346_copy_ignore_txt_for_devel.yml @@ -0,0 +1,3 @@ +--- +trivial: +- CI tests - create ignore file for 2.14.0.dev0 (https://github.com/ansible-collections/ansible.posix/issues/345). diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt new file mode 100644 index 0000000..0b6905e --- /dev/null +++ b/tests/sanity/ignore-2.14.txt @@ -0,0 +1,8 @@ +plugins/modules/synchronize.py pylint:disallowed-name +plugins/modules/synchronize.py use-argspec-type-path +plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec +plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented +plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc +plugins/modules/synchronize.py validate-modules:undocumented-parameter +tests/utils/shippable/check_matrix.py replace-urlopen +tests/utils/shippable/timing.py shebang From def5d2bae04fd5deda4f2260ecc2afa39c503f22 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Thu, 31 Mar 2022 13:18:11 +0900 Subject: [PATCH 005/109] Add testing against ansible-core 2.13 - Relates to ansible-collections/news-for-maintainers#14 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 40 +++++++++++++++++++++ README.md | 3 +- changelogs/fragments/347_add_branch_213.yml | 3 ++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/347_add_branch_213.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index e2ac310..e8003df 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -63,6 +63,26 @@ stages: test: ubuntu1804 - name: Ubuntu 20.04 test: ubuntu2004 + - stage: Docker_2_13 + displayName: Docker 2.13 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.13/linux/{0}/1 + targets: + - name: CentOS 7 + test: centos7 + - name: Fedora 34 + test: fedora34 + - name: Fedora 35 + test: fedora35 + - name: openSUSE 15 py3 + test: opensuse15 + - name: Ubuntu 18.04 + test: ubuntu1804 + - name: Ubuntu 20.04 + test: ubuntu2004 - stage: Docker_2_12 displayName: Docker 2.12 dependsOn: [] @@ -179,6 +199,24 @@ stages: test: freebsd/12.3 - name: FreeBSD 13.0 test: freebsd/13.0 + - stage: Remote_2_13 + displayName: Remote 2.13 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.13/{0}/1 + targets: + - name: MacOS 12.0 + test: macos/12.0 + - name: RHEL 7.9 + test: rhel/7.9 + - name: RHEL 8.5 + test: rhel/8.5 + - name: FreeBSD 12.3 + test: freebsd/12.3 + - name: FreeBSD 13.0 + test: freebsd/13.0 - stage: Remote_2_12 displayName: Remote 2.12 dependsOn: [] @@ -265,6 +303,8 @@ stages: - Docker_2_11 - Remote_2_12 - Docker_2_12 + - Remote_2_13 + - Docker_2_13 - Remote_devel - Docker_devel jobs: diff --git a/README.md b/README.md index 9144f77..9542c96 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,8 @@ None -* ansible-core 2.13 (devel) +* ansible-core 2.14 (devel) +- ansible-core 2.13 (stable) * ansible-core 2.12 (stable) * ansible-core 2.11 (stable) * ansible-base 2.10 (stable) diff --git a/changelogs/fragments/347_add_branch_213.yml b/changelogs/fragments/347_add_branch_213.yml new file mode 100644 index 0000000..846850f --- /dev/null +++ b/changelogs/fragments/347_add_branch_213.yml @@ -0,0 +1,3 @@ +--- +trivial: +- CI tests - add CI tests against stable-2.13 (https://github.com/ansible-collections/ansible.posix/issues/345). From 0e71c0e53090ca6894687a30b37921aeb313f809 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Fri, 1 Apr 2022 12:22:20 +0900 Subject: [PATCH 006/109] Fixed documentation and options to address new sanity tests - https://docs.ansible.com/ansible/latest/dev_guide/testing_validate-modules.html Signed-off-by: Hideki Saito --- README.md | 10 +++++----- changelogs/fragments/349_follow_new_guidelines.yml | 3 +++ meta/runtime.yml | 6 ++++++ plugins/callback/cgroup_perf_recap.py | 4 ++-- plugins/callback/debug.py | 2 +- plugins/callback/json.py | 2 +- plugins/callback/profile_roles.py | 2 +- plugins/callback/profile_tasks.py | 2 +- plugins/callback/skippy.py | 12 ++++++------ plugins/callback/timer.py | 4 ++-- plugins/modules/mount.py | 8 ++++---- plugins/shell/csh.py | 9 ++++----- plugins/shell/fish.py | 9 ++++----- 13 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 changelogs/fragments/349_follow_new_guidelines.yml diff --git a/README.md b/README.md index 9542c96..33511ce 100644 --- a/README.md +++ b/README.md @@ -86,12 +86,12 @@ None -* ansible-core 2.14 (devel) +- ansible-core 2.14 (devel) - ansible-core 2.13 (stable) -* ansible-core 2.12 (stable) -* ansible-core 2.11 (stable) -* ansible-base 2.10 (stable) -* ansible 2.9 (stable) +- ansible-core 2.12 (stable) +- ansible-core 2.11 (stable) +- ansible-base 2.10 (stable) +- ansible 2.9 (stable) ## Roadmap diff --git a/changelogs/fragments/349_follow_new_guidelines.yml b/changelogs/fragments/349_follow_new_guidelines.yml new file mode 100644 index 0000000..2b13e12 --- /dev/null +++ b/changelogs/fragments/349_follow_new_guidelines.yml @@ -0,0 +1,3 @@ +--- +trivial: +- CI tests - following the new sanity check guideline (https://github.com/ansible-collections/ansible.posix/issues/348). diff --git a/meta/runtime.yml b/meta/runtime.yml index 43bbe45..f43de48 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,2 +1,8 @@ --- requires_ansible: '>=2.9' +plugin_routing: + callback: + skippy: + deprecation: + removal_date: '2022-06-01' + warning_text: See the plugin documentation for more details diff --git a/plugins/callback/cgroup_perf_recap.py b/plugins/callback/cgroup_perf_recap.py index 5313353..d1f4247 100644 --- a/plugins/callback/cgroup_perf_recap.py +++ b/plugins/callback/cgroup_perf_recap.py @@ -11,8 +11,8 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} DOCUMENTATION = ''' - callback: cgroup_perf_recap - callback_type: aggregate + name: cgroup_perf_recap + type: aggregate requirements: - whitelist in configuration - cgroups diff --git a/plugins/callback/debug.py b/plugins/callback/debug.py index a7e1d15..85e0f4e 100644 --- a/plugins/callback/debug.py +++ b/plugins/callback/debug.py @@ -5,7 +5,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' - callback: debug + name: debug type: stdout short_description: formatted stdout/stderr display description: diff --git a/plugins/callback/json.py b/plugins/callback/json.py index a69f38f..f0c56b4 100644 --- a/plugins/callback/json.py +++ b/plugins/callback/json.py @@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' - callback: json + name: json short_description: Ansible screen output as JSON description: - This callback converts all events into JSON output to stdout diff --git a/plugins/callback/profile_roles.py b/plugins/callback/profile_roles.py index fc0346e..13dae0c 100644 --- a/plugins/callback/profile_roles.py +++ b/plugins/callback/profile_roles.py @@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' - callback: profile_roles + name: profile_roles type: aggregate short_description: adds timing information to roles description: diff --git a/plugins/callback/profile_tasks.py b/plugins/callback/profile_tasks.py index e4b5e91..c6118df 100644 --- a/plugins/callback/profile_tasks.py +++ b/plugins/callback/profile_tasks.py @@ -10,7 +10,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' - callback: profile_tasks + name: profile_tasks type: aggregate short_description: adds time information to tasks description: diff --git a/plugins/callback/skippy.py b/plugins/callback/skippy.py index 9c12ee4..ced28af 100644 --- a/plugins/callback/skippy.py +++ b/plugins/callback/skippy.py @@ -7,19 +7,19 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' - callback: skippy - callback_type: stdout + 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" + 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 + - 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 diff --git a/plugins/callback/timer.py b/plugins/callback/timer.py index 7b38d10..3ef9255 100644 --- a/plugins/callback/timer.py +++ b/plugins/callback/timer.py @@ -6,8 +6,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' - callback: timer - callback_type: aggregate + name: timer + type: aggregate requirements: - whitelist in configuration short_description: Adds time to play stats diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 8b28f12..2021464 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -50,7 +50,7 @@ options: with subsequent runs. - Has no effect on Solaris systems. type: str - default: 0 + default: '0' passno: description: - Passno (see fstab(5)). @@ -59,7 +59,7 @@ options: with subsequent runs. - Deprecated on Solaris systems. type: str - default: 0 + default: '0' state: description: - If C(mounted), the device will be actively mounted and appropriately @@ -667,12 +667,12 @@ def main(): module = AnsibleModule( argument_spec=dict( boot=dict(type='bool', default=True), - dump=dict(type='str'), + dump=dict(type='str', default='0'), fstab=dict(type='str'), fstype=dict(type='str'), path=dict(type='path', required=True, aliases=['name']), opts=dict(type='str'), - passno=dict(type='str', no_log=False), + passno=dict(type='str', no_log=False, default='0'), src=dict(type='path'), backup=dict(type='bool', default=False), state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted']), diff --git a/plugins/shell/csh.py b/plugins/shell/csh.py index bce5734..9baae25 100644 --- a/plugins/shell/csh.py +++ b/plugins/shell/csh.py @@ -4,13 +4,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible.module_utils.six import text_type -from ansible.module_utils.six.moves import shlex_quote -from ansible.plugins.shell import ShellBase - DOCUMENTATION = ''' name: csh - plugin_type: shell short_description: C shell (/bin/csh) description: - When you have no other option than to use csh @@ -18,6 +13,10 @@ DOCUMENTATION = ''' - shell_common ''' +from ansible.module_utils.six import text_type +from ansible.module_utils.six.moves import shlex_quote +from ansible.plugins.shell import ShellBase + class ShellModule(ShellBase): diff --git a/plugins/shell/fish.py b/plugins/shell/fish.py index ea13358..b96efa5 100644 --- a/plugins/shell/fish.py +++ b/plugins/shell/fish.py @@ -4,13 +4,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible.module_utils.six import text_type -from ansible.module_utils.six.moves import shlex_quote -from ansible.plugins.shell.sh import ShellModule as ShModule - DOCUMENTATION = ''' name: fish - plugin_type: shell short_description: fish shell (/bin/fish) description: - This is here because some people are restricted to fish. @@ -18,6 +13,10 @@ DOCUMENTATION = ''' - shell_common ''' +from ansible.module_utils.six import text_type +from ansible.module_utils.six.moves import shlex_quote +from ansible.plugins.shell.sh import ShellModule as ShModule + class ShellModule(ShModule): From c520b682765b35cd8067862468a212ddd43049b2 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Fri, 22 Apr 2022 14:07:37 +0900 Subject: [PATCH 007/109] Added check_mode attr to synchronize plugin test * Added check_mode attribute to TaskMock class in the unit test for synchronize plugin * Fixes #352 Signed-off-by: Hideki Saito --- changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml | 3 +++ tests/unit/plugins/action/test_synchronize.py | 1 + 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml diff --git a/changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml b/changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml new file mode 100644 index 0000000..190b9f9 --- /dev/null +++ b/changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml @@ -0,0 +1,3 @@ +--- +trivial: +- CI tests - added check_mode attribute to TaskMock class for synchronize plugin unit test (https://github.com/ansible-collections/ansible.posix/issues/352). diff --git a/tests/unit/plugins/action/test_synchronize.py b/tests/unit/plugins/action/test_synchronize.py index bc1efca..40e489d 100644 --- a/tests/unit/plugins/action/test_synchronize.py +++ b/tests/unit/plugins/action/test_synchronize.py @@ -55,6 +55,7 @@ class TaskMock(object): become = None become_user = None become_method = None + check_mode = False class StdinMock(object): From 33f2ef8f119979e759f7859f248484841736d5f1 Mon Sep 17 00:00:00 2001 From: mandar242 Date: Mon, 25 Apr 2022 15:32:27 -0700 Subject: [PATCH 008/109] Update bindep.txt for adding rhel-9 --- bindep.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/bindep.txt b/bindep.txt index 62151cb..fac394c 100644 --- a/bindep.txt +++ b/bindep.txt @@ -2,3 +2,4 @@ # see https://docs.openstack.org/infra/bindep/ for additional information. rsync [platform:rhel-8] +rsync [platform:rhel-9] From 45519c68bebc3bd8d85344d50232f6cf7c68c241 Mon Sep 17 00:00:00 2001 From: mandar242 Date: Tue, 26 Apr 2022 11:18:58 -0700 Subject: [PATCH 009/109] Modified based on feedback --- bindep.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindep.txt b/bindep.txt index fac394c..fc5997d 100644 --- a/bindep.txt +++ b/bindep.txt @@ -1,5 +1,4 @@ # This is a cross-platform list tracking distribution packages needed by tests; # see https://docs.openstack.org/infra/bindep/ for additional information. -rsync [platform:rhel-8] -rsync [platform:rhel-9] +rsync [platform:rhel-8 platform:rhel-9] From 2ee9cc533a7938e52a78144259091594cdcbdf7a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 16 May 2022 07:27:10 +0200 Subject: [PATCH 010/109] Add PSF-license.txt file. --- PSF-license.txt | 48 ++++++++++++++++++++++++++++ changelogs/fragments/psf-license.yml | 2 ++ plugins/module_utils/_version.py | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 PSF-license.txt create mode 100644 changelogs/fragments/psf-license.yml diff --git a/PSF-license.txt b/PSF-license.txt new file mode 100644 index 0000000..b6bddd8 --- /dev/null +++ b/PSF-license.txt @@ -0,0 +1,48 @@ +PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +-------------------------------------------- + +1. This LICENSE AGREEMENT is between the Python Software Foundation +("PSF"), and the Individual or Organization ("Licensee") accessing and +otherwise using this software ("Python") in source or binary form and +its associated documentation. + +2. Subject to the terms and conditions of this License Agreement, PSF hereby +grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, +analyze, test, perform and/or display publicly, prepare derivative works, +distribute, and otherwise use Python alone or in any derivative version, +provided, however, that PSF's License Agreement and PSF's notice of copyright, +i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, +2011, 2012, 2013, 2014, 2015, 2016, 2017 Python Software Foundation; All Rights +Reserved" are retained in Python alone or in any derivative version prepared by +Licensee. + +3. In the event Licensee prepares a derivative work that is based on +or incorporates Python or any part thereof, and wants to make +the derivative work available to others as provided herein, then +Licensee hereby agrees to include in any such work a brief summary of +the changes made to Python. + +4. PSF is making Python available to Licensee on an "AS IS" +basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +6. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +7. Nothing in this License Agreement shall be deemed to create any +relationship of agency, partnership, or joint venture between PSF and +Licensee. This License Agreement does not grant permission to use PSF +trademarks or trade name in a trademark sense to endorse or promote +products or services of Licensee, or any third party. + +8. By copying, installing or otherwise using Python, Licensee +agrees to be bound by the terms and conditions of this License +Agreement. diff --git a/changelogs/fragments/psf-license.yml b/changelogs/fragments/psf-license.yml new file mode 100644 index 0000000..f8fbc0b --- /dev/null +++ b/changelogs/fragments/psf-license.yml @@ -0,0 +1,2 @@ +bugfixes: + - Include ``PSF-license.txt`` file for ``plugins/module_utils/_version.py``. diff --git a/plugins/module_utils/_version.py b/plugins/module_utils/_version.py index 4ee5820..d91cf3a 100644 --- a/plugins/module_utils/_version.py +++ b/plugins/module_utils/_version.py @@ -3,7 +3,7 @@ # Implements multiple version numbering conventions for the # Python Module Distribution Utilities. # -# PSF License (see licenses/PSF-license.txt or https://opensource.org/licenses/Python-2.0) +# PSF License (see PSF-license.txt or https://opensource.org/licenses/Python-2.0) # """Provides classes to represent module version numbers (one class for From eebfff4eb8579c4eadfa279b8784d85b66e53915 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 16 May 2022 08:00:40 +0200 Subject: [PATCH 011/109] Update with actual CPython 3.9.5 license. --- PSF-license.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PSF-license.txt b/PSF-license.txt index b6bddd8..35acd7f 100644 --- a/PSF-license.txt +++ b/PSF-license.txt @@ -12,9 +12,9 @@ analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -2011, 2012, 2013, 2014, 2015, 2016, 2017 Python Software Foundation; All Rights -Reserved" are retained in Python alone or in any derivative version prepared by -Licensee. +2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Python Software Foundation; +All Rights Reserved" are retained in Python alone or in any derivative version +prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python or any part thereof, and wants to make From ab3bf45c6c8dbb89b7085f9dbc0ab5bb8e241d1d Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 23 May 2022 16:37:36 +0900 Subject: [PATCH 012/109] Release 1.4.0 commit Signed-off-by: Hideki Saito --- CHANGELOG.rst | 28 +++++++++++ README.md | 2 + changelogs/changelog.yaml | 50 +++++++++++++++++++ .../fragments/211_fstab_append_newline.yml | 3 -- changelogs/fragments/247_firewalld.yml | 3 -- .../fragments/254_variable_warnings.yml | 5 -- .../fragments/255_authorized_key_url.yml | 3 -- .../263_profile_tasks_with_serial.yml | 3 -- changelogs/fragments/272-copy_ignore_txt.yml | 3 -- .../277_fix_integration_test_on_devel.yml | 3 -- .../282_fix_unit_test_for_synchronize.yml | 3 -- .../fragments/287_firewalld_requirements.yml | 3 -- changelogs/fragments/288_mounts_options.yml | 3 -- ...7_firewalld_exclusive_options_handling.yml | 3 -- .../fragments/299_seboolean_python3.yml | 3 -- .../fragments/302_shippable_exit_code.yml | 3 -- changelogs/fragments/304_pep632.yml | 3 -- .../346_copy_ignore_txt_for_devel.yml | 3 -- changelogs/fragments/347_add_branch_213.yml | 3 -- .../fragments/349_follow_new_guidelines.yml | 3 -- .../353_ci_fix_unittest_for_synchronize.yml | 3 -- .../disable_selinux_via_kernel_cmdline.yml | 2 - changelogs/fragments/psf-license.yml | 2 - changelogs/fragments/sanity_fixes.yml | 3 -- .../shell_escape_full_path_for_rsync.yml | 3 -- docs/ansible.posix.authorized_key_module.rst | 6 +++ docs/ansible.posix.firewalld_module.rst | 2 + docs/ansible.posix.mount_module.rst | 8 +-- docs/ansible.posix.seboolean_module.rst | 1 + docs/ansible.posix.selinux_module.rst | 21 ++++++++ 30 files changed, 114 insertions(+), 70 deletions(-) delete mode 100644 changelogs/fragments/211_fstab_append_newline.yml delete mode 100644 changelogs/fragments/247_firewalld.yml delete mode 100644 changelogs/fragments/254_variable_warnings.yml delete mode 100644 changelogs/fragments/255_authorized_key_url.yml delete mode 100644 changelogs/fragments/263_profile_tasks_with_serial.yml delete mode 100644 changelogs/fragments/272-copy_ignore_txt.yml delete mode 100644 changelogs/fragments/277_fix_integration_test_on_devel.yml delete mode 100644 changelogs/fragments/282_fix_unit_test_for_synchronize.yml delete mode 100644 changelogs/fragments/287_firewalld_requirements.yml delete mode 100644 changelogs/fragments/288_mounts_options.yml delete mode 100644 changelogs/fragments/297_firewalld_exclusive_options_handling.yml delete mode 100644 changelogs/fragments/299_seboolean_python3.yml delete mode 100644 changelogs/fragments/302_shippable_exit_code.yml delete mode 100644 changelogs/fragments/304_pep632.yml delete mode 100644 changelogs/fragments/346_copy_ignore_txt_for_devel.yml delete mode 100644 changelogs/fragments/347_add_branch_213.yml delete mode 100644 changelogs/fragments/349_follow_new_guidelines.yml delete mode 100644 changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml delete mode 100644 changelogs/fragments/disable_selinux_via_kernel_cmdline.yml delete mode 100644 changelogs/fragments/psf-license.yml delete mode 100644 changelogs/fragments/sanity_fixes.yml delete mode 100644 changelogs/fragments/shell_escape_full_path_for_rsync.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1fd693d..9d1d855 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,34 @@ ansible.posix Release Notes .. contents:: Topics +v1.4.0 +====== + +Release Summary +--------------- + +This is the minor release of the ``ansible.posix`` collection. +This changelog contains all changes to the modules in this collection that +have been added after the release of ``ansible.posix`` 1.3.0. + +Minor Changes +------------- + +- firewalld - Show warning message that variable type of ``masquerade`` and ``icmp_block_inversion`` will be changed from ``str`` to ``boolean`` in the future release (https://github.com/ansible-collections/ansible.posix/pull/254). +- selinux - optionally update kernel boot params when disabling/re-enabling SELinux (https://github.com/ansible-collections/ansible.posix/pull/142). + +Bugfixes +-------- + +- Fix for whitespace in source full path causing error ```code 23) at main.c(1330) [sender=3.2.3]``` (https://github.com/ansible-collections/ansible.posix/pull/278) +- Include ``PSF-license.txt`` file for ``plugins/module_utils/_version.py``. +- Use vendored version of ``distutils.version`` instead of the deprecated Python standard library to address PEP 632 (https://github.com/ansible-collections/ansible.posix/issues/303). +- firewalld - Correct usage of queryForwardPort (https://github.com/ansible-collections/ansible.posix/issues/247). +- firewalld - Refine the handling of exclusive options (https://github.com/ansible-collections/ansible.posix/issues/255). +- mount - add a newline at the end of line in ``fstab`` (https://github.com/ansible-collections/ansible.posix/issues/210). +- profile_tasks - Correctly calculate task execution time with serial execution (https://github.com/ansible-collections/ansible.posix/issues/83). +- seboolean - add ``python3-libsemanage`` package dependency for RHEL8+ systems. + v1.3.0 ====== diff --git a/README.md b/README.md index 33511ce..c0ee2b4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ An Ansible Collection of modules and plugins that target POSIX UNIX/Linux and de This collection has been tested against following Ansible versions: **>=2.9**. +For collections that support Ansible 2.9, please ensure you update your `network_os` to use the +fully qualified collection name (for example, `cisco.ios.ios`). Plugins and modules within a collection may be tested with only specific Ansible versions. A collection may contain metadata that identifies these versions. PEP440 is the schema used to describe the versions of Ansible. diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 828127b..382141c 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -210,3 +210,53 @@ releases: - synchronize.yml - test_matrix.yml release_date: '2021-08-11' + 1.4.0: + changes: + bugfixes: + - Fix for whitespace in source full path causing error ```code 23) at main.c(1330) + [sender=3.2.3]``` (https://github.com/ansible-collections/ansible.posix/pull/278) + - Include ``PSF-license.txt`` file for ``plugins/module_utils/_version.py``. + - Use vendored version of ``distutils.version`` instead of the deprecated Python + standard library to address PEP 632 (https://github.com/ansible-collections/ansible.posix/issues/303). + - firewalld - Correct usage of queryForwardPort (https://github.com/ansible-collections/ansible.posix/issues/247). + - firewalld - Refine the handling of exclusive options (https://github.com/ansible-collections/ansible.posix/issues/255). + - mount - add a newline at the end of line in ``fstab`` (https://github.com/ansible-collections/ansible.posix/issues/210). + - profile_tasks - Correctly calculate task execution time with serial execution + (https://github.com/ansible-collections/ansible.posix/issues/83). + - seboolean - add ``python3-libsemanage`` package dependency for RHEL8+ systems. + minor_changes: + - firewalld - Show warning message that variable type of ``masquerade`` and + ``icmp_block_inversion`` will be changed from ``str`` to ``boolean`` in the + future release (https://github.com/ansible-collections/ansible.posix/pull/254). + - selinux - optionally update kernel boot params when disabling/re-enabling + SELinux (https://github.com/ansible-collections/ansible.posix/pull/142). + release_summary: 'This is the minor release of the ``ansible.posix`` collection. + + This changelog contains all changes to the modules in this collection that + + have been added after the release of ``ansible.posix`` 1.3.0.' + fragments: + - 1.4.0.yml + - 211_fstab_append_newline.yml + - 247_firewalld.yml + - 254_variable_warnings.yml + - 255_authorized_key_url.yml + - 263_profile_tasks_with_serial.yml + - 272-copy_ignore_txt.yml + - 277_fix_integration_test_on_devel.yml + - 282_fix_unit_test_for_synchronize.yml + - 287_firewalld_requirements.yml + - 288_mounts_options.yml + - 297_firewalld_exclusive_options_handling.yml + - 299_seboolean_python3.yml + - 302_shippable_exit_code.yml + - 304_pep632.yml + - 346_copy_ignore_txt_for_devel.yml + - 347_add_branch_213.yml + - 349_follow_new_guidelines.yml + - 353_ci_fix_unittest_for_synchronize.yml + - disable_selinux_via_kernel_cmdline.yml + - psf-license.yml + - sanity_fixes.yml + - shell_escape_full_path_for_rsync.yml + release_date: '2022-05-23' diff --git a/changelogs/fragments/211_fstab_append_newline.yml b/changelogs/fragments/211_fstab_append_newline.yml deleted file mode 100644 index 6861798..0000000 --- a/changelogs/fragments/211_fstab_append_newline.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: -- mount - add a newline at the end of line in ``fstab`` (https://github.com/ansible-collections/ansible.posix/issues/210). diff --git a/changelogs/fragments/247_firewalld.yml b/changelogs/fragments/247_firewalld.yml deleted file mode 100644 index 2a45b48..0000000 --- a/changelogs/fragments/247_firewalld.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: -- firewalld - Correct usage of queryForwardPort (https://github.com/ansible-collections/ansible.posix/issues/247). diff --git a/changelogs/fragments/254_variable_warnings.yml b/changelogs/fragments/254_variable_warnings.yml deleted file mode 100644 index 4b87e31..0000000 --- a/changelogs/fragments/254_variable_warnings.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -minor_changes: -- firewalld - Show warning message that variable type of ``masquerade`` and - ``icmp_block_inversion`` will be changed from ``str`` to ``boolean`` - in the future release (https://github.com/ansible-collections/ansible.posix/pull/254). diff --git a/changelogs/fragments/255_authorized_key_url.yml b/changelogs/fragments/255_authorized_key_url.yml deleted file mode 100644 index 5381935..0000000 --- a/changelogs/fragments/255_authorized_key_url.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- authorized_keys - add an example involving ``url`` lookup plugin (https://github.com/ansible-collections/ansible.posix/pull/260). diff --git a/changelogs/fragments/263_profile_tasks_with_serial.yml b/changelogs/fragments/263_profile_tasks_with_serial.yml deleted file mode 100644 index f3032e9..0000000 --- a/changelogs/fragments/263_profile_tasks_with_serial.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: -- profile_tasks - Correctly calculate task execution time with serial execution (https://github.com/ansible-collections/ansible.posix/issues/83). diff --git a/changelogs/fragments/272-copy_ignore_txt.yml b/changelogs/fragments/272-copy_ignore_txt.yml deleted file mode 100644 index 7537d54..0000000 --- a/changelogs/fragments/272-copy_ignore_txt.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Copy ignore-2.12.txt to ignore-2.13.txt. diff --git a/changelogs/fragments/277_fix_integration_test_on_devel.yml b/changelogs/fragments/277_fix_integration_test_on_devel.yml deleted file mode 100644 index d2b4c69..0000000 --- a/changelogs/fragments/277_fix_integration_test_on_devel.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- Fix integration tests of synchronize and sysctl to address chaging behavior on devel branch (https://github.com/ansible-collections/overview/issues/45). diff --git a/changelogs/fragments/282_fix_unit_test_for_synchronize.yml b/changelogs/fragments/282_fix_unit_test_for_synchronize.yml deleted file mode 100644 index 23521af..0000000 --- a/changelogs/fragments/282_fix_unit_test_for_synchronize.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- Fix unit tests of synchronize action plugin to use yaml.safe_load(). diff --git a/changelogs/fragments/287_firewalld_requirements.yml b/changelogs/fragments/287_firewalld_requirements.yml deleted file mode 100644 index 621701b..0000000 --- a/changelogs/fragments/287_firewalld_requirements.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- firewalld - add python-firewall to requirements (https://github.com/ansible-collections/ansible.posix/issues/286). diff --git a/changelogs/fragments/288_mounts_options.yml b/changelogs/fragments/288_mounts_options.yml deleted file mode 100644 index 23b6edd..0000000 --- a/changelogs/fragments/288_mounts_options.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- mount - remove deprecated option from nfs example diff --git a/changelogs/fragments/297_firewalld_exclusive_options_handling.yml b/changelogs/fragments/297_firewalld_exclusive_options_handling.yml deleted file mode 100644 index 4727000..0000000 --- a/changelogs/fragments/297_firewalld_exclusive_options_handling.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: -- firewalld - Refine the handling of exclusive options (https://github.com/ansible-collections/ansible.posix/issues/255). diff --git a/changelogs/fragments/299_seboolean_python3.yml b/changelogs/fragments/299_seboolean_python3.yml deleted file mode 100644 index 5680d99..0000000 --- a/changelogs/fragments/299_seboolean_python3.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: -- seboolean - add ``python3-libsemanage`` package dependency for RHEL8+ systems. diff --git a/changelogs/fragments/302_shippable_exit_code.yml b/changelogs/fragments/302_shippable_exit_code.yml deleted file mode 100644 index d1dae9b..0000000 --- a/changelogs/fragments/302_shippable_exit_code.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI tests - fix exit code to address shellckeck test issue (https://github.com/ansible-collections/ansible.posix/issues/301). diff --git a/changelogs/fragments/304_pep632.yml b/changelogs/fragments/304_pep632.yml deleted file mode 100644 index 6c92fdc..0000000 --- a/changelogs/fragments/304_pep632.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: -- Use vendored version of ``distutils.version`` instead of the deprecated Python standard library to address PEP 632 (https://github.com/ansible-collections/ansible.posix/issues/303). diff --git a/changelogs/fragments/346_copy_ignore_txt_for_devel.yml b/changelogs/fragments/346_copy_ignore_txt_for_devel.yml deleted file mode 100644 index 053d865..0000000 --- a/changelogs/fragments/346_copy_ignore_txt_for_devel.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI tests - create ignore file for 2.14.0.dev0 (https://github.com/ansible-collections/ansible.posix/issues/345). diff --git a/changelogs/fragments/347_add_branch_213.yml b/changelogs/fragments/347_add_branch_213.yml deleted file mode 100644 index 846850f..0000000 --- a/changelogs/fragments/347_add_branch_213.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI tests - add CI tests against stable-2.13 (https://github.com/ansible-collections/ansible.posix/issues/345). diff --git a/changelogs/fragments/349_follow_new_guidelines.yml b/changelogs/fragments/349_follow_new_guidelines.yml deleted file mode 100644 index 2b13e12..0000000 --- a/changelogs/fragments/349_follow_new_guidelines.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI tests - following the new sanity check guideline (https://github.com/ansible-collections/ansible.posix/issues/348). diff --git a/changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml b/changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml deleted file mode 100644 index 190b9f9..0000000 --- a/changelogs/fragments/353_ci_fix_unittest_for_synchronize.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI tests - added check_mode attribute to TaskMock class for synchronize plugin unit test (https://github.com/ansible-collections/ansible.posix/issues/352). diff --git a/changelogs/fragments/disable_selinux_via_kernel_cmdline.yml b/changelogs/fragments/disable_selinux_via_kernel_cmdline.yml deleted file mode 100644 index 505a134..0000000 --- a/changelogs/fragments/disable_selinux_via_kernel_cmdline.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: -- selinux - optionally update kernel boot params when disabling/re-enabling SELinux (https://github.com/ansible-collections/ansible.posix/pull/142). diff --git a/changelogs/fragments/psf-license.yml b/changelogs/fragments/psf-license.yml deleted file mode 100644 index f8fbc0b..0000000 --- a/changelogs/fragments/psf-license.yml +++ /dev/null @@ -1,2 +0,0 @@ -bugfixes: - - Include ``PSF-license.txt`` file for ``plugins/module_utils/_version.py``. diff --git a/changelogs/fragments/sanity_fixes.yml b/changelogs/fragments/sanity_fixes.yml deleted file mode 100644 index 4920b88..0000000 --- a/changelogs/fragments/sanity_fixes.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- sanity fixes for pylint test. diff --git a/changelogs/fragments/shell_escape_full_path_for_rsync.yml b/changelogs/fragments/shell_escape_full_path_for_rsync.yml deleted file mode 100644 index d37bee7..0000000 --- a/changelogs/fragments/shell_escape_full_path_for_rsync.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - Fix for whitespace in source full path causing error ```code 23) at main.c(1330) [sender=3.2.3]``` (https://github.com/ansible-collections/ansible.posix/pull/278) diff --git a/docs/ansible.posix.authorized_key_module.rst b/docs/ansible.posix.authorized_key_module.rst index 69e80e3..bfbb444 100644 --- a/docs/ansible.posix.authorized_key_module.rst +++ b/docs/ansible.posix.authorized_key_module.rst @@ -240,6 +240,12 @@ Examples state: present key: https://github.com/charlie.keys + - name: Set authorized keys taken from url using lookup + ansible.posix.authorized_key: + user: charlie + state: present + key: "{{ lookup('url', 'https://github.com/charlie.keys', split_lines=False) }}" + - name: Set authorized key in alternate location ansible.posix.authorized_key: user: charlie diff --git a/docs/ansible.posix.firewalld_module.rst b/docs/ansible.posix.firewalld_module.rst index a041534..ea58ff2 100644 --- a/docs/ansible.posix.firewalld_module.rst +++ b/docs/ansible.posix.firewalld_module.rst @@ -25,6 +25,7 @@ Requirements The below requirements are needed on the host that executes this module. - firewalld >= 0.2.11 +- python-firewall >= 0.2.11 Parameters @@ -401,6 +402,7 @@ Notes - Requires the python2 bindings of firewalld, which may not be installed by default. - For distributions where the python2 firewalld bindings are unavailable (e.g Fedora 28 and later) you will have to set the ansible_python_interpreter for these hosts to the python3 interpreter path and install the python3 bindings. - Zone transactions (creating, deleting) can be performed by using only the zone and state parameters "present" or "absent". Note that zone transactions must explicitly be permanent. This is a limitation in firewalld. This also means that you will have to reload firewalld after adding a zone that you wish to perform immediate actions on. The module will not take care of this for you implicitly because that would undo any previously performed immediate actions which were not permanent. Therefore, if you require immediate access to a newly created zone it is recommended you reload firewalld immediately after the zone creation returns with a changed state and before you perform any other immediate, non-permanent actions on that zone. + - This module needs ``python-firewall`` or ``python3-firewall`` on managed nodes. It is usually provided as a subset with ``firewalld`` from the OS distributor for the OS default Python interpreter. diff --git a/docs/ansible.posix.mount_module.rst b/docs/ansible.posix.mount_module.rst index d955f7b..3ec3ce9 100644 --- a/docs/ansible.posix.mount_module.rst +++ b/docs/ansible.posix.mount_module.rst @@ -85,7 +85,7 @@ Parameters - Default:
0
+ Default:
"0"
Dump (see fstab(5)).
@@ -153,7 +153,7 @@ Parameters - Default:
0
+ Default:
"0"
Passno (see fstab(5)).
@@ -295,7 +295,7 @@ Examples ansible.posix.mount: src: 192.168.1.100:/nfs/ssd/shared_data path: /mnt/shared_data - opts: rw,sync,hard,intr + opts: rw,sync,hard state: mounted fstype: nfs @@ -303,7 +303,7 @@ Examples ansible.posix.mount: src: 192.168.1.100:/nfs/ssd/shared_data path: /mnt/shared_data - opts: rw,sync,hard,intr + opts: rw,sync,hard boot: no state: mounted fstype: nfs diff --git a/docs/ansible.posix.seboolean_module.rst b/docs/ansible.posix.seboolean_module.rst index b089b14..03a9b33 100644 --- a/docs/ansible.posix.seboolean_module.rst +++ b/docs/ansible.posix.seboolean_module.rst @@ -27,6 +27,7 @@ The below requirements are needed on the host that executes this module. - libselinux-python - libsemanage-python +- python3-libsemanage Parameters diff --git a/docs/ansible.posix.selinux_module.rst b/docs/ansible.posix.selinux_module.rst index b7f7976..20d9ef8 100644 --- a/docs/ansible.posix.selinux_module.rst +++ b/docs/ansible.posix.selinux_module.rst @@ -94,6 +94,27 @@ Parameters
The SELinux mode.
+ + +
+ update_kernel_param + +
+ boolean +
+
added in 1.4.0
+ + +
    Choices: +
  • no ←
  • +
  • yes
  • +
+ + +
If set to true, will update also the kernel boot parameters when disabling/enabling SELinux.
+
The grubby tool must be present on the target system for this to work.
+ +
From c1f830f3df8655d5256f369a806ebd8d3c267d81 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 30 May 2022 10:53:44 +0900 Subject: [PATCH 013/109] Refactoring AZP CI matrix * https://github.com/ansible-collections/news-for-maintainers/issues/17 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 94 +++++++++++----------------- 1 file changed, 37 insertions(+), 57 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index e8003df..5d9aafc 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -49,20 +49,20 @@ stages: jobs: - template: templates/matrix.yml parameters: - testFormat: devel/linux/{0}/1 + testFormat: devel/linux/{0} targets: - name: CentOS 7 test: centos7 - - name: Fedora 34 - test: fedora34 - name: Fedora 35 test: fedora35 + - name: Fedora 36 + test: fedora36 - name: openSUSE 15 py3 test: opensuse15 - - name: Ubuntu 18.04 - test: ubuntu1804 - name: Ubuntu 20.04 test: ubuntu2004 + - name: Ubuntu 22.04 + test: ubuntu2204 - stage: Docker_2_13 displayName: Docker 2.13 dependsOn: [] @@ -131,30 +131,6 @@ stages: test: ubuntu1804 - name: Ubuntu 20.04 test: ubuntu2004 - - stage: Docker_2_10 - displayName: Docker 2.10 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.10/linux/{0}/1 - targets: - - name: CentOS 6 - test: centos6 - - name: CentOS 7 - test: centos7 - - name: Fedora 30 - test: fedora30 - - name: Fedora 31 - test: fedora31 - - name: openSUSE 15 py2 - test: opensuse15py2 - - name: openSUSE 15 py3 - test: opensuse15 - - name: Ubuntu 16.04 - test: ubuntu1604 - - name: Ubuntu 18.04 - test: ubuntu1804 - stage: Docker_2_9 displayName: Docker 2.9 dependsOn: [] @@ -187,25 +163,31 @@ stages: jobs: - template: templates/matrix.yml parameters: - testFormat: devel/{0}/1 + testFormat: devel/{0} targets: - name: MacOS 12.0 test: macos/12.0 - name: RHEL 7.9 test: rhel/7.9 - - name: RHEL 8.5 - test: rhel/8.5 + - name: RHEL 8.6 + test: rhel/8.6 + - name: RHEL 9.0 + test: rhel/9.0 - name: FreeBSD 12.3 test: freebsd/12.3 - - name: FreeBSD 13.0 - test: freebsd/13.0 + - name: FreeBSD 13.1 + test: freebsd/13.1 + groups: + - 1 + - 2 + - 3 - stage: Remote_2_13 displayName: Remote 2.13 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.13/{0}/1 + testFormat: 2.13/{0} targets: - name: MacOS 12.0 test: macos/12.0 @@ -217,13 +199,17 @@ stages: test: freebsd/12.3 - name: FreeBSD 13.0 test: freebsd/13.0 + groups: + - 1 + - 2 + - 3 - stage: Remote_2_12 displayName: Remote 2.12 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.12/{0}/1 + testFormat: 2.12/{0} targets: - name: MacOS 11.1 test: macos/11.1 @@ -235,13 +221,17 @@ stages: test: freebsd/12.2 - name: FreeBSD 13.0 test: freebsd/13.0 + groups: + - 1 + - 2 + - 3 - stage: Remote_2_11 displayName: Remote 2.11 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.11/{0}/1 + testFormat: 2.11/{0} targets: - name: MacOS 11.1 test: macos/11.1 @@ -253,32 +243,17 @@ stages: test: freebsd/11.4 - name: FreeBSD 12.2 test: freebsd/12.2 - - stage: Remote_2_10 - displayName: Remote 2.10 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.10/{0}/1 - targets: - - name: OS X 10.11 - test: osx/10.11 - - name: RHEL 7.9 - test: rhel/7.9 - - name: RHEL 8.2 - test: rhel/8.2 - - name: FreeBSD 11.1 - test: freebsd/11.1 - - name: FreeBSD 12.1 - test: freebsd/12.1 - + groups: + - 1 + - 2 + - 3 - stage: Remote_2_9 displayName: Remote 2.9 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.9/{0}/1 + testFormat: 2.9/{0} targets: - name: OS X 10.11 test: osx/10.11 @@ -290,6 +265,11 @@ stages: test: freebsd/11.1 - name: FreeBSD 12.0 test: freebsd/12.0 + groups: + - 1 + - 2 + - 3 + ## Finally - stage: Summary From ee652056073fe09f4c7d5b8736ec570f69c39cde Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 25 May 2022 19:06:27 +0900 Subject: [PATCH 014/109] Update version number of galaxy.yml to 1.5.0. Signed-off-by: Hideki Saito --- changelogs/fragments/366_update_version_number_for_galaxy.yml | 3 +++ galaxy.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/366_update_version_number_for_galaxy.yml diff --git a/changelogs/fragments/366_update_version_number_for_galaxy.yml b/changelogs/fragments/366_update_version_number_for_galaxy.yml new file mode 100644 index 0000000..a905b39 --- /dev/null +++ b/changelogs/fragments/366_update_version_number_for_galaxy.yml @@ -0,0 +1,3 @@ +--- +trivial: +- Update version number in galaxy.yml to 1.5.0. diff --git a/galaxy.yml b/galaxy.yml index a3b9509..9520636 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: ansible name: posix -version: 1.4.0 +version: 1.5.0 readme: README.md authors: - Ansible (github.com/ansible) From f451f2211bcc7b59122124aa37fc8694be6f0a4a Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Thu, 2 Jun 2022 11:04:16 +0900 Subject: [PATCH 015/109] Refactor AZP settings and CI script * Addresses https://github.com/ansible-collections/news-for-maintainers/issues/17 * Addresses https://github.com/ansible-collections/ansible.posix/pull/369 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 76 +++++++++++-------- .../371_refactoring_ci_process_202206.yml | 3 + tests/utils/shippable/shippable.sh | 9 ++- 3 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 changelogs/fragments/371_refactoring_ci_process_202206.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 5d9aafc..078109b 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -49,7 +49,7 @@ stages: jobs: - template: templates/matrix.yml parameters: - testFormat: devel/linux/{0} + testFormat: devel/linux/{0}/1 targets: - name: CentOS 7 test: centos7 @@ -131,6 +131,30 @@ stages: test: ubuntu1804 - name: Ubuntu 20.04 test: ubuntu2004 + - stage: Docker_2_10 + displayName: Docker 2.10 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.10/linux/{0}/1 + targets: + - name: CentOS 6 + test: centos6 + - name: CentOS 7 + test: centos7 + - name: Fedora 30 + test: fedora30 + - name: Fedora 31 + test: fedora31 + - name: openSUSE 15 py2 + test: opensuse15py2 + - name: openSUSE 15 py3 + test: opensuse15 + - name: Ubuntu 16.04 + test: ubuntu1604 + - name: Ubuntu 18.04 + test: ubuntu1804 - stage: Docker_2_9 displayName: Docker 2.9 dependsOn: [] @@ -163,7 +187,7 @@ stages: jobs: - template: templates/matrix.yml parameters: - testFormat: devel/{0} + testFormat: devel/{0}/1 targets: - name: MacOS 12.0 test: macos/12.0 @@ -177,17 +201,13 @@ stages: test: freebsd/12.3 - name: FreeBSD 13.1 test: freebsd/13.1 - groups: - - 1 - - 2 - - 3 - stage: Remote_2_13 displayName: Remote 2.13 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.13/{0} + testFormat: 2.13/{0}/1 targets: - name: MacOS 12.0 test: macos/12.0 @@ -199,17 +219,13 @@ stages: test: freebsd/12.3 - name: FreeBSD 13.0 test: freebsd/13.0 - groups: - - 1 - - 2 - - 3 - stage: Remote_2_12 displayName: Remote 2.12 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.12/{0} + testFormat: 2.12/{0}/1 targets: - name: MacOS 11.1 test: macos/11.1 @@ -221,17 +237,13 @@ stages: test: freebsd/12.2 - name: FreeBSD 13.0 test: freebsd/13.0 - groups: - - 1 - - 2 - - 3 - stage: Remote_2_11 displayName: Remote 2.11 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.11/{0} + testFormat: 2.11/{0}/1 targets: - name: MacOS 11.1 test: macos/11.1 @@ -239,21 +251,29 @@ stages: test: rhel/7.9 - name: RHEL 8.3 test: rhel/8.3 - - name: FreeBSD 11.4 - test: freebsd/11.4 - name: FreeBSD 12.2 test: freebsd/12.2 - groups: - - 1 - - 2 - - 3 + - stage: Remote_2_10 + displayName: Remote 2.10 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.10/{0}/1 + targets: + - name: OS X 10.11 + test: osx/10.11 + - name: RHEL 7.9 + test: rhel/7.9 + - name: RHEL 8.2 + test: rhel/8.2 - stage: Remote_2_9 displayName: Remote 2.9 dependsOn: [] jobs: - template: templates/matrix.yml parameters: - testFormat: 2.9/{0} + testFormat: 2.9/{0}/1 targets: - name: OS X 10.11 test: osx/10.11 @@ -261,14 +281,6 @@ stages: test: rhel/7.9 - name: RHEL 8.1 test: rhel/8.1 - - name: FreeBSD 11.1 - test: freebsd/11.1 - - name: FreeBSD 12.0 - test: freebsd/12.0 - groups: - - 1 - - 2 - - 3 ## Finally diff --git a/changelogs/fragments/371_refactoring_ci_process_202206.yml b/changelogs/fragments/371_refactoring_ci_process_202206.yml new file mode 100644 index 0000000..26325d4 --- /dev/null +++ b/changelogs/fragments/371_refactoring_ci_process_202206.yml @@ -0,0 +1,3 @@ +--- +trivial: +- CI - Refactor AZP to address new test infrastructure (https://github.com/ansible-collections/news-for-maintainers/issues/17). diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index 14f2e57..8dfec24 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -74,7 +74,14 @@ else fi # START: HACK install dependencies -retry ansible-galaxy collection install community.general +if [ "${ansible_version}" == "2.9" ] || [ "${ansible_version}" == "2.10" ]; then + # Note: Since community.general 5.x, Ansible Core versions prior to 2.11 are not supported. + # So we need to use 4.8.1 for Ansible 2.9 and Ansible Engine 2.10. + retry git clone --depth=1 --single-branch -b 4.8.1 https://github.com/ansible-collections/community.general.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/general" +else + retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.general.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/general" +fi +# Note: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429) # END: HACK export PYTHONIOENCODING='utf-8' From 04089e80fbfd969f2b0fd43a80e42639d25c1f8e Mon Sep 17 00:00:00 2001 From: NdFeB Date: Tue, 14 Sep 2021 18:57:39 +0200 Subject: [PATCH 016/109] Add ephemeral state to mount fs without altering fstab --- changelogs/fragments/267_mount_ephemeral.yml | 4 + plugins/modules/mount.py | 161 +++++++++-- .../integration/targets/mount/tasks/main.yml | 273 ++++++++++++++++++ 3 files changed, 416 insertions(+), 22 deletions(-) create mode 100644 changelogs/fragments/267_mount_ephemeral.yml diff --git a/changelogs/fragments/267_mount_ephemeral.yml b/changelogs/fragments/267_mount_ephemeral.yml new file mode 100644 index 0000000..5671916 --- /dev/null +++ b/changelogs/fragments/267_mount_ephemeral.yml @@ -0,0 +1,4 @@ +--- +minor_changes: +- mount - Add ``ephemeral`` value for the ``state`` parameter, that allows to mount a filesystem + without altering the ``fstab`` file (https://github.com/ansible-collections/ansible.posix/pull/267). diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 2021464..7c4cc3d 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -31,12 +31,12 @@ options: src: description: - Device (or NFS volume, or something else) to be mounted on I(path). - - Required when I(state) set to C(present) or C(mounted). + - Required when I(state) set to C(present), C(mounted) or C(ephemeral). type: path fstype: description: - Filesystem type. - - Required when I(state) is C(present) or C(mounted). + - Required when I(state) is C(present), C(mounted) or C(ephemeral). type: str opts: description: @@ -48,7 +48,7 @@ options: - Note that if set to C(null) and I(state) set to C(present), it will cease to work and duplicate entries will be made with subsequent runs. - - Has no effect on Solaris systems. + - Has no effect on Solaris systems or when used with C(ephemeral). type: str default: '0' passno: @@ -57,7 +57,7 @@ options: - Note that if set to C(null) and I(state) set to C(present), it will cease to work and duplicate entries will be made with subsequent runs. - - Deprecated on Solaris systems. + - Deprecated on Solaris systems. Has no effect when used with C(ephemeral). type: str default: '0' state: @@ -68,6 +68,13 @@ options: - If C(unmounted), the device will be unmounted without changing I(fstab). - C(present) only specifies that the device is to be configured in I(fstab) and does not trigger or require a mount. + - C(ephemeral) only specifies that the device is to be mounted, without changing + I(fstab). If it is already mounted, a remount will be triggered. + This will always return changed=True. If the mount point I(path) + has already a device mounted on, and its source is different than I(src), + the module will fail to avoid unexpected unmount or mount point override. + If the mount point is not present, the mount point will be created. + The I(fstab) is completely ignored. - C(absent) specifies that the device mount's entry will be removed from I(fstab) and will also unmount the device and remove the mount point. @@ -77,10 +84,12 @@ options: applied to the remount, but will not change I(fstab). Additionally, if I(opts) is set, and the remount command fails, the module will error to prevent unexpected mount changes. Try using C(mounted) - instead to work around this issue. + instead to work around this issue. C(remounted) expects the mount point + to be present in the I(fstab). To remount a mount point not registered + in I(fstab), use C(ephemeral) instead, especially with BSD nodes. type: str required: true - choices: [ absent, mounted, present, unmounted, remounted ] + choices: [ absent, mounted, present, unmounted, remounted, ephemeral ] fstab: description: - File to use instead of C(/etc/fstab). @@ -89,6 +98,7 @@ options: - OpenBSD does not allow specifying alternate fstab files with mount so do not use this on OpenBSD with any state that operates on the live filesystem. - This parameter defaults to /etc/fstab or /etc/vfstab on Solaris. + - This parameter is ignored when I(state) is set to C(ephemeral). type: str boot: description: @@ -100,6 +110,7 @@ options: to mount options in I(/etc/fstab). - To avoid mount option conflicts, if C(noauto) specified in C(opts), mount module will ignore C(boot). + - This parameter is ignored when I(state) is set to C(ephemeral). type: bool default: yes backup: @@ -184,6 +195,14 @@ EXAMPLES = r''' boot: no state: mounted fstype: nfs + +- name: Mount ephemeral SMB volume + ansible.posix.mount: + src: //192.168.1.200/share + path: /mnt/smb_share + opts: "rw,vers=3,file_mode=0600,dir_mode=0700,dom={{ ad_domain }},username={{ ad_username }},password={{ ad_password }}" + fstype: cifs + state: ephemeral ''' import errno @@ -430,6 +449,24 @@ def _set_fstab_args(fstab_file): return result +def _set_ephemeral_args(args): + result = [] + # Set fstype switch according to platform. SunOS/Solaris use -F + if platform.system().lower() == 'sunos': + result.append('-F') + else: + result.append('-t') + result.append(args['fstype']) + + # Even if '-o remount' is already set, specifying multiple -o is valid + if args['opts'] != 'defaults': + result += ['-o', args['opts']] + + result.append(args['src']) + + return result + + def mount(module, args): """Mount up a path or remount if needed.""" @@ -446,7 +483,11 @@ def mount(module, args): 'OpenBSD does not support alternate fstab files. Do not ' 'specify the fstab parameter for OpenBSD hosts')) else: - cmd += _set_fstab_args(args['fstab']) + if module.params['state'] != 'ephemeral': + cmd += _set_fstab_args(args['fstab']) + + if module.params['state'] == 'ephemeral': + cmd += _set_ephemeral_args(args) cmd += [name] @@ -498,18 +539,24 @@ def remount(module, args): 'OpenBSD does not support alternate fstab files. Do not ' 'specify the fstab parameter for OpenBSD hosts')) else: - cmd += _set_fstab_args(args['fstab']) + if module.params['state'] != 'ephemeral': + cmd += _set_fstab_args(args['fstab']) + + if module.params['state'] == 'ephemeral': + cmd += _set_ephemeral_args(args) cmd += [args['name']] out = err = '' try: - if platform.system().lower().endswith('bsd'): + if module.params['state'] != 'ephemeral' and platform.system().lower().endswith('bsd'): # Note: Forcing BSDs to do umount/mount due to BSD remount not # working as expected (suspect bug in the BSD mount command) # Interested contributor could rework this to use mount options on # the CLI instead of relying on fstab # https://github.com/ansible/ansible-modules-core/issues/5591 + # Note: this does not affect ephemeral state as all options + # are set on the CLI and fstab is expected to be ignored. rc = 1 else: rc, out, err = module.run_command(cmd) @@ -663,6 +710,47 @@ def get_linux_mounts(module, mntinfo_file="/proc/self/mountinfo"): return mounts +def _is_same_mount_src(module, src, mountpoint, linux_mounts): + """Return True if the mounted fs on mountpoint is the same source than src. Return False if mountpoint is not a mountpoint""" + # If the provided mountpoint is not a mountpoint, don't waste time + if ( + not ismount(mountpoint) and + not is_bind_mounted(module, linux_mounts, mountpoint)): + return False + + # Treat Linux bind mounts + if platform.system() == 'Linux' and linux_mounts is not None: + # For Linux bind mounts only: the mount command does not return + # the actual source for bind mounts, but the device of the source. + # is_bind_mounted() called with the 'src' parameter will return True if + # the mountpoint is a bind mount AND the source FS is the same than 'src'. + # is_bind_mounted() is not reliable on Solaris, NetBSD and OpenBSD. + # But we can rely on 'mount -v' on all other platforms, and Linux non-bind mounts. + if (is_bind_mounted(module, linux_mounts, mountpoint, src)): + return True + + # mount with parameter -v has a close behavior on Linux, *BSD, SunOS + # Requires -v with SunOS. Without -v, source and destination are reversed + # Output format differs from a system to another, but field[0:3] are consistent: [src, 'on', dest] + cmd = '%s -v' % module.get_bin_path('mount', required=True) + rc, out, err = module.run_command(cmd) + mounts = [] + + if len(out): + mounts = to_native(out).strip().split('\n') + else: + module.fail_json(msg="Unable to retrieve mount info with command '%s'" % cmd) + + for mnt in mounts: + fields = mnt.split() + mp_src = fields[0] + mp_dst = fields[2] + if mp_src == src and mp_dst == mountpoint: + return True + + return False + + def main(): module = AnsibleModule( argument_spec=dict( @@ -675,12 +763,13 @@ def main(): passno=dict(type='str', no_log=False, default='0'), src=dict(type='path'), backup=dict(type='bool', default=False), - state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted']), + state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted', 'ephemeral']), ), supports_check_mode=True, required_if=( ['state', 'mounted', ['src', 'fstype']], ['state', 'present', ['src', 'fstype']], + ['state', 'ephemeral', ['src', 'fstype']] ), ) @@ -751,15 +840,17 @@ def main(): # If fstab file does not exist, we first need to create it. This mainly # happens when fstab option is passed to the module. - if not os.path.exists(args['fstab']): - if not os.path.exists(os.path.dirname(args['fstab'])): - os.makedirs(os.path.dirname(args['fstab'])) - try: - open(args['fstab'], 'a').close() - except PermissionError as e: - module.fail_json(msg="Failed to open %s due to permission issue" % args['fstab']) - except Exception as e: - module.fail_json(msg="Failed to open %s due to %s" % (args['fstab'], to_native(e))) + # If state is 'ephemeral', we do not need fstab file + if module.params['state'] != 'ephemeral': + if not os.path.exists(args['fstab']): + if not os.path.exists(os.path.dirname(args['fstab'])): + os.makedirs(os.path.dirname(args['fstab'])) + try: + open(args['fstab'], 'a').close() + except PermissionError as e: + module.fail_json(msg="Failed to open %s due to permission issue" % args['fstab']) + except Exception as e: + module.fail_json(msg="Failed to open %s due to %s" % (args['fstab'], to_native(e))) # absent: # Remove from fstab and unmounted. @@ -770,6 +861,8 @@ def main(): # mounted: # Add to fstab if not there and make sure it is mounted. If it has # changed in fstab then remount it. + # ephemeral: + # Do not change fstab state, but mount. state = module.params['state'] name = module.params['path'] @@ -801,7 +894,7 @@ def main(): msg="Error unmounting %s: %s" % (name, msg)) changed = True - elif state == 'mounted': + elif state == 'mounted' or state == 'ephemeral': dirs_created = [] if not os.path.exists(name) and not module.check_mode: try: @@ -829,7 +922,11 @@ def main(): module.fail_json( msg="Error making dir %s: %s" % (name, to_native(e))) - name, backup_lines, changed = _set_mount_save_old(module, args) + # ephemeral: completely ignore fstab + if state != 'ephemeral': + name, backup_lines, changed = _set_mount_save_old(module, args) + else: + name, backup_lines, changed = args['name'], [], False res = 0 if ( @@ -839,7 +936,26 @@ def main(): if changed and not module.check_mode: res, msg = remount(module, args) changed = True + + # When 'state' == 'ephemeral', we don't know what is in fstab, and 'changed' is always False + if state == 'ephemeral': + # If state == 'ephemeral', check if the mountpoint src == module.params['src'] + # If it doesn't, fail to prevent unwanted unmount or unwanted mountpoint override + if _is_same_mount_src(module, args['src'], args['name'], linux_mounts): + changed = True + if not module.check_mode: + res, msg = remount(module, args) + else: + module.fail_json( + msg=( + 'Ephemeral mount point is already mounted with a different ' + 'source than the specified one. Failing in order to prevent an ' + 'unwanted unmount or override operation. Try replacing this command with ' + 'a "state: unmounted" followed by a "state: ephemeral", or use ' + 'a different destination path.')) + else: + # If not already mounted, mount it changed = True if not module.check_mode: @@ -851,7 +967,8 @@ def main(): # A non-working fstab entry may break the system at the reboot, # so undo all the changes if possible. try: - write_fstab(module, backup_lines, args['fstab']) + if state != 'ephemeral': + write_fstab(module, backup_lines, args['fstab']) except Exception: pass diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index be1850f..7b0d141 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -1,3 +1,9 @@ +- name: Install dependencies + ansible.builtin.package: + name: e2fsprogs + state: present + when: ansible_system == 'Linux' + - name: Create the mount point file: state: directory @@ -406,3 +412,270 @@ - /tmp/myfs1 - /tmp/test_fstab when: ansible_system in ('Linux') + +- name: Block to test ephemeral option + environment: + PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + block: + - name: Create empty file A + community.general.filesize: + path: /tmp/myfs_A.img + size: 20M + + - name: Create empty file B + community.general.filesize: + path: /tmp/myfs_B.img + size: 20M + + - name: Register facts on Linux + ansible.builtin.set_fact: + ephemeral_device_A: /tmp/myfs_A.img + ephemeral_device_B: /tmp/myfs_B.img + ephemeral_fstype: ext3 + ephemeral_fstab: /etc/fstab + when: ansible_system == 'Linux' + + - name: Register facts on Solaris/SunOS + ansible.builtin.set_fact: + ephemeral_device_A: /dev/lofi/1 + ephemeral_device_B: /dev/lofi/2 + ephemeral_create_loop_dev_cmd: > + lofiadm -a /tmp/myfs_A.img /dev/lofi/1 && + lofiadm -a /tmp/myfs_B.img /dev/lofi/2 + ephemeral_remove_loop_dev_cmd: > + lofiadm -d /dev/lofi/1 && + lofiadm -d /dev/lofi/2 || true + ephemeral_fstype: ufs + ephemeral_fstab: /etc/vfstab + when: ansible_system == 'SunOS' + + - name: Register facts on FreeBSD + ansible.builtin.set_fact: + ephemeral_device_A: /dev/md1 + ephemeral_device_B: /dev/md2 + ephemeral_create_loop_dev_cmd: > + mdconfig -a -t vnode -f /tmp/myfs_A.img -u /dev/md1 && + mdconfig -a -t vnode -f /tmp/myfs_B.img -u /dev/md2 + ephemeral_remove_loop_dev_cmd: > + mdconfig -d -u /dev/md1 && + mdconfig -d -u /dev/md2 + ephemeral_fstype: ufs + ephemeral_fstab: /etc/fstab + when: ansible_system == 'FreeBSD' + + - name: Register facts on NetBSD + ansible.builtin.set_fact: + ephemeral_device_A: /dev/vnd1 + ephemeral_device_B: /dev/vnd2 + ephemeral_create_loop_dev_cmd: > + vnconfig /dev/vnd1 /tmp/myfs_A.img && + vnconfig /dev/vnd2 /tmp/myfs_B.img + ephemeral_remove_loop_dev_cmd: > + vnconfig -u /dev/vnd1 && + vnconfig -u /dev/vnd2 + ephemeral_fstype: ufs + ephemeral_fstab: /etc/fstab + when: ansible_system == 'NetBSD' + + - name: Register format fs command on Non-Linux and Non-OpenBSD + ansible.builtin.set_fact: + ephemeral_format_fs_cmd: > + yes | newfs {{ ephemeral_device_A }} && + yes | newfs {{ ephemeral_device_B }} + when: ansible_system in ('SunOS', 'FreeBSD', 'NetBSD') + + - name: Register facts on OpenBSD + ansible.builtin.set_fact: + ephemeral_device_A: /dev/vnd1c + ephemeral_device_B: /dev/vnd2c + ephemeral_create_loop_dev_cmd: > + vnconfig vnd1 /tmp/myfs_A.img && + vnconfig vnd2 /tmp/myfs_B.img + ephemeral_remove_loop_dev_cmd: > + vnconfig -u vnd1 && + vnconfig -u vnd2 + ephemeral_format_fs_cmd: > + yes | newfs /dev/rvnd1c && + yes | newfs /dev/rvnd2c + ephemeral_fstype: ffs + ephemeral_fstab: /etc/fstab + when: ansible_system == 'OpenBSD' + +##### FORMAT FS ON LINUX + + - name: Block to format FS on Linux + block: + - name: Format FS A on Linux + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs_A.img + + - name: Format FS B on Linux + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs_B.img + when: ansible_system == 'Linux' + +##### FORMAT FS ON SOLARIS AND BSD + + - name: Create loop devices on Solaris and BSD + ansible.builtin.shell: "{{ ephemeral_create_loop_dev_cmd }}" + when: ephemeral_create_loop_dev_cmd is defined + + - name: Format FS A and B on Solaris and BSD + ansible.builtin.shell: "{{ ephemeral_format_fs_cmd }}" + when: ephemeral_format_fs_cmd is defined + +##### TESTS + + - name: Create fstab if it does not exist + ansible.builtin.file: + path: "{{ ephemeral_fstab }}" + state: touch + + - name: Get checksum of /etc/fstab before mounting anything + stat: + path: '{{ ephemeral_fstab }}' + register: fstab_stat_before_mount + + - name: Mount the FS A with ephemeral state + mount: + path: /tmp/myfs + src: '{{ ephemeral_device_A }}' + fstype: '{{ ephemeral_fstype }}' + opts: rw + state: ephemeral + register: ephemeral_mount_info + + - name: Put something in the directory so we can do additional checks later on + copy: + content: 'Testing' + dest: /tmp/myfs/test_file + + - name: Get checksum of /etc/fstab after an ephemeral mount + stat: + path: '{{ ephemeral_fstab }}' + register: fstab_stat_after_mount + + - name: Get mountinfo + shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l + register: check_mountinfo + changed_when: no + + - name: Assert the mount occured and the fstab is unchanged + assert: + that: + - check_mountinfo.stdout|int == 1 + - ephemeral_mount_info['changed'] + - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_mount['stat']['checksum'] + + - name: Get first mount record + shell: mount -v | grep '/tmp/myfs' + register: ephemeral_mount_record_1 + changed_when: no + + - name: Try to mount FS A where FS A is already mounted (should trigger remount and changed) + mount: + path: /tmp/myfs + src: '{{ ephemeral_device_A }}' + fstype: '{{ ephemeral_fstype }}' + opts: ro + state: ephemeral + register: ephemeral_mount_info + + - name: Get second mount record (should be different than the first) + shell: mount -v | grep '/tmp/myfs' + register: ephemeral_mount_record_2 + changed_when: no + + - name: Get mountinfo + shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l + register: check_mountinfo + changed_when: no + + - name: Assert the FS A is still mounted, the options changed and the fstab unchanged + assert: + that: + - check_mountinfo.stdout|int == 1 + - ephemeral_mount_record_1.stdout != ephemeral_mount_record_2.stdout + - ephemeral_mount_info['changed'] + - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_mount['stat']['checksum'] + + - name: Try to mount file B on file A mountpoint (should fail) + mount: + path: /tmp/myfs + src: '{{ ephemeral_device_B }}' + fstype: '{{ ephemeral_fstype }}' + state: ephemeral + register: ephemeral_mount_b_info + ignore_errors: true + + - name: Get third mount record (should be the same than the second) + shell: mount -v | grep '/tmp/myfs' + register: ephemeral_mount_record_3 + changed_when: no + + - name: Get mountinfo + shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l + register: check_mountinfo + changed_when: no + + - name: Try to stat our test file + stat: + path: /tmp/myfs/test_file + register: test_file_stat + + - name: Assert that mounting FS B over FS A failed + assert: + that: + - check_mountinfo.stdout|int == 1 + - ephemeral_mount_record_2.stdout == ephemeral_mount_record_3.stdout + - test_file_stat['stat']['exists'] + - ephemeral_mount_b_info is failed + + - name: Unmount FS with state = unmounted + mount: + path: /tmp/myfs + state: unmounted + + - name: Get fstab checksum after unmounting an ephemeral mount with state = unmounted + stat: + path: '{{ ephemeral_fstab }}' + register: fstab_stat_after_unmount + + - name: Get mountinfo + shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l + register: check_mountinfo + changed_when: no + + - name: Try to stat our test file + stat: + path: /tmp/myfs/test_file + register: test_file_stat + + - name: Assert that fstab is unchanged after unmounting an ephemeral mount with state = unmounted + assert: + that: + - check_mountinfo.stdout|int == 0 + - not test_file_stat['stat']['exists'] + - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_unmount['stat']['checksum'] + + always: + - name: Unmount potential failure relicas + mount: + path: /tmp/myfs + state: unmounted + + - name: Remove loop devices on Solaris and BSD + ansible.builtin.shell: "{{ ephemeral_remove_loop_dev_cmd }}" + when: ephemeral_remove_loop_dev_cmd is defined + + - name: Remove the test FS + file: + path: '{{ item }}' + state: absent + loop: + - /tmp/myfs_A.img + - /tmp/myfs_B.img + - /tmp/myfs + when: ansible_system in ('Linux', 'SunOS', 'FreeBSD', 'NetBSD', 'OpenBSD') From b8ed9190116ff924c8e9431f090f35c07bc92943 Mon Sep 17 00:00:00 2001 From: NeodymiumFerBore <32781483+NeodymiumFerBore@users.noreply.github.com> Date: Wed, 18 May 2022 18:55:10 +0200 Subject: [PATCH 017/109] Apply suggestions from code review Co-authored-by: Abhijeet Kasurde --- plugins/modules/mount.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 7c4cc3d..36ceb98 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -74,7 +74,7 @@ options: has already a device mounted on, and its source is different than I(src), the module will fail to avoid unexpected unmount or mount point override. If the mount point is not present, the mount point will be created. - The I(fstab) is completely ignored. + The I(fstab) is completely ignored. This option is added in version 1.5.0. - C(absent) specifies that the device mount's entry will be removed from I(fstab) and will also unmount the device and remove the mount point. @@ -726,7 +726,7 @@ def _is_same_mount_src(module, src, mountpoint, linux_mounts): # the mountpoint is a bind mount AND the source FS is the same than 'src'. # is_bind_mounted() is not reliable on Solaris, NetBSD and OpenBSD. # But we can rely on 'mount -v' on all other platforms, and Linux non-bind mounts. - if (is_bind_mounted(module, linux_mounts, mountpoint, src)): + if is_bind_mounted(module, linux_mounts, mountpoint, src): return True # mount with parameter -v has a close behavior on Linux, *BSD, SunOS From d7c7d1d2c89f961e1aa85c6d1bc136687d4dd99d Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 3 Jun 2022 18:39:01 -0400 Subject: [PATCH 018/109] More complete missing lib msg adds 'exact' python used by module and hostname to avoid confusion --- plugins/module_utils/firewalld.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/firewalld.py b/plugins/module_utils/firewalld.py index c79a126..6a76c32 100644 --- a/plugins/module_utils/firewalld.py +++ b/plugins/module_utils/firewalld.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function from ansible_collections.ansible.posix.plugins.module_utils.version import LooseVersion +from ansible.module_utils.basic import missing_required_lib __metaclass__ = type @@ -314,6 +315,5 @@ class FirewallTransaction(object): if import_failure: module.fail_json( - msg='Python Module not found: firewalld and its python module are required for this module, \ - version 0.2.11 or newer required (0.3.9 or newer for offline operations)' + msg=missing_required_lib('firewall') + '. Version 0.2.11 or newer required (0.3.9 or newer for offline operations)' ) From 17fc3bcce6ac18d8a1c6ab7baa7d9a29a43990f9 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 15 Jun 2022 18:26:15 +0900 Subject: [PATCH 019/109] Bump AZP container version - https://github.com/ansible-collections/news-for-maintainers/issues/18 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 2 +- changelogs/fragments/375_update_azp_container.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/375_update_azp_container.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 078109b..4b1b3a9 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -36,7 +36,7 @@ variables: resources: containers: - container: default - image: quay.io/ansible/azure-pipelines-test-container:1.9.0 + image: quay.io/ansible/azure-pipelines-test-container:3.0.0 pool: Standard diff --git a/changelogs/fragments/375_update_azp_container.yml b/changelogs/fragments/375_update_azp_container.yml new file mode 100644 index 0000000..6d02987 --- /dev/null +++ b/changelogs/fragments/375_update_azp_container.yml @@ -0,0 +1,3 @@ +--- +trivial: + - CI - AZP test container to 3.0.0 (https://github.com/ansible-collections/news-for-maintainers/issues/18). From c4be75114b876ff61478a4173a352bacf5ea499d Mon Sep 17 00:00:00 2001 From: Sean Cavanaugh Date: Fri, 15 Jul 2022 14:04:06 -0400 Subject: [PATCH 020/109] Update profile_tasks.py removing contentious terminology to match reference documentation https://docs.ansible.com/ansible/latest/reference_appendices/config.html --- plugins/callback/profile_tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/callback/profile_tasks.py b/plugins/callback/profile_tasks.py index c6118df..b7fc3ac 100644 --- a/plugins/callback/profile_tasks.py +++ b/plugins/callback/profile_tasks.py @@ -21,7 +21,7 @@ DOCUMENTATION = ''' - It also lists the top/bottom time consuming tasks in the summary (configurable) - Before 2.4 only the environment variables were available for configuration. requirements: - - whitelisting in configuration - see examples section below for details. + - enable in configuration - see examples section below for details. options: output_limit: description: Number of tasks to display in the summary @@ -46,7 +46,7 @@ EXAMPLES = ''' example: > To enable, add this to your ansible.cfg file in the defaults block [defaults] - callback_whitelist = ansible.posix.profile_tasks + callbacks_enabled=ansible.posix.profile_tasks sample output: > # # TASK: [ensure messaging security group exists] ******************************** From f7fac900098cfa117c5035091e456b617f04ea02 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Fri, 19 Aug 2022 12:53:51 +0900 Subject: [PATCH 021/109] Removing Fedora 35 and FreeBSD 12.3 from CI tests Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 4b1b3a9..cd21121 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -53,8 +53,6 @@ stages: targets: - name: CentOS 7 test: centos7 - - name: Fedora 35 - test: fedora35 - name: Fedora 36 test: fedora36 - name: openSUSE 15 py3 @@ -197,8 +195,6 @@ stages: test: rhel/8.6 - name: RHEL 9.0 test: rhel/9.0 - - name: FreeBSD 12.3 - test: freebsd/12.3 - name: FreeBSD 13.1 test: freebsd/13.1 - stage: Remote_2_13 From abfe36c62f2e58d6660dce6559a8c38ea37f6b1c Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 7 Sep 2022 11:05:24 +0900 Subject: [PATCH 022/109] Fix to follow pylint check in ansible-test-sanity-docker-devel Signed-off-by: Hideki Saito --- changelogs/fragments/386_follow_ci_testing_rules.yml | 3 +++ plugins/modules/authorized_key.py | 2 ++ plugins/modules/mount.py | 2 +- .../targets/authorized_key/tasks/setup_steps.yml | 9 +++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/386_follow_ci_testing_rules.yml diff --git a/changelogs/fragments/386_follow_ci_testing_rules.yml b/changelogs/fragments/386_follow_ci_testing_rules.yml new file mode 100644 index 0000000..f59e82a --- /dev/null +++ b/changelogs/fragments/386_follow_ci_testing_rules.yml @@ -0,0 +1,3 @@ +--- +trivial: + - CI - following the new CI testing rule ansible-test-sanity-docker-devel. diff --git a/plugins/modules/authorized_key.py b/plugins/modules/authorized_key.py index e11b416..5e37c28 100644 --- a/plugins/modules/authorized_key.py +++ b/plugins/modules/authorized_key.py @@ -347,6 +347,8 @@ def keyfile(module, user, write=False, path=None, manage_dir=True, follow=False) basedir = os.path.dirname(keysfile) if not os.path.exists(basedir): os.makedirs(basedir) + + f = None try: f = open(keysfile, "w") # touches file so we can set ownership and perms finally: diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 2021464..58b49bc 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -226,7 +226,7 @@ def _escape_fstab(v): if isinstance(v, int): return v else: - return( + return ( v. replace('\\', '\\134'). replace(' ', '\\040'). diff --git a/tests/integration/targets/authorized_key/tasks/setup_steps.yml b/tests/integration/targets/authorized_key/tasks/setup_steps.yml index a3c21dc..2144b7a 100644 --- a/tests/integration/targets/authorized_key/tasks/setup_steps.yml +++ b/tests/integration/targets/authorized_key/tasks/setup_steps.yml @@ -1,5 +1,14 @@ # ------------------------------------------------------------- # Setup steps +- name: Clean up the working directory and files + file: + path: '{{ output_dir }}' + state: absent + +- name: Create the working directory + file: + path: '{{ output_dir }}' + state: directory - name: copy an existing file in place with comments copy: From acd5a2b17e8d27608a45ae5113852b05d3f11379 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 12 Sep 2022 13:47:55 +0900 Subject: [PATCH 023/109] Add changelog fragments to PR #380 Signed-off-by: Hideki Saito --- changelogs/fragments/380_update_usage_profile_tasks.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/380_update_usage_profile_tasks.yml diff --git a/changelogs/fragments/380_update_usage_profile_tasks.yml b/changelogs/fragments/380_update_usage_profile_tasks.yml new file mode 100644 index 0000000..5b23d40 --- /dev/null +++ b/changelogs/fragments/380_update_usage_profile_tasks.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Removed contentious terminology to match reference documentation in profile_tasks. From cc20deaad240e24e0083b3d1c6589ad833c040f6 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Fri, 16 Sep 2022 16:37:23 +0900 Subject: [PATCH 024/109] Add changelog fragment file to PR #373 Signed-off-by: Hideki Saito --- .../fragments/373_firewall_fix_missing_library_message.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/373_firewall_fix_missing_library_message.yml diff --git a/changelogs/fragments/373_firewall_fix_missing_library_message.yml b/changelogs/fragments/373_firewall_fix_missing_library_message.yml new file mode 100644 index 0000000..a5faea8 --- /dev/null +++ b/changelogs/fragments/373_firewall_fix_missing_library_message.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - firewall - Fixed to output a more complete missing library message. From 6c9616291ee6531752a15e2a468f0a5f73e53d0e Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Tue, 27 Sep 2022 20:43:22 +0900 Subject: [PATCH 025/109] Add stable-2.14 branch to AZP * Fixes #388 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 38 +++++++++++++++++++ .../fragments/389_ci_add_stable_214.yml | 3 ++ tests/sanity/ignore-2.15.txt | 8 ++++ 3 files changed, 49 insertions(+) create mode 100644 changelogs/fragments/389_ci_add_stable_214.yml create mode 100644 tests/sanity/ignore-2.15.txt diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index cd21121..9aef200 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -61,6 +61,24 @@ stages: test: ubuntu2004 - name: Ubuntu 22.04 test: ubuntu2204 + - stage: Docker_2_14 + displayName: Docker 2.14 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.14/linux/{0}/1 + targets: + - name: CentOS 7 + test: centos7 + - name: Fedora 36 + test: fedora36 + - name: openSUSE 15 py3 + test: opensuse15 + - name: Ubuntu 20.04 + test: ubuntu2004 + - name: Ubuntu 22.04 + test: ubuntu2204 - stage: Docker_2_13 displayName: Docker 2.13 dependsOn: [] @@ -197,6 +215,24 @@ stages: test: rhel/9.0 - name: FreeBSD 13.1 test: freebsd/13.1 + - stage: Remote_2_14 + displayName: Remote 2.14 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.14/{0}/1 + targets: + - name: MacOS 12.0 + test: macos/12.0 + - name: RHEL 7.9 + test: rhel/7.9 + - name: RHEL 8.6 + test: rhel/8.6 + - name: RHEL 9.0 + test: rhel/9.0 + - name: FreeBSD 13.1 + test: freebsd/13.1 - stage: Remote_2_13 displayName: Remote 2.13 dependsOn: [] @@ -293,6 +329,8 @@ stages: - Docker_2_12 - Remote_2_13 - Docker_2_13 + - Remote_2_14 + - Docker_2_14 - Remote_devel - Docker_devel jobs: diff --git a/changelogs/fragments/389_ci_add_stable_214.yml b/changelogs/fragments/389_ci_add_stable_214.yml new file mode 100644 index 0000000..6a174fd --- /dev/null +++ b/changelogs/fragments/389_ci_add_stable_214.yml @@ -0,0 +1,3 @@ +--- +trivial: +- CI - Add stable-2.14 to AZP (https://github.com/ansible-collections/ansible.posix/issues/388). diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt new file mode 100644 index 0000000..0b6905e --- /dev/null +++ b/tests/sanity/ignore-2.15.txt @@ -0,0 +1,8 @@ +plugins/modules/synchronize.py pylint:disallowed-name +plugins/modules/synchronize.py use-argspec-type-path +plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec +plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented +plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc +plugins/modules/synchronize.py validate-modules:undocumented-parameter +tests/utils/shippable/check_matrix.py replace-urlopen +tests/utils/shippable/timing.py shebang From 139e103b0f2f211bcf73b0bdff4307ff3ce9d2dc Mon Sep 17 00:00:00 2001 From: Juan Antonio Valino Garcia Date: Fri, 7 Oct 2022 17:20:20 +0200 Subject: [PATCH 026/109] Fixes ##390. Hosts involved must have same password --- plugins/action/synchronize.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/action/synchronize.py b/plugins/action/synchronize.py index a5752b9..7a330ac 100644 --- a/plugins/action/synchronize.py +++ b/plugins/action/synchronize.py @@ -225,7 +225,6 @@ class ActionModule(ActionBase): # Parameter name needed by the ansible module _tmp_args['_local_rsync_path'] = task_vars.get('ansible_rsync_path') or 'rsync' - _tmp_args['_local_rsync_password'] = task_vars.get('ansible_ssh_pass') or task_vars.get('ansible_password') # rsync thinks that one end of the connection is localhost and the # other is the host we're running the task for (Note: We use @@ -333,8 +332,9 @@ class ActionModule(ActionBase): if src is None or dest is None: return dict(failed=True, msg="synchronize requires both src and dest parameters are set") - # Determine if we need a user@ + # Determine if we need a user@ and a password user = None + password = task_vars.get('ansible_ssh_pass', None) or task_vars.get('ansible_password', None) if not dest_is_local: # Src and dest rsync "path" handling if boolean(_tmp_args.get('set_remote_user', 'yes'), strict=False): @@ -344,10 +344,11 @@ class ActionModule(ActionBase): user = task_vars.get('ansible_user') or self._play_context.remote_user if not user: user = C.DEFAULT_REMOTE_USER - else: user = task_vars.get('ansible_user') or self._play_context.remote_user + user = self._templar.template(user) + # Private key handling # Use the private_key parameter if passed else use context private_key_file _tmp_args['private_key'] = _tmp_args.get('private_key', self._play_context.private_key_file) @@ -361,12 +362,15 @@ class ActionModule(ActionBase): # src is a local path, dest is a remote path: @ src = self._process_origin(src_host, src, user) dest = self._process_remote(_tmp_args, dest_host, dest, user, inv_port in localhost_ports) + + password = dest_host_inventory_vars.get('ansible_ssh_pass', None) or dest_host_inventory_vars.get('ansible_password', None) else: # Still need to munge paths (to account for roles) even if we aren't # copying files between hosts src = self._get_absolute_path(path=src) dest = self._get_absolute_path(path=dest) + _tmp_args['_local_rsync_password'] = self._templar.template(password) _tmp_args['src'] = src _tmp_args['dest'] = dest From 297a10fec7eb431c95584eb7317f90434e22dbe3 Mon Sep 17 00:00:00 2001 From: Juan Antonio Valino Garcia Date: Fri, 7 Oct 2022 18:04:09 +0200 Subject: [PATCH 027/109] handle missing templar --- synchronize.py | 434 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 434 insertions(+) create mode 100644 synchronize.py diff --git a/synchronize.py b/synchronize.py new file mode 100644 index 0000000..c70db5f --- /dev/null +++ b/synchronize.py @@ -0,0 +1,434 @@ +# -*- coding: utf-8 -*- + +# (c) 2012-2013, Timothy Appnel +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os.path + +from ansible import constants as C +from ansible.module_utils.six import string_types +from ansible.module_utils.six.moves import shlex_quote +from ansible.module_utils._text import to_text +from ansible.module_utils.common._collections_compat import MutableSequence +from ansible.module_utils.parsing.convert_bool import boolean +from ansible.plugins.action import ActionBase +from ansible.plugins.loader import connection_loader + + +DOCKER = ['docker', 'community.general.docker', 'community.docker.docker'] +PODMAN = ['podman', 'ansible.builtin.podman', 'containers.podman.podman'] +BUILDAH = ['buildah', 'containers.podman.buildah'] + + +class ActionModule(ActionBase): + + def _get_absolute_path(self, path): + original_path = path + + # + # Check if we have a local relative path and do not process + # * remote paths (some.server.domain:/some/remote/path/...) + # * URLs (rsync://...) + # * local absolute paths (/some/local/path/...) + # + if ':' in path or path.startswith('/'): + return path + + if self._task._role is not None: + path = self._loader.path_dwim_relative(self._task._role._role_path, 'files', path) + else: + path = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', path) + + if original_path and original_path[-1] == '/' and path[-1] != '/': + # make sure the dwim'd path ends in a trailing "/" + # if the original path did + path += '/' + + return path + + def _host_is_ipv6_address(self, host): + return ':' in to_text(host, errors='surrogate_or_strict') + + def _format_rsync_rsh_target(self, host, path, user): + ''' formats rsync rsh target, escaping ipv6 addresses if needed ''' + + user_prefix = '' + + if path.startswith('rsync://'): + return path + + # If using docker or buildah, do not add user information + if self._remote_transport not in DOCKER + PODMAN + BUILDAH and user: + user_prefix = '%s@' % (user, ) + + if self._host_is_ipv6_address(host): + return '[%s%s]:%s' % (user_prefix, host, path) + return '%s%s:%s' % (user_prefix, host, path) + + def _process_origin(self, host, path, user): + + if host not in C.LOCALHOST: + return self._format_rsync_rsh_target(host, path, user) + + path = self._get_absolute_path(path=path) + return path + + def _process_remote(self, task_args, host, path, user, port_matches_localhost_port): + """ + :arg host: hostname for the path + :arg path: file path + :arg user: username for the transfer + :arg port_matches_localhost_port: boolean whether the remote port + matches the port used by localhost's sshd. This is used in + conjunction with seeing whether the host is localhost to know + if we need to have the module substitute the pathname or if it + is a different host (for instance, an ssh tunnelled port or an + alternative ssh port to a vagrant host.) + """ + transport = self._connection.transport + # If we're connecting to a remote host or we're delegating to another + # host or we're connecting to a different ssh instance on the + # localhost then we have to format the path as a remote rsync path + if host not in C.LOCALHOST or transport != "local" or \ + (host in C.LOCALHOST and not port_matches_localhost_port): + # If we're delegating to non-localhost and but the + # inventory_hostname host is localhost then we need the module to + # fix up the rsync path to use the controller's public DNS/IP + # instead of "localhost" + if port_matches_localhost_port and host in C.LOCALHOST: + task_args['_substitute_controller'] = True + return self._format_rsync_rsh_target(host, path, user) + + path = self._get_absolute_path(path=path) + return path + + def _override_module_replaced_vars(self, task_vars): + """ Some vars are substituted into the modules. Have to make sure + that those are correct for localhost when synchronize creates its own + connection to localhost.""" + + # Clear the current definition of these variables as they came from the + # connection to the remote host + if 'ansible_syslog_facility' in task_vars: + del task_vars['ansible_syslog_facility'] + for key in list(task_vars.keys()): + if key.startswith("ansible_") and key.endswith("_interpreter"): + del task_vars[key] + + # Add the definitions from localhost + for host in C.LOCALHOST: + if host in task_vars['hostvars']: + localhost = task_vars['hostvars'][host] + break + if 'ansible_syslog_facility' in localhost: + task_vars['ansible_syslog_facility'] = localhost['ansible_syslog_facility'] + for key in localhost: + if key.startswith("ansible_") and key.endswith("_interpreter"): + task_vars[key] = localhost[key] + + def run(self, tmp=None, task_vars=None): + ''' generates params and passes them on to the rsync module ''' + # When modifying this function be aware of the tricky convolutions + # your thoughts have to go through: + # + # In normal ansible, we connect from controller to inventory_hostname + # (playbook's hosts: field) or controller to delegate_to host and run + # a module on one of those hosts. + # + # So things that are directly related to the core of ansible are in + # terms of that sort of connection that always originate on the + # controller. + # + # In synchronize we use ansible to connect to either the controller or + # to the delegate_to host and then run rsync which makes its own + # connection from controller to inventory_hostname or delegate_to to + # inventory_hostname. + # + # That means synchronize needs to have some knowledge of the + # controller to inventory_host/delegate host that ansible typically + # establishes and use those to construct a command line for rsync to + # connect from the inventory_host to the controller/delegate. The + # challenge for coders is remembering which leg of the trip is + # associated with the conditions that you're checking at any one time. + if task_vars is None: + task_vars = dict() + + # We make a copy of the args here because we may fail and be asked to + # retry. If that happens we don't want to pass the munged args through + # to our next invocation. Munged args are single use only. + _tmp_args = self._task.args.copy() + + result = super(ActionModule, self).run(tmp, task_vars) + del tmp # tmp no longer has any effect + + # Store remote connection type + self._remote_transport = self._connection.transport + use_ssh_args = _tmp_args.pop('use_ssh_args', None) + + if use_ssh_args and self._connection.transport == 'ssh': + ssh_args = [ + self._connection.get_option('ssh_args'), + self._connection.get_option('ssh_common_args'), + self._connection.get_option('ssh_extra_args'), + ] + _tmp_args['ssh_args'] = ' '.join([a for a in ssh_args if a]) + + # Handle docker connection options + if self._remote_transport in DOCKER: + self._docker_cmd = self._connection.docker_cmd + if self._play_context.docker_extra_args: + self._docker_cmd = "%s %s" % (self._docker_cmd, self._play_context.docker_extra_args) + elif self._remote_transport in PODMAN: + self._docker_cmd = self._connection._options['podman_executable'] + if self._connection._options.get('podman_extra_args'): + self._docker_cmd = "%s %s" % (self._docker_cmd, self._connection._options['podman_extra_args']) + + # self._connection accounts for delegate_to so + # remote_transport is the transport ansible thought it would need + # between the controller and the delegate_to host or the controller + # and the remote_host if delegate_to isn't set. + + remote_transport = False + if self._connection.transport != 'local': + remote_transport = True + + try: + delegate_to = self._task.delegate_to + except (AttributeError, KeyError): + delegate_to = None + + # ssh paramiko docker buildah and local are fully supported transports. Anything + # else only works with delegate_to + if delegate_to is None and self._connection.transport not in [ + 'ssh', 'paramiko', 'local'] + DOCKER + PODMAN + BUILDAH: + result['failed'] = True + result['msg'] = ( + "synchronize uses rsync to function. rsync needs to connect to the remote " + "host via ssh, docker client or a direct filesystem " + "copy. This remote host is being accessed via %s instead " + "so it cannot work." % self._connection.transport) + return result + + # Parameter name needed by the ansible module + _tmp_args['_local_rsync_path'] = task_vars.get('ansible_rsync_path') or 'rsync' + + # rsync thinks that one end of the connection is localhost and the + # other is the host we're running the task for (Note: We use + # ansible's delegate_to mechanism to determine which host rsync is + # running on so localhost could be a non-controller machine if + # delegate_to is used) + src_host = '127.0.0.1' + inventory_hostname = task_vars.get('inventory_hostname') + dest_host_inventory_vars = task_vars['hostvars'].get(inventory_hostname) + dest_host = dest_host_inventory_vars.get('ansible_host', inventory_hostname) + + dest_host_ids = [hostid for hostid in (dest_host_inventory_vars.get('inventory_hostname'), + dest_host_inventory_vars.get('ansible_host')) + if hostid is not None] + + localhost_ports = set() + for host in C.LOCALHOST: + localhost_vars = task_vars['hostvars'].get(host, {}) + for port_var in C.MAGIC_VARIABLE_MAPPING['port']: + port = localhost_vars.get(port_var, None) + if port: + break + else: + port = C.DEFAULT_REMOTE_PORT + localhost_ports.add(port) + + # dest_is_local tells us if the host rsync runs on is the same as the + # host rsync puts the files on. This is about *rsync's connection*, + # not about the ansible connection to run the module. + dest_is_local = False + if delegate_to is None and remote_transport is False: + dest_is_local = True + elif delegate_to is not None and delegate_to in dest_host_ids: + dest_is_local = True + + # CHECK FOR NON-DEFAULT SSH PORT + inv_port = task_vars.get('ansible_port', None) or C.DEFAULT_REMOTE_PORT + if _tmp_args.get('dest_port', None) is None: + if inv_port is not None: + _tmp_args['dest_port'] = inv_port + + # Set use_delegate if we are going to run rsync on a delegated host + # instead of localhost + use_delegate = False + if delegate_to is not None and delegate_to in dest_host_ids: + # edge case: explicit delegate and dest_host are the same + # so we run rsync on the remote machine targeting its localhost + # (itself) + dest_host = '127.0.0.1' + use_delegate = True + elif delegate_to is not None and remote_transport: + # If we're delegating to a remote host then we need to use the + # delegate_to settings + use_delegate = True + + # Delegate to localhost as the source of the rsync unless we've been + # told (via delegate_to) that a different host is the source of the + # rsync + if not use_delegate and remote_transport: + # Create a connection to localhost to run rsync on + new_stdin = self._connection._new_stdin + + # Unlike port, there can be only one shell + localhost_shell = None + for host in C.LOCALHOST: + localhost_vars = task_vars['hostvars'].get(host, {}) + for shell_var in C.MAGIC_VARIABLE_MAPPING['shell']: + localhost_shell = localhost_vars.get(shell_var, None) + if localhost_shell: + break + if localhost_shell: + break + else: + localhost_shell = os.path.basename(C.DEFAULT_EXECUTABLE) + self._play_context.shell = localhost_shell + + # Unlike port, there can be only one executable + localhost_executable = None + for host in C.LOCALHOST: + localhost_vars = task_vars['hostvars'].get(host, {}) + for executable_var in C.MAGIC_VARIABLE_MAPPING['executable']: + localhost_executable = localhost_vars.get(executable_var, None) + if localhost_executable: + break + if localhost_executable: + break + else: + localhost_executable = C.DEFAULT_EXECUTABLE + self._play_context.executable = localhost_executable + + new_connection = connection_loader.get('local', self._play_context, new_stdin) + self._connection = new_connection + # Override _remote_is_local as an instance attribute specifically for the synchronize use case + # ensuring we set local tmpdir correctly + self._connection._remote_is_local = True + self._override_module_replaced_vars(task_vars) + + # SWITCH SRC AND DEST HOST PER MODE + if _tmp_args.get('mode', 'push') == 'pull': + (dest_host, src_host) = (src_host, dest_host) + + # MUNGE SRC AND DEST PER REMOTE_HOST INFO + src = _tmp_args.get('src', None) + dest = _tmp_args.get('dest', None) + if src is None or dest is None: + return dict(failed=True, msg="synchronize requires both src and dest parameters are set") + + # Determine if we need a user@ and a password + user = None + password = task_vars.get('ansible_ssh_pass', None) or task_vars.get('ansible_password', None) + if not dest_is_local: + # Src and dest rsync "path" handling + if boolean(_tmp_args.get('set_remote_user', 'yes'), strict=False): + if use_delegate: + user = task_vars.get('ansible_delegated_vars', dict()).get('ansible_user', None) + if not user: + user = task_vars.get('ansible_user') or self._play_context.remote_user + if not user: + user = C.DEFAULT_REMOTE_USER + else: + user = task_vars.get('ansible_user') or self._play_context.remote_user + + if self._templar is not None: + user = self._templar.template(user) + + # Private key handling + # Use the private_key parameter if passed else use context private_key_file + _tmp_args['private_key'] = _tmp_args.get('private_key', self._play_context.private_key_file) + + # use the mode to define src and dest's url + if _tmp_args.get('mode', 'push') == 'pull': + # src is a remote path: @, dest is a local path + src = self._process_remote(_tmp_args, src_host, src, user, inv_port in localhost_ports) + dest = self._process_origin(dest_host, dest, user) + else: + # src is a local path, dest is a remote path: @ + src = self._process_origin(src_host, src, user) + dest = self._process_remote(_tmp_args, dest_host, dest, user, inv_port in localhost_ports) + + password = dest_host_inventory_vars.get('ansible_ssh_pass', None) or dest_host_inventory_vars.get('ansible_password', None) + if self._templar is not None: + password = self._templar.template(password) + else: + # Still need to munge paths (to account for roles) even if we aren't + # copying files between hosts + src = self._get_absolute_path(path=src) + dest = self._get_absolute_path(path=dest) + + _tmp_args['_local_rsync_password'] = password + _tmp_args['src'] = src + _tmp_args['dest'] = dest + + # Allow custom rsync path argument + rsync_path = _tmp_args.get('rsync_path', None) + + # backup original become as we are probably about to unset it + become = self._play_context.become + + if not dest_is_local: + # don't escalate for docker. doing --rsync-path with docker exec fails + # and we can switch directly to the user via docker arguments + if self._play_context.become and not rsync_path and self._remote_transport not in DOCKER + PODMAN: + # If no rsync_path is set, become was originally set, and dest is + # remote then add privilege escalation here. + if self._play_context.become_method == 'sudo': + if self._play_context.become_user: + rsync_path = 'sudo -u %s rsync' % self._play_context.become_user + else: + rsync_path = 'sudo rsync' + # TODO: have to add in the rest of the become methods here + + # We cannot use privilege escalation on the machine running the + # module. Instead we run it on the machine rsync is connecting + # to. + self._play_context.become = False + + _tmp_args['rsync_path'] = rsync_path + + # If launching synchronize against docker container + # use rsync_opts to support container to override rsh options + if self._remote_transport in DOCKER + BUILDAH + PODMAN and not use_delegate: + # Replicate what we do in the module argumentspec handling for lists + if not isinstance(_tmp_args.get('rsync_opts'), MutableSequence): + tmp_rsync_opts = _tmp_args.get('rsync_opts', []) + if isinstance(tmp_rsync_opts, string_types): + tmp_rsync_opts = tmp_rsync_opts.split(',') + elif isinstance(tmp_rsync_opts, (int, float)): + tmp_rsync_opts = [to_text(tmp_rsync_opts)] + _tmp_args['rsync_opts'] = tmp_rsync_opts + + if '--blocking-io' not in _tmp_args['rsync_opts']: + _tmp_args['rsync_opts'].append('--blocking-io') + + if self._remote_transport in DOCKER + PODMAN: + if become and self._play_context.become_user: + _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('%s exec -u %s -i' % (self._docker_cmd, self._play_context.become_user))) + elif user is not None: + _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('%s exec -u %s -i' % (self._docker_cmd, user))) + else: + _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('%s exec -i' % self._docker_cmd)) + elif self._remote_transport in BUILDAH: + _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('buildah run --')) + + # run the module and store the result + result.update(self._execute_module('ansible.posix.synchronize', module_args=_tmp_args, task_vars=task_vars)) + + return result From 4512e7b1e9d195bd30a535f09f207b322da53177 Mon Sep 17 00:00:00 2001 From: Juan Antonio Valino Garcia Date: Fri, 7 Oct 2022 18:10:45 +0200 Subject: [PATCH 028/109] add changelog fragment --- changelogs/fragments/390_hosts_involved_same_password.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/390_hosts_involved_same_password.yml diff --git a/changelogs/fragments/390_hosts_involved_same_password.yml b/changelogs/fragments/390_hosts_involved_same_password.yml new file mode 100644 index 0000000..1169a31 --- /dev/null +++ b/changelogs/fragments/390_hosts_involved_same_password.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - synchronize - Fixed hosts involved in rsync require the same password From 50f87b0d15903cfc3f7cd700d550b1e633310a0b Mon Sep 17 00:00:00 2001 From: Juan Antonio Valino Garcia Date: Fri, 7 Oct 2022 18:30:49 +0200 Subject: [PATCH 029/109] move plugin to correct dir --- plugins/action/synchronize.py | 7 +- synchronize.py | 434 ---------------------------------- 2 files changed, 5 insertions(+), 436 deletions(-) delete mode 100644 synchronize.py diff --git a/plugins/action/synchronize.py b/plugins/action/synchronize.py index 7a330ac..c70db5f 100644 --- a/plugins/action/synchronize.py +++ b/plugins/action/synchronize.py @@ -347,7 +347,8 @@ class ActionModule(ActionBase): else: user = task_vars.get('ansible_user') or self._play_context.remote_user - user = self._templar.template(user) + if self._templar is not None: + user = self._templar.template(user) # Private key handling # Use the private_key parameter if passed else use context private_key_file @@ -364,13 +365,15 @@ class ActionModule(ActionBase): dest = self._process_remote(_tmp_args, dest_host, dest, user, inv_port in localhost_ports) password = dest_host_inventory_vars.get('ansible_ssh_pass', None) or dest_host_inventory_vars.get('ansible_password', None) + if self._templar is not None: + password = self._templar.template(password) else: # Still need to munge paths (to account for roles) even if we aren't # copying files between hosts src = self._get_absolute_path(path=src) dest = self._get_absolute_path(path=dest) - _tmp_args['_local_rsync_password'] = self._templar.template(password) + _tmp_args['_local_rsync_password'] = password _tmp_args['src'] = src _tmp_args['dest'] = dest diff --git a/synchronize.py b/synchronize.py deleted file mode 100644 index c70db5f..0000000 --- a/synchronize.py +++ /dev/null @@ -1,434 +0,0 @@ -# -*- coding: utf-8 -*- - -# (c) 2012-2013, Timothy Appnel -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import os.path - -from ansible import constants as C -from ansible.module_utils.six import string_types -from ansible.module_utils.six.moves import shlex_quote -from ansible.module_utils._text import to_text -from ansible.module_utils.common._collections_compat import MutableSequence -from ansible.module_utils.parsing.convert_bool import boolean -from ansible.plugins.action import ActionBase -from ansible.plugins.loader import connection_loader - - -DOCKER = ['docker', 'community.general.docker', 'community.docker.docker'] -PODMAN = ['podman', 'ansible.builtin.podman', 'containers.podman.podman'] -BUILDAH = ['buildah', 'containers.podman.buildah'] - - -class ActionModule(ActionBase): - - def _get_absolute_path(self, path): - original_path = path - - # - # Check if we have a local relative path and do not process - # * remote paths (some.server.domain:/some/remote/path/...) - # * URLs (rsync://...) - # * local absolute paths (/some/local/path/...) - # - if ':' in path or path.startswith('/'): - return path - - if self._task._role is not None: - path = self._loader.path_dwim_relative(self._task._role._role_path, 'files', path) - else: - path = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', path) - - if original_path and original_path[-1] == '/' and path[-1] != '/': - # make sure the dwim'd path ends in a trailing "/" - # if the original path did - path += '/' - - return path - - def _host_is_ipv6_address(self, host): - return ':' in to_text(host, errors='surrogate_or_strict') - - def _format_rsync_rsh_target(self, host, path, user): - ''' formats rsync rsh target, escaping ipv6 addresses if needed ''' - - user_prefix = '' - - if path.startswith('rsync://'): - return path - - # If using docker or buildah, do not add user information - if self._remote_transport not in DOCKER + PODMAN + BUILDAH and user: - user_prefix = '%s@' % (user, ) - - if self._host_is_ipv6_address(host): - return '[%s%s]:%s' % (user_prefix, host, path) - return '%s%s:%s' % (user_prefix, host, path) - - def _process_origin(self, host, path, user): - - if host not in C.LOCALHOST: - return self._format_rsync_rsh_target(host, path, user) - - path = self._get_absolute_path(path=path) - return path - - def _process_remote(self, task_args, host, path, user, port_matches_localhost_port): - """ - :arg host: hostname for the path - :arg path: file path - :arg user: username for the transfer - :arg port_matches_localhost_port: boolean whether the remote port - matches the port used by localhost's sshd. This is used in - conjunction with seeing whether the host is localhost to know - if we need to have the module substitute the pathname or if it - is a different host (for instance, an ssh tunnelled port or an - alternative ssh port to a vagrant host.) - """ - transport = self._connection.transport - # If we're connecting to a remote host or we're delegating to another - # host or we're connecting to a different ssh instance on the - # localhost then we have to format the path as a remote rsync path - if host not in C.LOCALHOST or transport != "local" or \ - (host in C.LOCALHOST and not port_matches_localhost_port): - # If we're delegating to non-localhost and but the - # inventory_hostname host is localhost then we need the module to - # fix up the rsync path to use the controller's public DNS/IP - # instead of "localhost" - if port_matches_localhost_port and host in C.LOCALHOST: - task_args['_substitute_controller'] = True - return self._format_rsync_rsh_target(host, path, user) - - path = self._get_absolute_path(path=path) - return path - - def _override_module_replaced_vars(self, task_vars): - """ Some vars are substituted into the modules. Have to make sure - that those are correct for localhost when synchronize creates its own - connection to localhost.""" - - # Clear the current definition of these variables as they came from the - # connection to the remote host - if 'ansible_syslog_facility' in task_vars: - del task_vars['ansible_syslog_facility'] - for key in list(task_vars.keys()): - if key.startswith("ansible_") and key.endswith("_interpreter"): - del task_vars[key] - - # Add the definitions from localhost - for host in C.LOCALHOST: - if host in task_vars['hostvars']: - localhost = task_vars['hostvars'][host] - break - if 'ansible_syslog_facility' in localhost: - task_vars['ansible_syslog_facility'] = localhost['ansible_syslog_facility'] - for key in localhost: - if key.startswith("ansible_") and key.endswith("_interpreter"): - task_vars[key] = localhost[key] - - def run(self, tmp=None, task_vars=None): - ''' generates params and passes them on to the rsync module ''' - # When modifying this function be aware of the tricky convolutions - # your thoughts have to go through: - # - # In normal ansible, we connect from controller to inventory_hostname - # (playbook's hosts: field) or controller to delegate_to host and run - # a module on one of those hosts. - # - # So things that are directly related to the core of ansible are in - # terms of that sort of connection that always originate on the - # controller. - # - # In synchronize we use ansible to connect to either the controller or - # to the delegate_to host and then run rsync which makes its own - # connection from controller to inventory_hostname or delegate_to to - # inventory_hostname. - # - # That means synchronize needs to have some knowledge of the - # controller to inventory_host/delegate host that ansible typically - # establishes and use those to construct a command line for rsync to - # connect from the inventory_host to the controller/delegate. The - # challenge for coders is remembering which leg of the trip is - # associated with the conditions that you're checking at any one time. - if task_vars is None: - task_vars = dict() - - # We make a copy of the args here because we may fail and be asked to - # retry. If that happens we don't want to pass the munged args through - # to our next invocation. Munged args are single use only. - _tmp_args = self._task.args.copy() - - result = super(ActionModule, self).run(tmp, task_vars) - del tmp # tmp no longer has any effect - - # Store remote connection type - self._remote_transport = self._connection.transport - use_ssh_args = _tmp_args.pop('use_ssh_args', None) - - if use_ssh_args and self._connection.transport == 'ssh': - ssh_args = [ - self._connection.get_option('ssh_args'), - self._connection.get_option('ssh_common_args'), - self._connection.get_option('ssh_extra_args'), - ] - _tmp_args['ssh_args'] = ' '.join([a for a in ssh_args if a]) - - # Handle docker connection options - if self._remote_transport in DOCKER: - self._docker_cmd = self._connection.docker_cmd - if self._play_context.docker_extra_args: - self._docker_cmd = "%s %s" % (self._docker_cmd, self._play_context.docker_extra_args) - elif self._remote_transport in PODMAN: - self._docker_cmd = self._connection._options['podman_executable'] - if self._connection._options.get('podman_extra_args'): - self._docker_cmd = "%s %s" % (self._docker_cmd, self._connection._options['podman_extra_args']) - - # self._connection accounts for delegate_to so - # remote_transport is the transport ansible thought it would need - # between the controller and the delegate_to host or the controller - # and the remote_host if delegate_to isn't set. - - remote_transport = False - if self._connection.transport != 'local': - remote_transport = True - - try: - delegate_to = self._task.delegate_to - except (AttributeError, KeyError): - delegate_to = None - - # ssh paramiko docker buildah and local are fully supported transports. Anything - # else only works with delegate_to - if delegate_to is None and self._connection.transport not in [ - 'ssh', 'paramiko', 'local'] + DOCKER + PODMAN + BUILDAH: - result['failed'] = True - result['msg'] = ( - "synchronize uses rsync to function. rsync needs to connect to the remote " - "host via ssh, docker client or a direct filesystem " - "copy. This remote host is being accessed via %s instead " - "so it cannot work." % self._connection.transport) - return result - - # Parameter name needed by the ansible module - _tmp_args['_local_rsync_path'] = task_vars.get('ansible_rsync_path') or 'rsync' - - # rsync thinks that one end of the connection is localhost and the - # other is the host we're running the task for (Note: We use - # ansible's delegate_to mechanism to determine which host rsync is - # running on so localhost could be a non-controller machine if - # delegate_to is used) - src_host = '127.0.0.1' - inventory_hostname = task_vars.get('inventory_hostname') - dest_host_inventory_vars = task_vars['hostvars'].get(inventory_hostname) - dest_host = dest_host_inventory_vars.get('ansible_host', inventory_hostname) - - dest_host_ids = [hostid for hostid in (dest_host_inventory_vars.get('inventory_hostname'), - dest_host_inventory_vars.get('ansible_host')) - if hostid is not None] - - localhost_ports = set() - for host in C.LOCALHOST: - localhost_vars = task_vars['hostvars'].get(host, {}) - for port_var in C.MAGIC_VARIABLE_MAPPING['port']: - port = localhost_vars.get(port_var, None) - if port: - break - else: - port = C.DEFAULT_REMOTE_PORT - localhost_ports.add(port) - - # dest_is_local tells us if the host rsync runs on is the same as the - # host rsync puts the files on. This is about *rsync's connection*, - # not about the ansible connection to run the module. - dest_is_local = False - if delegate_to is None and remote_transport is False: - dest_is_local = True - elif delegate_to is not None and delegate_to in dest_host_ids: - dest_is_local = True - - # CHECK FOR NON-DEFAULT SSH PORT - inv_port = task_vars.get('ansible_port', None) or C.DEFAULT_REMOTE_PORT - if _tmp_args.get('dest_port', None) is None: - if inv_port is not None: - _tmp_args['dest_port'] = inv_port - - # Set use_delegate if we are going to run rsync on a delegated host - # instead of localhost - use_delegate = False - if delegate_to is not None and delegate_to in dest_host_ids: - # edge case: explicit delegate and dest_host are the same - # so we run rsync on the remote machine targeting its localhost - # (itself) - dest_host = '127.0.0.1' - use_delegate = True - elif delegate_to is not None and remote_transport: - # If we're delegating to a remote host then we need to use the - # delegate_to settings - use_delegate = True - - # Delegate to localhost as the source of the rsync unless we've been - # told (via delegate_to) that a different host is the source of the - # rsync - if not use_delegate and remote_transport: - # Create a connection to localhost to run rsync on - new_stdin = self._connection._new_stdin - - # Unlike port, there can be only one shell - localhost_shell = None - for host in C.LOCALHOST: - localhost_vars = task_vars['hostvars'].get(host, {}) - for shell_var in C.MAGIC_VARIABLE_MAPPING['shell']: - localhost_shell = localhost_vars.get(shell_var, None) - if localhost_shell: - break - if localhost_shell: - break - else: - localhost_shell = os.path.basename(C.DEFAULT_EXECUTABLE) - self._play_context.shell = localhost_shell - - # Unlike port, there can be only one executable - localhost_executable = None - for host in C.LOCALHOST: - localhost_vars = task_vars['hostvars'].get(host, {}) - for executable_var in C.MAGIC_VARIABLE_MAPPING['executable']: - localhost_executable = localhost_vars.get(executable_var, None) - if localhost_executable: - break - if localhost_executable: - break - else: - localhost_executable = C.DEFAULT_EXECUTABLE - self._play_context.executable = localhost_executable - - new_connection = connection_loader.get('local', self._play_context, new_stdin) - self._connection = new_connection - # Override _remote_is_local as an instance attribute specifically for the synchronize use case - # ensuring we set local tmpdir correctly - self._connection._remote_is_local = True - self._override_module_replaced_vars(task_vars) - - # SWITCH SRC AND DEST HOST PER MODE - if _tmp_args.get('mode', 'push') == 'pull': - (dest_host, src_host) = (src_host, dest_host) - - # MUNGE SRC AND DEST PER REMOTE_HOST INFO - src = _tmp_args.get('src', None) - dest = _tmp_args.get('dest', None) - if src is None or dest is None: - return dict(failed=True, msg="synchronize requires both src and dest parameters are set") - - # Determine if we need a user@ and a password - user = None - password = task_vars.get('ansible_ssh_pass', None) or task_vars.get('ansible_password', None) - if not dest_is_local: - # Src and dest rsync "path" handling - if boolean(_tmp_args.get('set_remote_user', 'yes'), strict=False): - if use_delegate: - user = task_vars.get('ansible_delegated_vars', dict()).get('ansible_user', None) - if not user: - user = task_vars.get('ansible_user') or self._play_context.remote_user - if not user: - user = C.DEFAULT_REMOTE_USER - else: - user = task_vars.get('ansible_user') or self._play_context.remote_user - - if self._templar is not None: - user = self._templar.template(user) - - # Private key handling - # Use the private_key parameter if passed else use context private_key_file - _tmp_args['private_key'] = _tmp_args.get('private_key', self._play_context.private_key_file) - - # use the mode to define src and dest's url - if _tmp_args.get('mode', 'push') == 'pull': - # src is a remote path: @, dest is a local path - src = self._process_remote(_tmp_args, src_host, src, user, inv_port in localhost_ports) - dest = self._process_origin(dest_host, dest, user) - else: - # src is a local path, dest is a remote path: @ - src = self._process_origin(src_host, src, user) - dest = self._process_remote(_tmp_args, dest_host, dest, user, inv_port in localhost_ports) - - password = dest_host_inventory_vars.get('ansible_ssh_pass', None) or dest_host_inventory_vars.get('ansible_password', None) - if self._templar is not None: - password = self._templar.template(password) - else: - # Still need to munge paths (to account for roles) even if we aren't - # copying files between hosts - src = self._get_absolute_path(path=src) - dest = self._get_absolute_path(path=dest) - - _tmp_args['_local_rsync_password'] = password - _tmp_args['src'] = src - _tmp_args['dest'] = dest - - # Allow custom rsync path argument - rsync_path = _tmp_args.get('rsync_path', None) - - # backup original become as we are probably about to unset it - become = self._play_context.become - - if not dest_is_local: - # don't escalate for docker. doing --rsync-path with docker exec fails - # and we can switch directly to the user via docker arguments - if self._play_context.become and not rsync_path and self._remote_transport not in DOCKER + PODMAN: - # If no rsync_path is set, become was originally set, and dest is - # remote then add privilege escalation here. - if self._play_context.become_method == 'sudo': - if self._play_context.become_user: - rsync_path = 'sudo -u %s rsync' % self._play_context.become_user - else: - rsync_path = 'sudo rsync' - # TODO: have to add in the rest of the become methods here - - # We cannot use privilege escalation on the machine running the - # module. Instead we run it on the machine rsync is connecting - # to. - self._play_context.become = False - - _tmp_args['rsync_path'] = rsync_path - - # If launching synchronize against docker container - # use rsync_opts to support container to override rsh options - if self._remote_transport in DOCKER + BUILDAH + PODMAN and not use_delegate: - # Replicate what we do in the module argumentspec handling for lists - if not isinstance(_tmp_args.get('rsync_opts'), MutableSequence): - tmp_rsync_opts = _tmp_args.get('rsync_opts', []) - if isinstance(tmp_rsync_opts, string_types): - tmp_rsync_opts = tmp_rsync_opts.split(',') - elif isinstance(tmp_rsync_opts, (int, float)): - tmp_rsync_opts = [to_text(tmp_rsync_opts)] - _tmp_args['rsync_opts'] = tmp_rsync_opts - - if '--blocking-io' not in _tmp_args['rsync_opts']: - _tmp_args['rsync_opts'].append('--blocking-io') - - if self._remote_transport in DOCKER + PODMAN: - if become and self._play_context.become_user: - _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('%s exec -u %s -i' % (self._docker_cmd, self._play_context.become_user))) - elif user is not None: - _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('%s exec -u %s -i' % (self._docker_cmd, user))) - else: - _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('%s exec -i' % self._docker_cmd)) - elif self._remote_transport in BUILDAH: - _tmp_args['rsync_opts'].append('--rsh=' + shlex_quote('buildah run --')) - - # run the module and store the result - result.update(self._execute_module('ansible.posix.synchronize', module_args=_tmp_args, task_vars=task_vars)) - - return result From d1fbbb79058511bd2ea7e8fda4c512fab6a94450 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 8 Nov 2022 10:17:53 -0600 Subject: [PATCH 030/109] rhel4edge modules Signed-off-by: Adam Miller --- plugins/modules/r4e_rpm_ostree.py | 123 +++++++++++++++++++++++++ plugins/modules/rpm_ostree_upgrade.py | 125 ++++++++++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 plugins/modules/r4e_rpm_ostree.py create mode 100644 plugins/modules/rpm_ostree_upgrade.py diff --git a/plugins/modules/r4e_rpm_ostree.py b/plugins/modules/r4e_rpm_ostree.py new file mode 100644 index 0000000..04e25d8 --- /dev/null +++ b/plugins/modules/r4e_rpm_ostree.py @@ -0,0 +1,123 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright: Red Hat Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: r4e_rpm_ostree +version_added: 2.14.0 +short_description: Ensure packages exist in a RHEL for Edge rpm-ostree based system +description: + - Compatibility layer for using the "package" module for RHEL for Edge systems utilizing the RHEL System Roles. +author: + - Adam Miller (@maxamillion) +requirements: + - rpm-ostree +options: + name: + description: + - A package name or package specifier with version, like C(name-1.0). + - Comparison operators for package version are valid here C(>), C(<), C(>=), C(<=). Example - C(name>=1.0) + - If a previous version is specified, the task also needs to turn C(allow_downgrade) on. + See the C(allow_downgrade) documentation for caveats with downgrading packages. + - When using state=latest, this can be C('*') which means run C(yum -y update). + - You can also pass a url or a local path to a rpm file (using state=present). + To operate on several packages this can accept a comma separated string of packages or (as of 2.0) a list of packages. + aliases: [ pkg ] + type: list + elements: str + state: + description: + - Whether to install (C(present) or C(installed), C(latest)), or remove (C(absent) or C(removed)) a package. + - C(present) and C(installed) will simply ensure that a desired package is installed. + - C(latest) will update the specified package if it's not of the latest available version. + - C(absent) and C(removed) will remove the specified package. + - Default is C(None), however in effect the default action is C(present) unless the C(autoremove) option is + enabled for this module, then C(absent) is inferred. + type: str + choices: [ absent, installed, latest, present, removed ] +notes: + - This module does not support installing or removing packages to/from an overlay as this is not supported + by RHEL for Edge, packages needed should be defined in the osbuild Blueprint and provided to Image Builder + at build time. This module exists only for C(package) module compatibility. +''' + +EXAMPLES = ''' +- name: Install htop and ansible on rpm-ostree based overlay + ansible.builtin.rpm_ostree: + name: + - htop + - ansible + state: present +''' + +RETURN = """ +msg: + description: status of rpm transaction + returned: always + type: str + sample: "No changes made." +""" + +import os +import traceback + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_text + + +def locally_installed(module, pkgname): + (rc, out, err) = module.run_command('rpm -q {0}'.format(pkgname).split()) + return (rc == 0) + + +def rpm_ostree_transaction(module): + pkgs = [] + + if module.params['state'] in ['present', 'installed', 'latest']: + for pkg in module.params['name']: + if not locally_installed(module, pkg): + pkgs.append(pkg) + elif module.params['state'] in ['absent', 'removed']: + for pkg in module.params['name']: + if locally_installed(module, pkg): + pkgs.append(pkg) + + if not pkgs: + module.exit_json(msg="No changes made.") + else: + if module.params['state'] in ['present', 'installed', 'latest']: + module.fail_json(msg="The following packages are absent in the currently booted rpm-ostree commit: %s" ' '.join(pkgs)) + else: + module.fail_json(msg="The following packages are present in the currently booted rpm-ostree commit: %s" ' '.join(pkgs)) + + +def main(): + module = AnsibleModule( + argument_spec=dict( + name=dict(type='list', elements='str', aliases=['pkg'], default=[]), + state=dict(type='str', default=None, choices=['absent', 'installed', 'latest', 'present', 'removed']), + ), + ) + + # Verify that the platform is an rpm-ostree based system + if not os.path.exists("/run/ostree-booted"): + module.fail_json(msg="Module rpm_ostree is only applicable for rpm-ostree based systems.") + + try: + rpm_ostree_transaction(module) + except Exception as e: + module.fail_json(msg=to_text(e), exception=traceback.format_exc()) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/rpm_ostree_upgrade.py b/plugins/modules/rpm_ostree_upgrade.py new file mode 100644 index 0000000..069e8b7 --- /dev/null +++ b/plugins/modules/rpm_ostree_upgrade.py @@ -0,0 +1,125 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright: Red Hat Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: rpm_ostree_upgrade +short_description: Manage rpm-ostree upgrade transactions +description: + - Manage an rpm-ostree upgrade transactions +version_added: "2.14" +author: +- Adam Miller (@maxamillion) +requirements: + - rpm-ostree +options: + os: + description: + - The OSNAME upon which to operate + type: str + default: "" + required: false + cache_only: + description: + - Perform the transaction using only pre-cached data, don't download + type: bool + default: false + required: false + allow_downgrade: + description: + - Allow for the upgrade to be a chronologically older tree + type: bool + default: false + required: false + peer: + description: + - Force peer-to-peer connection instead of using system message bus + type: bool + default: false + required: false + +''' + +EXAMPLES = ''' +- name: Upgrade the rpm-ostree image without options, accept all defaults + ansible.builtin.rpm_ostree_upgrade: + +- name: Upgrade the rpm-ostree image allowing downgrades + ansible.builtin.rpm_ostree_upgrade: + allow_downgrade: true +''' + +RETURN = ''' +msg: + description: The command standard output + returned: always + type: str + sample: 'No upgrade available.' +''' + +import os +import traceback + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native, to_text + + +def rpm_ostree_transaction(module): + cmd = [] + cmd.append(module.get_bin_path("rpm-ostree")) + cmd.append('upgrade') + + if module.params['os']: + cmd += ['--os', module.params['os']] + if module.params['cache_only']: + cmd += ['--cache-only'] + if module.params['allow_downgrade']: + cmd += ['--allow-downgrade'] + if module.params['peer']: + cmd += ['--peer'] + + module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') + + rc, out, err = module.run_command(cmd) + + if rc != 0: + module.fail_json(rc=rc, msg=err) + else: + if to_text("No upgrade available.") in to_text(out): + module.exit_json(msg=out, changed=False) + else: + module.exit_json(msg=out, changed=True) + + +def main(): + module = AnsibleModule( + argument_spec=dict( + os=dict(type='str', default=''), + cache_only=dict(type='bool', default=False), + allow_downgrade=dict(type='bool', default=False), + peer=dict(type='bool', default=False), + ), + ) + + # Verify that the platform is an rpm-ostree based system + if not os.path.exists("/run/ostree-booted"): + module.fail_json(msg="Module rpm_ostree_upgrade is only applicable for rpm-ostree based systems.") + + try: + rpm_ostree_transaction(module) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + + +if __name__ == '__main__': + main() From 69228e79d281a89c358c3a0fbbf8d6ea2253f30c Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 8 Nov 2022 11:25:25 -0600 Subject: [PATCH 031/109] fix up some sanity things Signed-off-by: Adam Miller --- plugins/modules/r4e_rpm_ostree.py | 4 ++-- plugins/modules/rpm_ostree_upgrade.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/modules/r4e_rpm_ostree.py b/plugins/modules/r4e_rpm_ostree.py index 04e25d8..47b0d7e 100644 --- a/plugins/modules/r4e_rpm_ostree.py +++ b/plugins/modules/r4e_rpm_ostree.py @@ -14,7 +14,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = ''' --- module: r4e_rpm_ostree -version_added: 2.14.0 +version_added: 1.5.0 short_description: Ensure packages exist in a RHEL for Edge rpm-ostree based system description: - Compatibility layer for using the "package" module for RHEL for Edge systems utilizing the RHEL System Roles. @@ -53,7 +53,7 @@ notes: EXAMPLES = ''' - name: Install htop and ansible on rpm-ostree based overlay - ansible.builtin.rpm_ostree: + ansible.posix.r4e_rpm_ostree: name: - htop - ansible diff --git a/plugins/modules/rpm_ostree_upgrade.py b/plugins/modules/rpm_ostree_upgrade.py index 069e8b7..5b799ae 100644 --- a/plugins/modules/rpm_ostree_upgrade.py +++ b/plugins/modules/rpm_ostree_upgrade.py @@ -17,7 +17,7 @@ module: rpm_ostree_upgrade short_description: Manage rpm-ostree upgrade transactions description: - Manage an rpm-ostree upgrade transactions -version_added: "2.14" +version_added: 1.5.0 author: - Adam Miller (@maxamillion) requirements: @@ -52,10 +52,10 @@ options: EXAMPLES = ''' - name: Upgrade the rpm-ostree image without options, accept all defaults - ansible.builtin.rpm_ostree_upgrade: + ansible.posix.rpm_ostree_upgrade: - name: Upgrade the rpm-ostree image allowing downgrades - ansible.builtin.rpm_ostree_upgrade: + ansible.posix.rpm_ostree_upgrade: allow_downgrade: true ''' From a3b8fdbf25e2fc60a3879410ad7cdd5ba0d37584 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 8 Nov 2022 16:23:08 -0600 Subject: [PATCH 032/109] add changelog fragment Signed-off-by: Adam Miller --- changelogs/fragments/393_rhel_for_edge.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/393_rhel_for_edge.yml diff --git a/changelogs/fragments/393_rhel_for_edge.yml b/changelogs/fragments/393_rhel_for_edge.yml new file mode 100644 index 0000000..118d377 --- /dev/null +++ b/changelogs/fragments/393_rhel_for_edge.yml @@ -0,0 +1,4 @@ +--- +minor_changes: +- r4e_rpm_ostree - new module for validating package state on RHEL for Edge +- rpm_ostree_upgrade - new module to manage upgrades for rpm-ostree based systems From fc5894171d5daa6008ce0c723440d27ddec2ca1f Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 15 Nov 2022 16:59:48 -0600 Subject: [PATCH 033/109] add rhel_facts, move r4e_rpm_ostree to rhel_rpm_ostree Signed-off-by: Adam Miller --- plugins/modules/rhel_facts.py | 73 +++++++++++++++++++ .../{r4e_rpm_ostree.py => rhel_rpm_ostree.py} | 6 +- 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 plugins/modules/rhel_facts.py rename plugins/modules/{r4e_rpm_ostree.py => rhel_rpm_ostree.py} (97%) diff --git a/plugins/modules/rhel_facts.py b/plugins/modules/rhel_facts.py new file mode 100644 index 0000000..e8084e5 --- /dev/null +++ b/plugins/modules/rhel_facts.py @@ -0,0 +1,73 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright: Red Hat Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: rhel_facts +version_added: 1.5.0 +short_description: Facts module to set or override RHEL specific facts +description: + - Compatibility layer for using the "package" module for rpm-ostree based systems via setting the "pkg_mgr" fact correctly. +author: + - Adam Miller (@maxamillion) +requirements: + - rpm-ostree +seealso: + - module: ansible.builtin.package +options: {} +''' + +EXAMPLES = ''' +- name: Playbook to use the package module on all RHEL footprints + vars: + ansible_facts_modules: + - setup # REQUIRED to be run before all custom fact modules + - ansible.posix.rhel_facts + tasks: + - name: Ensure packages are installed + ansible.builtin.package: + name: + - htop + - ansible + state: present +''' + +RETURN = """ +ansible_facts: + description: Relevant Ansible Facts + returned: always + type: complex + sample: {'pkg_mgr': 'ansible.posix.rhel_facts'} +""" + +import os +import traceback + +from ansible.module_utils.basic import AnsibleModule + +def main(): + module = AnsibleModule( + argument_spec=dict(), + ) + + ansible_facts = {} + + # Verify that the platform is an rpm-ostree based system + if os.path.exists("/run/ostree-booted"): + ansible_facts['pkg_mgr'] = 'ansible.posix.rhel_rpm_ostree' + + module.exit_json(ansible_facts, changed=False) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/r4e_rpm_ostree.py b/plugins/modules/rhel_rpm_ostree.py similarity index 97% rename from plugins/modules/r4e_rpm_ostree.py rename to plugins/modules/rhel_rpm_ostree.py index 47b0d7e..84ca19a 100644 --- a/plugins/modules/r4e_rpm_ostree.py +++ b/plugins/modules/rhel_rpm_ostree.py @@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = ''' --- -module: r4e_rpm_ostree +module: rhel_rpm_ostree version_added: 1.5.0 short_description: Ensure packages exist in a RHEL for Edge rpm-ostree based system description: @@ -52,8 +52,8 @@ notes: ''' EXAMPLES = ''' -- name: Install htop and ansible on rpm-ostree based overlay - ansible.posix.r4e_rpm_ostree: +- name: Ensure htop and ansible are installed on rpm-ostree based RHEL + ansible.posix.rhel_rpm_ostree: name: - htop - ansible From dcd9598e48bfb219948d780fed23843c82137ec8 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Mon, 21 Nov 2022 12:14:34 -0600 Subject: [PATCH 034/109] make sanity checks happy Signed-off-by: Adam Miller --- plugins/modules/rhel_facts.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/modules/rhel_facts.py b/plugins/modules/rhel_facts.py index e8084e5..4ecfca5 100644 --- a/plugins/modules/rhel_facts.py +++ b/plugins/modules/rhel_facts.py @@ -45,19 +45,26 @@ EXAMPLES = ''' RETURN = """ ansible_facts: description: Relevant Ansible Facts - returned: always + returned: when needed type: complex - sample: {'pkg_mgr': 'ansible.posix.rhel_facts'} + contains: + pkg_mgr: + description: System-level package manager override + returned: when needed + type: str + sample: {'pkg_mgr': 'ansible.posix.rhel_facts'} """ import os -import traceback from ansible.module_utils.basic import AnsibleModule + def main(): + module = AnsibleModule( argument_spec=dict(), + supports_check_mode=True, ) ansible_facts = {} From 7df358d74fbc2a635379ccc413908ce91d0b5a04 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Mon, 21 Nov 2022 12:26:48 -0600 Subject: [PATCH 035/109] add changelog fragment Signed-off-by: Adam Miller --- changelogs/fragments/393-rpm-ostree.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/fragments/393-rpm-ostree.yml diff --git a/changelogs/fragments/393-rpm-ostree.yml b/changelogs/fragments/393-rpm-ostree.yml new file mode 100644 index 0000000..e473b39 --- /dev/null +++ b/changelogs/fragments/393-rpm-ostree.yml @@ -0,0 +1,5 @@ +--- +minor_changes: + - rhel_facts - new facts module to handle RHEL specific facts + - rhel_rpm_ostree - new module to handle RHEL rpm-ostree specific package management functionality + - rpm_ostree_upgrade - new module to automate rpm-ostree upgrades From e52ae8a9bcb1ff12de10b112279fb4a2fe691608 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 22 Nov 2022 09:03:04 -0600 Subject: [PATCH 036/109] fixes based on feedback Signed-off-by: Adam Miller --- plugins/modules/rhel_facts.py | 6 +----- plugins/modules/rhel_rpm_ostree.py | 2 +- plugins/modules/rpm_ostree_upgrade.py | 10 +++++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/plugins/modules/rhel_facts.py b/plugins/modules/rhel_facts.py index 4ecfca5..57c15f7 100644 --- a/plugins/modules/rhel_facts.py +++ b/plugins/modules/rhel_facts.py @@ -7,15 +7,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - DOCUMENTATION = ''' --- module: rhel_facts version_added: 1.5.0 -short_description: Facts module to set or override RHEL specific facts +short_description: Facts module to set or override RHEL specific facts. description: - Compatibility layer for using the "package" module for rpm-ostree based systems via setting the "pkg_mgr" fact correctly. author: diff --git a/plugins/modules/rhel_rpm_ostree.py b/plugins/modules/rhel_rpm_ostree.py index 84ca19a..e5e8f2b 100644 --- a/plugins/modules/rhel_rpm_ostree.py +++ b/plugins/modules/rhel_rpm_ostree.py @@ -76,7 +76,7 @@ from ansible.module_utils._text import to_text def locally_installed(module, pkgname): - (rc, out, err) = module.run_command('rpm -q {0}'.format(pkgname).split()) + (rc, out, err) = module.run_command('{0} -q {1}'.format(module.get_bin_path("rpm"), pkgname).split()) return (rc == 0) diff --git a/plugins/modules/rpm_ostree_upgrade.py b/plugins/modules/rpm_ostree_upgrade.py index 5b799ae..16689ca 100644 --- a/plugins/modules/rpm_ostree_upgrade.py +++ b/plugins/modules/rpm_ostree_upgrade.py @@ -16,7 +16,7 @@ DOCUMENTATION = ''' module: rpm_ostree_upgrade short_description: Manage rpm-ostree upgrade transactions description: - - Manage an rpm-ostree upgrade transactions + - Manage an rpm-ostree upgrade transactions. version_added: 1.5.0 author: - Adam Miller (@maxamillion) @@ -25,25 +25,25 @@ requirements: options: os: description: - - The OSNAME upon which to operate + - The OSNAME upon which to operate. type: str default: "" required: false cache_only: description: - - Perform the transaction using only pre-cached data, don't download + - Perform the transaction using only pre-cached data, do not download. type: bool default: false required: false allow_downgrade: description: - - Allow for the upgrade to be a chronologically older tree + - Allow for the upgrade to be a chronologically older tree. type: bool default: false required: false peer: description: - - Force peer-to-peer connection instead of using system message bus + - Force peer-to-peer connection instead of using a system message bus. type: bool default: false required: false From d0e1504f8a74f666bad417c69f3b48b9b8d141b3 Mon Sep 17 00:00:00 2001 From: Vladislav Sharapov Date: Fri, 9 Dec 2022 00:36:29 +0400 Subject: [PATCH 037/109] Fix boolean values in docs --- plugins/modules/acl.py | 16 +++++----- plugins/modules/at.py | 4 +-- plugins/modules/authorized_key.py | 30 +++++++++---------- plugins/modules/firewalld.py | 34 ++++++++++----------- plugins/modules/firewalld_info.py | 4 +-- plugins/modules/mount.py | 6 ++-- plugins/modules/patch.py | 16 +++++----- plugins/modules/seboolean.py | 8 ++--- plugins/modules/selinux.py | 2 +- plugins/modules/synchronize.py | 50 +++++++++++++++---------------- plugins/modules/sysctl.py | 20 ++++++------- 11 files changed, 95 insertions(+), 95 deletions(-) diff --git a/plugins/modules/acl.py b/plugins/modules/acl.py index a2e3d6d..37efc44 100644 --- a/plugins/modules/acl.py +++ b/plugins/modules/acl.py @@ -20,7 +20,7 @@ options: description: - The full path of the file or object. type: path - required: yes + required: true aliases: [ name ] state: description: @@ -33,13 +33,13 @@ options: description: - Whether to follow symlinks on the path if a symlink is encountered. type: bool - default: yes + default: true default: description: - - If the target is a directory, setting this to C(yes) will make it the default ACL for entities created inside the directory. - - Setting C(default) to C(yes) causes an error if the path is a file. + - If the target is a directory, setting this to C(true) will make it the default ACL for entities created inside the directory. + - Setting C(default) to C(true) causes an error if the path is a file. type: bool - default: no + default: false entity: description: - The actual user or group that the ACL applies to when matching entity types user or group are selected. @@ -69,13 +69,13 @@ options: - Incompatible with C(state=query). - Alias C(recurse) added in version 1.3.0. type: bool - default: no + default: false aliases: [ recurse ] use_nfsv4_acls: description: - Use NFSv4 ACLs instead of POSIX ACLs. type: bool - default: no + default: false recalculate_mask: description: - Select if and when to recalculate the effective right masks of the files. @@ -115,7 +115,7 @@ EXAMPLES = r''' entity: joe etype: user permissions: rw - default: yes + default: true state: present - name: Same as previous but using entry shorthand diff --git a/plugins/modules/at.py b/plugins/modules/at.py index a35ec4e..3db953e 100644 --- a/plugins/modules/at.py +++ b/plugins/modules/at.py @@ -44,7 +44,7 @@ options: description: - If a matching job is present a new job will not be added. type: bool - default: no + default: false requirements: - at author: @@ -68,7 +68,7 @@ EXAMPLES = r''' command: ls -d / >/dev/null count: 20 units: minutes - unique: yes + unique: true ''' import os diff --git a/plugins/modules/authorized_key.py b/plugins/modules/authorized_key.py index 5e37c28..424ee4a 100644 --- a/plugins/modules/authorized_key.py +++ b/plugins/modules/authorized_key.py @@ -34,13 +34,13 @@ options: manage_dir: description: - Whether this module should manage the directory of the authorized key file. - - If set to C(yes), the module will create the directory, as well as set the owner and permissions + - If set to C(true), the module will create the directory, as well as set the owner and permissions of an existing directory. - - Be sure to set C(manage_dir=no) if you are using an alternate directory for authorized_keys, + - Be sure to set C(manage_dir=false) if you are using an alternate directory for authorized_keys, as set with C(path), since you could lock yourself out of SSH access. - See the example below. type: bool - default: yes + default: true state: description: - Whether the given key (with the given key_options) should or should not be in the file. @@ -58,15 +58,15 @@ options: - This option is not loop aware, so if you use C(with_) , it will be exclusive per iteration of the loop. - If you want multiple keys in the file you need to pass them all to C(key) in a single batch as mentioned above. type: bool - default: no + default: false validate_certs: description: - This only applies if using a https url as the source of the keys. - - If set to C(no), the SSL certificates will not be validated. - - This should only set to C(no) used on personally controlled sites using self-signed certificates as it avoids verifying the source site. - - Prior to 2.1 the code worked as if this was set to C(yes). + - If set to C(false), the SSL certificates will not be validated. + - This should only set to C(false) used on personally controlled sites using self-signed certificates as it avoids verifying the source site. + - Prior to 2.1 the code worked as if this was set to C(true). type: bool - default: yes + default: true comment: description: - Change the comment on the public key. @@ -77,7 +77,7 @@ options: description: - Follow path symlink instead of replacing it. type: bool - default: no + default: false author: Ansible Core Team ''' @@ -106,7 +106,7 @@ EXAMPLES = r''' state: present key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" path: /etc/ssh/authorized_keys/charlie - manage_dir: False + manage_dir: false - name: Set up multiple authorized keys ansible.posix.authorized_key: @@ -129,14 +129,14 @@ EXAMPLES = r''' user: charlie state: present key: https://github.com/user.keys - validate_certs: False + validate_certs: false - name: Set authorized key, removing all the authorized keys already set ansible.posix.authorized_key: user: root key: "{{ lookup('file', 'public_keys/doe-jane') }}" state: present - exclusive: True + exclusive: true - name: Set authorized key for user ubuntu copying it from current user ansible.posix.authorized_key: @@ -150,7 +150,7 @@ exclusive: description: If the key has been forced to be exclusive or not. returned: success type: bool - sample: False + sample: false key: description: The key that the module was running against. returned: success @@ -170,7 +170,7 @@ manage_dir: description: Whether this module managed the directory of the authorized key file. returned: success type: bool - sample: True + sample: true path: description: Alternate path to the authorized_keys file returned: success @@ -192,7 +192,7 @@ user: type: str sample: user validate_certs: - description: This only applies if using a https url as the source of the keys. If set to C(no), the SSL certificates will not be validated. + description: This only applies if using a https url as the source of the keys. If set to C(false), the SSL certificates will not be validated. returned: success type: bool sample: true diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index 39a3b18..dba16aa 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -82,13 +82,13 @@ options: description: - Should this configuration be in the running firewalld configuration or persist across reboots. - As of Ansible 2.3, permanent operations can operate on firewalld configs when it is not running (requires firewalld >= 0.3.9). - - Note that if this is C(no), immediate is assumed C(yes). + - Note that if this is C(false), immediate is assumed C(true). type: bool immediate: description: - Should this configuration be applied immediately, if set as permanent. type: bool - default: no + default: false state: description: - Enable or disable a setting. @@ -141,29 +141,29 @@ EXAMPLES = r''' - name: permit traffic in default zone for https service ansible.posix.firewalld: service: https - permanent: yes + permanent: true state: enabled - name: do not permit traffic in default zone on port 8081/tcp ansible.posix.firewalld: port: 8081/tcp - permanent: yes + permanent: true state: disabled - ansible.posix.firewalld: port: 161-162/udp - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: zone: dmz service: http - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: rich_rule: rule service name="ftp" audit limit value="1/m" accept - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: @@ -174,44 +174,44 @@ EXAMPLES = r''' - ansible.posix.firewalld: zone: trusted interface: eth2 - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: - masquerade: yes + masquerade: true state: enabled - permanent: yes + permanent: true zone: dmz - ansible.posix.firewalld: zone: custom state: present - permanent: yes + permanent: true - ansible.posix.firewalld: zone: drop state: enabled - permanent: yes - icmp_block_inversion: yes + permanent: true + icmp_block_inversion: true - ansible.posix.firewalld: zone: drop state: enabled - permanent: yes + permanent: true icmp_block: echo-request - ansible.posix.firewalld: zone: internal state: present - permanent: yes + permanent: true target: ACCEPT - name: Redirect port 443 to 8443 with Rich Rule ansible.posix.firewalld: rich_rule: rule family=ipv4 forward-port port=443 protocol=tcp to-port=8443 zone: public - permanent: yes - immediate: yes + permanent: true + immediate: true state: enabled ''' diff --git a/plugins/modules/firewalld_info.py b/plugins/modules/firewalld_info.py index 6b1535b..29257bc 100644 --- a/plugins/modules/firewalld_info.py +++ b/plugins/modules/firewalld_info.py @@ -17,7 +17,7 @@ options: active_zones: description: Gather information about active zones. type: bool - default: no + default: false zones: description: - Gather information about specific zones. @@ -36,7 +36,7 @@ author: EXAMPLES = r''' - name: Gather information about active zones ansible.posix.firewalld_info: - active_zones: yes + active_zones: true - name: Gather information about specific zones ansible.posix.firewalld_info: diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index 58b49bc..d8e1359 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -101,13 +101,13 @@ options: - To avoid mount option conflicts, if C(noauto) specified in C(opts), mount module will ignore C(boot). type: bool - default: yes + default: true backup: description: - Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. type: bool - default: no + default: false notes: - As of Ansible 2.3, the I(name) option has been changed to I(path) as default, but I(name) still works as well. @@ -181,7 +181,7 @@ EXAMPLES = r''' src: 192.168.1.100:/nfs/ssd/shared_data path: /mnt/shared_data opts: rw,sync,hard - boot: no + boot: false state: mounted fstype: nfs ''' diff --git a/plugins/modules/patch.py b/plugins/modules/patch.py index ea2c618..0c6fe47 100644 --- a/plugins/modules/patch.py +++ b/plugins/modules/patch.py @@ -50,10 +50,10 @@ options: default: present remote_src: description: - - If C(no), it will search for src at originating/controller machine, if C(yes) it will + - If C(false), it will search for src at originating/controller machine, if C(true) it will go to the remote/target machine for the C(src). type: bool - default: no + default: false strip: description: - Number that indicates the smallest prefix containing leading slashes @@ -65,20 +65,20 @@ options: description: - Passes C(--backup --version-control=numbered) to patch, producing numbered backup copies. type: bool - default: no + default: false binary: description: - - Setting to C(yes) will disable patch's heuristic for transforming CRLF + - Setting to C(true) will disable patch's heuristic for transforming CRLF line endings into LF. - Line endings of src and dest must match. - - If set to C(no), C(patch) will replace CRLF in C(src) files on POSIX. + - If set to C(false), C(patch) will replace CRLF in C(src) files on POSIX. type: bool - default: no + default: false ignore_whitespace: description: - - Setting to C(yes) will ignore white space changes between patch and input.. + - Setting to C(true) will ignore white space changes between patch and input. type: bool - default: no + default: false notes: - This module requires GNU I(patch) utility to be installed on the remote host. ''' diff --git a/plugins/modules/seboolean.py b/plugins/modules/seboolean.py index f4d8cf4..657b7fa 100644 --- a/plugins/modules/seboolean.py +++ b/plugins/modules/seboolean.py @@ -22,9 +22,9 @@ options: type: str persistent: description: - - Set to C(yes) if the boolean setting should survive a reboot. + - Set to C(true) if the boolean setting should survive a reboot. type: bool - default: 'no' + default: false state: description: - Desired boolean value @@ -49,8 +49,8 @@ EXAMPLES = r''' - name: Set httpd_can_network_connect flag on and keep it persistent across reboots ansible.posix.seboolean: name: httpd_can_network_connect - state: yes - persistent: yes + state: true + persistent: true ''' import os diff --git a/plugins/modules/selinux.py b/plugins/modules/selinux.py index 89e6b63..14110fe 100644 --- a/plugins/modules/selinux.py +++ b/plugins/modules/selinux.py @@ -32,7 +32,7 @@ options: description: - If set to I(true), will update also the kernel boot parameters when disabling/enabling SELinux. - The C(grubby) tool must be present on the target system for this to work. - default: no + default: false type: bool version_added: '1.4.0' configfile: diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 86cf360..260fac8 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -53,36 +53,36 @@ options: description: - Mirrors the rsync archive flag, enables recursive, links, perms, times, owner, group flags and -D. type: bool - default: yes + default: true checksum: description: - Skip based on checksum, rather than mod-time & size; Note that that "archive" option is still enabled by default - the "checksum" option will not disable it. type: bool - default: no + default: false compress: description: - Compress file data during the transfer. - In most cases, leave this enabled unless it causes problems. type: bool - default: yes + default: true existing_only: description: - Skip creating new files on receiver. type: bool - default: no + default: false delete: description: - Delete files in I(dest) that do not exist (after transfer, not before) in the I(src) path. - - This option requires I(recursive=yes). + - This option requires I(recursive=true). - This option ignores excluded files and behaves like the rsync opt C(--delete-after). type: bool - default: no + default: false dirs: description: - Transfer directories without recursing. type: bool - default: no + default: false recursive: description: - Recurse into directories. @@ -97,7 +97,7 @@ options: description: - Copy symlinks as the item that they point to (the referent) is copied, rather than the symlink. type: bool - default: no + default: false perms: description: - Preserve permissions. @@ -132,26 +132,26 @@ options: description: - Put user@ for the remote paths. - If you have a custom ssh config to define the remote user for a host - that does not match the inventory user, you should set this parameter to C(no). + that does not match the inventory user, you should set this parameter to C(false). type: bool - default: yes + default: true use_ssh_args: description: - In Ansible 2.10 and lower, it uses the ssh_args specified in C(ansible.cfg). - In Ansible 2.11 and onwards, when set to C(true), it uses all SSH connection configurations like C(ansible_ssh_args), C(ansible_ssh_common_args), and C(ansible_ssh_extra_args). type: bool - default: no + default: false ssh_connection_multiplexing: description: - SSH connection multiplexing for rsync is disabled by default to prevent misconfigured ControlSockets from resulting in failed SSH connections. This is accomplished by setting the SSH C(ControlSocket) to C(none). - - Set this option to C(yes) to allow multiplexing and reduce SSH connection overhead. - - Note that simply setting this option to C(yes) is not enough; + - Set this option to C(true) to allow multiplexing and reduce SSH connection overhead. + - Note that simply setting this option to C(true) is not enough; You must also configure SSH connection multiplexing in your SSH client config by setting values for C(ControlMaster), C(ControlPersist) and C(ControlPath). type: bool - default: no + default: false rsync_opts: description: - Specify additional rsync options by passing in an array. @@ -163,12 +163,12 @@ options: description: - Tells rsync to keep the partial file which should make a subsequent transfer of the rest of the file much faster. type: bool - default: no + default: false verify_host: description: - Verify destination host key. type: bool - default: no + default: false private_key: description: - Specify the private key to use for SSH-based rsync connections (e.g. C(~/.ssh/id_rsa)). @@ -184,7 +184,7 @@ options: - This option puts the temporary file from each updated file into a holding directory until the end of the transfer, at which time all the files are renamed into place in rapid succession. type: bool - default: yes + default: true version_added: '1.3.0' notes: @@ -252,27 +252,27 @@ EXAMPLES = r''' ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - archive: no + archive: false - name: Synchronization with --archive options enabled except for --recursive ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - recursive: no + recursive: false - name: Synchronization with --archive options enabled except for --times, with --checksum option enabled ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - checksum: yes - times: no + checksum: true + times: false - name: Synchronization without --archive options enabled except use --links ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - archive: no - links: yes + archive: false + links: true - name: Synchronization of two paths both on the control machine ansible.posix.synchronize: @@ -302,8 +302,8 @@ EXAMPLES = r''' ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - delete: yes - recursive: yes + delete: true + recursive: true # This specific command is granted su privileges on the destination - name: Synchronize using an alternate rsync command diff --git a/plugins/modules/sysctl.py b/plugins/modules/sysctl.py index b82b2e4..542b3c5 100644 --- a/plugins/modules/sysctl.py +++ b/plugins/modules/sysctl.py @@ -38,14 +38,14 @@ options: description: - Use this option to ignore errors about unknown keys. type: bool - default: 'no' + default: false reload: description: - - If C(yes), performs a I(/sbin/sysctl -p) if the C(sysctl_file) is - updated. If C(no), does not reload I(sysctl) even if the + - If C(true), performs a I(/sbin/sysctl -p) if the C(sysctl_file) is + updated. If C(false), does not reload I(sysctl) even if the C(sysctl_file) is updated. type: bool - default: 'yes' + default: true sysctl_file: description: - Specifies the absolute path to C(sysctl.conf), if not C(/etc/sysctl.conf). @@ -53,9 +53,9 @@ options: type: path sysctl_set: description: - - Verify token value with the sysctl command and set with -w if necessary + - Verify token value with the sysctl command and set with -w if necessary. type: bool - default: 'no' + default: false author: - David CHANIAL (@davixx) ''' @@ -78,21 +78,21 @@ EXAMPLES = r''' name: kernel.panic value: '3' sysctl_file: /tmp/test_sysctl.conf - reload: no + reload: false # Set ip forwarding on in /proc and verify token value with the sysctl command - ansible.posix.sysctl: name: net.ipv4.ip_forward value: '1' - sysctl_set: yes + sysctl_set: true # Set ip forwarding on in /proc and in the sysctl file and reload if necessary - ansible.posix.sysctl: name: net.ipv4.ip_forward value: '1' - sysctl_set: yes + sysctl_set: true state: present - reload: yes + reload: true ''' # ============================================================== From adcb28f8069f33d0d93628ec106e3b19a7f9ee4e Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Tue, 13 Dec 2022 10:40:51 -0500 Subject: [PATCH 038/109] Update documented default value for acl's entry parameter to match implementation. --- plugins/modules/acl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/acl.py b/plugins/modules/acl.py index a2e3d6d..119520e 100644 --- a/plugins/modules/acl.py +++ b/plugins/modules/acl.py @@ -44,6 +44,7 @@ options: description: - The actual user or group that the ACL applies to when matching entity types user or group are selected. type: str + default: "" etype: description: - The entity type of the ACL to apply, see C(setfacl) documentation for more info. From 0fff8fde30b8daee3ab66699bce082839576dd28 Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Tue, 13 Dec 2022 11:48:39 -0500 Subject: [PATCH 039/109] Update documented default value for rhel_rpm_ostree's name parameter to match implementation. --- plugins/modules/rhel_rpm_ostree.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/rhel_rpm_ostree.py b/plugins/modules/rhel_rpm_ostree.py index e5e8f2b..0976e02 100644 --- a/plugins/modules/rhel_rpm_ostree.py +++ b/plugins/modules/rhel_rpm_ostree.py @@ -35,6 +35,7 @@ options: aliases: [ pkg ] type: list elements: str + default: [] state: description: - Whether to install (C(present) or C(installed), C(latest)), or remove (C(absent) or C(removed)) a package. From bf0ad4aad236ba719a41caf812d8f8e03ae966bf Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Tue, 13 Dec 2022 12:46:39 -0500 Subject: [PATCH 040/109] Document pr #401 as a changelog fragment. --- changelogs/fragments/401_document_module_default_values.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/401_document_module_default_values.yml diff --git a/changelogs/fragments/401_document_module_default_values.yml b/changelogs/fragments/401_document_module_default_values.yml new file mode 100644 index 0000000..8a631dc --- /dev/null +++ b/changelogs/fragments/401_document_module_default_values.yml @@ -0,0 +1,4 @@ +--- +trivial: +- acl - document default value for the ``entry`` parameter +- rhel_rpm_ostree - document default value for the ``name`` parameter From 4229db1bbec16f7a8401acf296f97763d3f55c35 Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Tue, 13 Dec 2022 17:27:59 -0500 Subject: [PATCH 041/109] Fix issue where interfaces could not be added to a zone when firewalld is offline. Resolves issue #357. --- plugins/modules/firewalld.py | 14 +-- .../firewalld/tasks/interface_test_cases.yml | 87 +++++++++++++++++++ .../targets/firewalld/tasks/run_all_tests.yml | 3 + 3 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 tests/integration/targets/firewalld/tasks/interface_test_cases.yml diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index 39a3b18..960a42d 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -469,6 +469,7 @@ class InterfaceTransaction(FirewallTransaction): old_zone_obj = self.fw.config.get_zone(zone) if interface in old_zone_obj.interfaces: iface_zone_objs.append(old_zone_obj) + if len(iface_zone_objs) > 1: # Even it shouldn't happen, it's actually possible that # the same interface is in several zone XML files @@ -478,18 +479,17 @@ class InterfaceTransaction(FirewallTransaction): len(iface_zone_objs) ) ) - old_zone_obj = iface_zone_objs[0] - if old_zone_obj.name != self.zone: - old_zone_settings = FirewallClientZoneSettings( - self.fw.config.get_zone_config(old_zone_obj) - ) + elif len(iface_zone_objs) == 1 and iface_zone_objs[0].name != self.zone: + old_zone_obj = iface_zone_objs[0] + old_zone_config = self.fw.config.get_zone_config(old_zone_obj) + old_zone_settings = FirewallClientZoneSettings(list(old_zone_config)) old_zone_settings.removeInterface(interface) # remove from old self.fw.config.set_zone_config( old_zone_obj, old_zone_settings.settings ) - fw_settings.addInterface(interface) # add to new - self.fw.config.set_zone_config(fw_zone, fw_settings.settings) + fw_settings.addInterface(interface) # add to new + self.fw.config.set_zone_config(fw_zone, fw_settings.settings) else: old_zone_name = self.fw.config().getZoneOfInterface(interface) if old_zone_name != self.zone: diff --git a/tests/integration/targets/firewalld/tasks/interface_test_cases.yml b/tests/integration/targets/firewalld/tasks/interface_test_cases.yml new file mode 100644 index 0000000..e7130f7 --- /dev/null +++ b/tests/integration/targets/firewalld/tasks/interface_test_cases.yml @@ -0,0 +1,87 @@ +# Test playbook for the firewalld module - interface operations +# (c) 2022, Gregory Furlong +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: Validate adding interface + block: + - name: Add lo interface to trusted zone + ansible.posix.firewalld: + interface: lo + zone: trusted + permanent: Yes + state: enabled + register: result + + - name: assert lo was added to trusted zone + assert: + that: + - result is changed + + - name: Add lo interface to trusted zone (verify not changed) + ansible.posix.firewalld: + interface: lo + zone: trusted + permanent: Yes + state: enabled + register: result + + - name: assert lo was added to trusted zone (verify not changed) + assert: + that: + - result is not changed + +- name: Validate moving interfaces + block: + - name: Move lo interface from trusted zone to internal zone + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: Yes + state: enabled + register: result + + - name: Assert lo was moved from trusted zone to internal zone + assert: + that: + - result is changed + + - name: Move lo interface from trusted zone to internal zone (verify not changed) + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: Yes + state: enabled + register: result + + - name: assert lo was moved from trusted zone to internal zone (verify not changed) + assert: + that: + - result is not changed + +- name: Validate removing interface + block: + - name: Remove lo interface from internal zone + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: Yes + state: disabled + register: result + + - name: Assert lo interface was removed from internal zone + assert: + that: + - result is changed + + - name: Remove lo interface from internal zone (verify not changed) + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: Yes + state: disabled + register: result + + - name: Assert lo interface was removed from internal zone (verify not changed) + assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index 4270e89..b7540f3 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -21,3 +21,6 @@ # firewalld port forwarding operation test cases - include_tasks: port_forward_test_cases.yml + +# firewalld interface operation test cases +- include_tasks: interface_test_cases.yml From 9575b9be6429f17f22a091f796d2f6fd2dff1e22 Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Tue, 13 Dec 2022 18:02:56 -0500 Subject: [PATCH 042/109] Add changelog fragment documenting PR #402 --- .../fragments/402_firewall_fix_offline_interface_add.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/402_firewall_fix_offline_interface_add.yml diff --git a/changelogs/fragments/402_firewall_fix_offline_interface_add.yml b/changelogs/fragments/402_firewall_fix_offline_interface_add.yml new file mode 100644 index 0000000..e59a45d --- /dev/null +++ b/changelogs/fragments/402_firewall_fix_offline_interface_add.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - firewall - Fix issue where adding an interface to a zone would fail when the daemon is offline From e647e147a1bfba01414c0ef6e7ede0c7adca5596 Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Wed, 14 Dec 2022 10:50:15 -0500 Subject: [PATCH 043/109] Update firewalld module to consider the value of the masquerade parameter when determining if masquerade should be enabled/disabled. --- plugins/modules/firewalld.py | 19 +- .../firewalld/tasks/masquerade_test_cases.yml | 172 ++++++++++++++++++ .../targets/firewalld/tasks/run_all_tests.yml | 3 + 3 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index 39a3b18..e700b88 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -973,12 +973,21 @@ def main(): msgs = msgs + transaction_msgs if masquerade is not None: + # Type of masquerade will be changed to boolean in a future release. + masquerade_status = True + try: + masquerade_status = boolean(masquerade, True) + except TypeError: + module.warn('The value of the masquerade option is "%s". ' + 'The type of the option will be changed from string to boolean in a future release. ' + 'To avoid unexpected behavior, please change the value to boolean.' % masquerade) + expected_state = 'enabled' if (desired_state == 'enabled') == masquerade_status else 'disabled' transaction = MasqueradeTransaction( module, action_args=(), zone=zone, - desired_state=desired_state, + desired_state=expected_state, permanent=permanent, immediate=immediate, ) @@ -986,14 +995,6 @@ def main(): changed, transaction_msgs = transaction.run() msgs = msgs + transaction_msgs - # Type of masquerade will be changed to boolean in a future release. - try: - boolean(masquerade, True) - except TypeError: - module.warn('The value of the masquerade option is "%s". ' - 'The type of the option will be changed from string to boolean in a future release. ' - 'To avoid unexpected behavior, please change the value to boolean.' % masquerade) - if target is not None: transaction = ZoneTargetTransaction( diff --git a/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml b/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml new file mode 100644 index 0000000..fd93397 --- /dev/null +++ b/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml @@ -0,0 +1,172 @@ +# Test playbook for the firewalld module +# (c) 2022, Gregory Furlong +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: Masquerade enabled when masquerade is truthy and state is enabled + block: + - name: Testing enable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: yes + permanent: yes + state: enabled + register: result + + - name: assert masquerade is enabled + assert: + that: + - result is changed + + - name: Testing enable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: yes + permanent: yes + state: enabled + register: result + + - name: assert masquerade is enabled (verify not changed) + assert: + that: + - result is not changed + +- name: Masquerade disabled when masquerade is falsy and state is enabled + block: + - name: Testing disable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: no + permanent: yes + state: enabled + register: result + + - name: assert masquerade is disabled + assert: + that: + - result is changed + + - name: Testing disable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: no + permanent: yes + state: enabled + register: result + + - name: assert masquerade is disabled (verify not changed) + assert: + that: + - result is not changed + +- name: Masquerade enabled when masquerade is falsy and state is disabled + block: + - name: Testing enable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: no + permanent: yes + state: disabled + register: result + + - name: assert masquerade is enabled + assert: + that: + - result is changed + + - name: Testing enable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: no + permanent: yes + state: disabled + register: result + + - name: assert masquerade is enabled (verify not changed) + assert: + that: + - result is not changed + +- name: Masquerade disabled when masquerade is truthy and state is disabled + block: + - name: Testing disable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: yes + permanent: yes + state: disabled + register: result + + - name: assert masquerade is disabled + assert: + that: + - result is changed + + - name: Testing disable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: yes + permanent: yes + state: disabled + register: result + + - name: assert masquerade is disabled (verify not changed) + assert: + that: + - result is not changed + +# Validate backwards compatible behavior until masquerade is switched from string to boolean type +- name: Masquerade enabled when masquerade is non-boolean string and state is enabled + block: + - name: Testing enable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: 'some string' + permanent: yes + state: enabled + register: result + + - name: assert masquerade is enabled + assert: + that: + - result is changed + + - name: Testing enable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: 'some string' + permanent: yes + state: enabled + register: result + + - name: assert masquerade is enabled (verify not changed) + assert: + that: + - result is not changed + +- name: Masquerade disabled when masquerade is non-boolean string and state is disabled + block: + - name: Testing disable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: 'some string' + permanent: yes + state: disabled + register: result + + - name: assert masquerade is disabled + assert: + that: + - result is changed + + - name: Testing disable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: 'some string' + permanent: yes + state: disabled + register: result + + - name: assert masquerade is disabled (verify not changed) + assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index 4270e89..ecc556d 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -21,3 +21,6 @@ # firewalld port forwarding operation test cases - include_tasks: port_forward_test_cases.yml + +# firewalld masquerade operation test cases +- include_tasks: masquerade_test_cases.yml From e97087e6161789e6dab816da577f5d9ec7cc590f Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Wed, 14 Dec 2022 11:07:53 -0500 Subject: [PATCH 044/109] Update firewalld module to consider the value of the icmp_block_inversion parameter when determining if icmp_block_inversion should be enabled/disabled. --- plugins/modules/firewalld.py | 19 +- .../tasks/icmp_block_inversion_test_cases.yml | 172 ++++++++++++++++++ .../firewalld/tasks/masquerade_test_cases.yml | 2 +- .../targets/firewalld/tasks/run_all_tests.yml | 3 + 4 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index e700b88..4e49ce1 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -846,12 +846,21 @@ def main(): msgs.append("Changed icmp-block %s to %s" % (icmp_block, desired_state)) if icmp_block_inversion is not None: + # Type of icmp_block_inversion will be changed to boolean in a future release. + icmp_block_inversion_status = True + try: + icmp_block_inversion_status = boolean(icmp_block_inversion, True) + except TypeError: + module.warn('The value of the icmp_block_inversion option is "%s". ' + 'The type of the option will be changed from string to boolean in a future release. ' + 'To avoid unexpected behavior, please change the value to boolean.' % icmp_block_inversion) + expected_state = 'enabled' if (desired_state == 'enabled') == icmp_block_inversion_status else 'disabled' transaction = IcmpBlockInversionTransaction( module, action_args=(), zone=zone, - desired_state=desired_state, + desired_state=expected_state, permanent=permanent, immediate=immediate, ) @@ -861,14 +870,6 @@ def main(): if changed is True: msgs.append("Changed icmp-block-inversion %s to %s" % (icmp_block_inversion, desired_state)) - # Type of icmp_block_inversion will be changed to boolean in a future release. - try: - boolean(icmp_block_inversion, True) - except TypeError: - module.warn('The value of the icmp_block_inversion option is "%s". ' - 'The type of the option will be changed from string to boolean in a future release. ' - 'To avoid unexpected behavior, please change the value to boolean.' % icmp_block_inversion) - if service is not None: transaction = ServiceTransaction( diff --git a/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml b/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml new file mode 100644 index 0000000..62fcbe4 --- /dev/null +++ b/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml @@ -0,0 +1,172 @@ +# Test playbook for the firewalld module - icmp block inversion operations +# (c) 2022, Gregory Furlong +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: Icmp block inversion enabled when icmp block inversion is truthy and state is enabled + block: + - name: Testing enable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: yes + permanent: yes + state: enabled + register: result + + - name: assert icmp block inversion is enabled + assert: + that: + - result is changed + + - name: Testing enable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: yes + permanent: yes + state: enabled + register: result + + - name: assert icmp block inversion is enabled (verify not changed) + assert: + that: + - result is not changed + +- name: Icmp block inversion disabled when icmp block inversion is falsy and state is enabled + block: + - name: Testing disable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: no + permanent: yes + state: enabled + register: result + + - name: assert icmp block inversion is disabled + assert: + that: + - result is changed + + - name: Testing disable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: no + permanent: yes + state: enabled + register: result + + - name: assert icmp block inversion is disabled (verify not changed) + assert: + that: + - result is not changed + +- name: Icmp block inversion enabled when icmp block inversion is falsy and state is disabled + block: + - name: Testing enable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: no + permanent: yes + state: disabled + register: result + + - name: assert icmp block inversion is enabled + assert: + that: + - result is changed + + - name: Testing enable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: no + permanent: yes + state: disabled + register: result + + - name: assert icmp block inversion is enabled (verify not changed) + assert: + that: + - result is not changed + +- name: Icmp block inversion disabled when icmp block inversion is truthy and state is disabled + block: + - name: Testing disable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: yes + permanent: yes + state: disabled + register: result + + - name: assert icmp block inversion is disabled + assert: + that: + - result is changed + + - name: Testing disable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: yes + permanent: yes + state: disabled + register: result + + - name: assert icmp block inversion is disabled (verify not changed) + assert: + that: + - result is not changed + +# Validate backwards compatible behavior until icmp block inversion is switched from string to boolean type +- name: Icmp block inversion enabled when icmp block inversion is non-boolean string and state is enabled + block: + - name: Testing enable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: 'some string' + permanent: yes + state: enabled + register: result + + - name: assert icmp block inversion is enabled + assert: + that: + - result is changed + + - name: Testing enable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: 'some string' + permanent: yes + state: enabled + register: result + + - name: assert icmp block inversion is enabled (verify not changed) + assert: + that: + - result is not changed + +- name: Icmp block inversion disabled when icmp block inversion is non-boolean string and state is disabled + block: + - name: Testing disable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: 'some string' + permanent: yes + state: disabled + register: result + + - name: assert icmp block inversion is disabled + assert: + that: + - result is changed + + - name: Testing disable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: 'some string' + permanent: yes + state: disabled + register: result + + - name: assert icmp block inversion is disabled (verify not changed) + assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml b/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml index fd93397..860378f 100644 --- a/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml @@ -1,4 +1,4 @@ -# Test playbook for the firewalld module +# Test playbook for the firewalld module - masquerade operations # (c) 2022, Gregory Furlong # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index ecc556d..45d1288 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -24,3 +24,6 @@ # firewalld masquerade operation test cases - include_tasks: masquerade_test_cases.yml + +# firewalld icmp block inversion operation test cases +- include_tasks: icmp_block_inversion_test_cases.yml From cc93ee82329f48f0ab56f65bf6ccb5aa32c314fa Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Wed, 14 Dec 2022 11:14:35 -0500 Subject: [PATCH 045/109] Add a changelog fragment in preparation for the pull request. --- .../404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml diff --git a/changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml b/changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml new file mode 100644 index 0000000..144b80e --- /dev/null +++ b/changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - firewalld - Consider value of masquerade and icmp_block_inversion parameters when a boolean like value is passed From c4742cfa810742c305d90b5461285f38810f7abc Mon Sep 17 00:00:00 2001 From: Vladislav Sharapov Date: Wed, 14 Dec 2022 20:44:50 +0400 Subject: [PATCH 046/109] Add changelog fragment --- changelogs/fragments/400-fix-boolean-values-in-docs.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/400-fix-boolean-values-in-docs.yml diff --git a/changelogs/fragments/400-fix-boolean-values-in-docs.yml b/changelogs/fragments/400-fix-boolean-values-in-docs.yml new file mode 100644 index 0000000..8ea04a7 --- /dev/null +++ b/changelogs/fragments/400-fix-boolean-values-in-docs.yml @@ -0,0 +1,3 @@ +--- +trivial: + - Change boolean values in documentation to ``true/false`` (https://github.com/ansible-collections/ansible.posix/pull/400). From d6a997b37d4c19c48f336a9415aa72658ec4cc92 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Thu, 22 Dec 2022 15:42:38 +0900 Subject: [PATCH 047/109] Modify firewalld port test cases to avoid port duplication. Signed-off-by: Hideki Saito --- changelogs/fragments/407_fix_firewalld_port_test.yml | 3 +++ .../integration/targets/firewalld/tasks/port_test_cases.yml | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/407_fix_firewalld_port_test.yml diff --git a/changelogs/fragments/407_fix_firewalld_port_test.yml b/changelogs/fragments/407_fix_firewalld_port_test.yml new file mode 100644 index 0000000..0b82489 --- /dev/null +++ b/changelogs/fragments/407_fix_firewalld_port_test.yml @@ -0,0 +1,3 @@ +--- +trivial: +- Fix firewalld port test cases to avoid port duplicatation. diff --git a/tests/integration/targets/firewalld/tasks/port_test_cases.yml b/tests/integration/targets/firewalld/tasks/port_test_cases.yml index 2beb8ca..c62c242 100644 --- a/tests/integration/targets/firewalld/tasks/port_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/port_test_cases.yml @@ -4,7 +4,7 @@ - name: firewalld port range test permanent enabled firewalld: - port: 5500-6950/tcp + port: 5500-6850/tcp permanent: true state: enabled register: result @@ -16,7 +16,7 @@ - name: firewalld port range test permanent enabled rerun (verify not changed) firewalld: - port: 5500-6950/tcp + port: 5500-6850/tcp permanent: true state: enabled register: result @@ -57,7 +57,7 @@ state: disabled loop: - 6900/tcp - - 5500-6950/tcp + - 5500-6850/tcp - name: firewalld port test permanent enabled firewalld: From f109c162b002feb02562c3502a880bea43e408c3 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 11 Jan 2023 19:21:27 +0900 Subject: [PATCH 048/109] Update AZP CI matrix - Addresses https://github.com/ansible-collections/news-for-maintainers/issues/31 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 16 ++++++++++------ changelogs/fragments/409_update_azp_matrix.yml | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/409_update_azp_matrix.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 9aef200..9fb818b 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -53,8 +53,8 @@ stages: targets: - name: CentOS 7 test: centos7 - - name: Fedora 36 - test: fedora36 + - name: Fedora 37 + test: fedora37 - name: openSUSE 15 py3 test: opensuse15 - name: Ubuntu 20.04 @@ -209,10 +209,12 @@ stages: test: macos/12.0 - name: RHEL 7.9 test: rhel/7.9 - - name: RHEL 8.6 - test: rhel/8.6 - - name: RHEL 9.0 - test: rhel/9.0 + - name: RHEL 8.7 + test: rhel/8.7 + - name: RHEL 9.1 + test: rhel/9.1 + - name: FreeBSD 12.4 + test: freebsd/12.4 - name: FreeBSD 13.1 test: freebsd/13.1 - stage: Remote_2_14 @@ -231,6 +233,8 @@ stages: test: rhel/8.6 - name: RHEL 9.0 test: rhel/9.0 + - name: FreeBSD 12.3 + test: freebsd/12.3 - name: FreeBSD 13.1 test: freebsd/13.1 - stage: Remote_2_13 diff --git a/changelogs/fragments/409_update_azp_matrix.yml b/changelogs/fragments/409_update_azp_matrix.yml new file mode 100644 index 0000000..23d7a86 --- /dev/null +++ b/changelogs/fragments/409_update_azp_matrix.yml @@ -0,0 +1,3 @@ +--- +trivial: + - CI - Update AZP CI matrix (https://github.com/ansible-collections/ansible.posix/issues/408). From 6695394af67a2b988d522f603794542a2e9a1bca Mon Sep 17 00:00:00 2001 From: Gregory Furlong Date: Tue, 29 Nov 2022 14:57:04 -0500 Subject: [PATCH 049/109] Update ZoneTransaction to support adding/removing zones when firewalld is offline. Add integration test cases for adding/removing a custom zone with the firewalld module. --- ...ewalld_create_remove_zone_when_offline.yml | 3 ++ plugins/modules/firewalld.py | 24 ++++++---- .../targets/firewalld/tasks/run_all_tests.yml | 3 ++ .../firewalld/tasks/zone_test_cases.yml | 47 +++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml create mode 100644 tests/integration/targets/firewalld/tasks/zone_test_cases.yml diff --git a/changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml b/changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml new file mode 100644 index 0000000..691fc65 --- /dev/null +++ b/changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fixed a bug where firewalld module fails to create/remove zones when the daemon is stopped diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index dba16aa..52a2a5a 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -675,25 +675,33 @@ class ZoneTransaction(FirewallTransaction): self.module.fail_json(msg=self.tx_not_permanent_error_msg) def get_enabled_permanent(self): - zones = self.fw.config().listZones() - zone_names = [self.fw.config().getZone(z).get_property("name") for z in zones] - if self.zone in zone_names: - return True + if self.fw_offline: + zones = self.fw.config.get_zones() + zone_names = [self.fw.config.get_zone(z).name for z in zones] else: - return False + zones = self.fw.config().listZones() + zone_names = [self.fw.config().getZone(z).get_property("name") for z in zones] + return self.zone in zone_names def set_enabled_immediate(self): self.module.fail_json(msg=self.tx_not_permanent_error_msg) def set_enabled_permanent(self): - self.fw.config().addZone(self.zone, FirewallClientZoneSettings()) + if self.fw_offline: + self.fw.config.new_zone(self.zone, FirewallClientZoneSettings().settings) + else: + self.fw.config().addZone(self.zone, FirewallClientZoneSettings()) def set_disabled_immediate(self): self.module.fail_json(msg=self.tx_not_permanent_error_msg) def set_disabled_permanent(self): - zone_obj = self.fw.config().getZoneByName(self.zone) - zone_obj.remove() + if self.fw_offline: + zone = self.fw.config.get_zone(self.zone) + self.fw.config.remove_zone(zone) + else: + zone_obj = self.fw.config().getZoneByName(self.zone) + zone_obj.remove() class ForwardPortTransaction(FirewallTransaction): diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index 4270e89..5027c1c 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -16,6 +16,9 @@ # firewalld source operation test cases - include_tasks: source_test_cases.yml +# firewalld zone operation test cases +- include_tasks: zone_test_cases.yml + # firewalld zone target operation test cases - include_tasks: zone_target_test_cases.yml diff --git a/tests/integration/targets/firewalld/tasks/zone_test_cases.yml b/tests/integration/targets/firewalld/tasks/zone_test_cases.yml new file mode 100644 index 0000000..c9d54c6 --- /dev/null +++ b/tests/integration/targets/firewalld/tasks/zone_test_cases.yml @@ -0,0 +1,47 @@ +- name: firewalld create zone custom + firewalld: + zone: custom + permanent: True + state: present + register: result + +- name: assert firewalld custom zone created worked + assert: + that: + - result is changed + +- name: firewalld create zone custom rerun (verify not changed) + firewalld: + zone: custom + permanent: True + state: present + register: result + +- name: assert firewalld custom zone created worked (verify not changed) + assert: + that: + - result is not changed + +- name: firewalld remove zone custom + firewalld: + zone: custom + permanent: True + state: absent + register: result + +- name: assert firewalld custom zone removed worked + assert: + that: + - result is changed + +- name: firewalld remove custom zone rerun (verify not changed) + firewalld: + zone: custom + permanent: True + state: absent + register: result + +- name: assert firewalld custom zone removed worked (verify not changed) + assert: + that: + - result is not changed From bbc511dbc811cc684c60eb3d1361b91540938647 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Fri, 20 Jan 2023 11:52:10 -0600 Subject: [PATCH 050/109] v1.5.1 changelog Signed-off-by: Adam Miller --- CHANGELOG.rst | 21 ++++++++++++ changelogs/changelog.yaml | 34 +++++++++++++++++++ .../fragments/166_mount_absent_fstab.yml | 2 -- changelogs/fragments/267_mount_ephemeral.yml | 4 --- .../366_update_version_number_for_galaxy.yml | 3 -- .../371_refactoring_ci_process_202206.yml | 3 -- ...3_firewall_fix_missing_library_message.yml | 3 -- .../fragments/375_update_azp_container.yml | 3 -- .../380_update_usage_profile_tasks.yml | 3 -- .../fragments/386_follow_ci_testing_rules.yml | 3 -- .../fragments/389_ci_add_stable_214.yml | 3 -- .../390_hosts_involved_same_password.yml | 3 -- changelogs/fragments/393-rpm-ostree.yml | 5 --- changelogs/fragments/393_rhel_for_edge.yml | 4 --- .../400-fix-boolean-values-in-docs.yml | 3 -- .../401_document_module_default_values.yml | 4 --- .../fragments/407_fix_firewalld_port_test.yml | 3 -- .../fragments/409_update_azp_matrix.yml | 3 -- 18 files changed, 55 insertions(+), 52 deletions(-) delete mode 100644 changelogs/fragments/166_mount_absent_fstab.yml delete mode 100644 changelogs/fragments/267_mount_ephemeral.yml delete mode 100644 changelogs/fragments/366_update_version_number_for_galaxy.yml delete mode 100644 changelogs/fragments/371_refactoring_ci_process_202206.yml delete mode 100644 changelogs/fragments/373_firewall_fix_missing_library_message.yml delete mode 100644 changelogs/fragments/375_update_azp_container.yml delete mode 100644 changelogs/fragments/380_update_usage_profile_tasks.yml delete mode 100644 changelogs/fragments/386_follow_ci_testing_rules.yml delete mode 100644 changelogs/fragments/389_ci_add_stable_214.yml delete mode 100644 changelogs/fragments/390_hosts_involved_same_password.yml delete mode 100644 changelogs/fragments/393-rpm-ostree.yml delete mode 100644 changelogs/fragments/393_rhel_for_edge.yml delete mode 100644 changelogs/fragments/400-fix-boolean-values-in-docs.yml delete mode 100644 changelogs/fragments/401_document_module_default_values.yml delete mode 100644 changelogs/fragments/407_fix_firewalld_port_test.yml delete mode 100644 changelogs/fragments/409_update_azp_matrix.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9d1d855..45421b2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,27 @@ ansible.posix Release Notes .. contents:: Topics +v1.5.1 +====== + +Minor Changes +------------- + +- mount - Add ``absent_from_fstab`` state (https://github.com/ansible-collections/ansible.posix/pull/166). +- mount - Add ``ephemeral`` value for the ``state`` parameter, that allows to mount a filesystem without altering the ``fstab`` file (https://github.com/ansible-collections/ansible.posix/pull/267). +- r4e_rpm_ostree - new module for validating package state on RHEL for Edge +- rhel_facts - new facts module to handle RHEL specific facts +- rhel_rpm_ostree - new module to handle RHEL rpm-ostree specific package management functionality +- rpm_ostree_upgrade - new module to automate rpm-ostree upgrades +- rpm_ostree_upgrade - new module to manage upgrades for rpm-ostree based systems + +Bugfixes +-------- + +- Removed contentious terminology to match reference documentation in profile_tasks. +- firewall - Fixed to output a more complete missing library message. +- synchronize - Fixed hosts involved in rsync require the same password + v1.4.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 382141c..d313a88 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -260,3 +260,37 @@ releases: - sanity_fixes.yml - shell_escape_full_path_for_rsync.yml release_date: '2022-05-23' + 1.5.1: + changes: + bugfixes: + - Removed contentious terminology to match reference documentation in profile_tasks. + - firewall - Fixed to output a more complete missing library message. + - synchronize - Fixed hosts involved in rsync require the same password + minor_changes: + - mount - Add ``absent_from_fstab`` state (https://github.com/ansible-collections/ansible.posix/pull/166). + - mount - Add ``ephemeral`` value for the ``state`` parameter, that allows to + mount a filesystem without altering the ``fstab`` file (https://github.com/ansible-collections/ansible.posix/pull/267). + - r4e_rpm_ostree - new module for validating package state on RHEL for Edge + - rhel_facts - new facts module to handle RHEL specific facts + - rhel_rpm_ostree - new module to handle RHEL rpm-ostree specific package management + functionality + - rpm_ostree_upgrade - new module to automate rpm-ostree upgrades + - rpm_ostree_upgrade - new module to manage upgrades for rpm-ostree based systems + fragments: + - 166_mount_absent_fstab.yml + - 267_mount_ephemeral.yml + - 366_update_version_number_for_galaxy.yml + - 371_refactoring_ci_process_202206.yml + - 373_firewall_fix_missing_library_message.yml + - 375_update_azp_container.yml + - 380_update_usage_profile_tasks.yml + - 386_follow_ci_testing_rules.yml + - 389_ci_add_stable_214.yml + - 390_hosts_involved_same_password.yml + - 393-rpm-ostree.yml + - 393_rhel_for_edge.yml + - 400-fix-boolean-values-in-docs.yml + - 401_document_module_default_values.yml + - 407_fix_firewalld_port_test.yml + - 409_update_azp_matrix.yml + release_date: '2023-01-20' diff --git a/changelogs/fragments/166_mount_absent_fstab.yml b/changelogs/fragments/166_mount_absent_fstab.yml deleted file mode 100644 index be11324..0000000 --- a/changelogs/fragments/166_mount_absent_fstab.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: - - mount - Add ``absent_from_fstab`` state (https://github.com/ansible-collections/ansible.posix/pull/166). diff --git a/changelogs/fragments/267_mount_ephemeral.yml b/changelogs/fragments/267_mount_ephemeral.yml deleted file mode 100644 index 5671916..0000000 --- a/changelogs/fragments/267_mount_ephemeral.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -minor_changes: -- mount - Add ``ephemeral`` value for the ``state`` parameter, that allows to mount a filesystem - without altering the ``fstab`` file (https://github.com/ansible-collections/ansible.posix/pull/267). diff --git a/changelogs/fragments/366_update_version_number_for_galaxy.yml b/changelogs/fragments/366_update_version_number_for_galaxy.yml deleted file mode 100644 index a905b39..0000000 --- a/changelogs/fragments/366_update_version_number_for_galaxy.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- Update version number in galaxy.yml to 1.5.0. diff --git a/changelogs/fragments/371_refactoring_ci_process_202206.yml b/changelogs/fragments/371_refactoring_ci_process_202206.yml deleted file mode 100644 index 26325d4..0000000 --- a/changelogs/fragments/371_refactoring_ci_process_202206.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI - Refactor AZP to address new test infrastructure (https://github.com/ansible-collections/news-for-maintainers/issues/17). diff --git a/changelogs/fragments/373_firewall_fix_missing_library_message.yml b/changelogs/fragments/373_firewall_fix_missing_library_message.yml deleted file mode 100644 index a5faea8..0000000 --- a/changelogs/fragments/373_firewall_fix_missing_library_message.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - firewall - Fixed to output a more complete missing library message. diff --git a/changelogs/fragments/375_update_azp_container.yml b/changelogs/fragments/375_update_azp_container.yml deleted file mode 100644 index 6d02987..0000000 --- a/changelogs/fragments/375_update_azp_container.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - CI - AZP test container to 3.0.0 (https://github.com/ansible-collections/news-for-maintainers/issues/18). diff --git a/changelogs/fragments/380_update_usage_profile_tasks.yml b/changelogs/fragments/380_update_usage_profile_tasks.yml deleted file mode 100644 index 5b23d40..0000000 --- a/changelogs/fragments/380_update_usage_profile_tasks.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - Removed contentious terminology to match reference documentation in profile_tasks. diff --git a/changelogs/fragments/386_follow_ci_testing_rules.yml b/changelogs/fragments/386_follow_ci_testing_rules.yml deleted file mode 100644 index f59e82a..0000000 --- a/changelogs/fragments/386_follow_ci_testing_rules.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - CI - following the new CI testing rule ansible-test-sanity-docker-devel. diff --git a/changelogs/fragments/389_ci_add_stable_214.yml b/changelogs/fragments/389_ci_add_stable_214.yml deleted file mode 100644 index 6a174fd..0000000 --- a/changelogs/fragments/389_ci_add_stable_214.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- CI - Add stable-2.14 to AZP (https://github.com/ansible-collections/ansible.posix/issues/388). diff --git a/changelogs/fragments/390_hosts_involved_same_password.yml b/changelogs/fragments/390_hosts_involved_same_password.yml deleted file mode 100644 index 1169a31..0000000 --- a/changelogs/fragments/390_hosts_involved_same_password.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - synchronize - Fixed hosts involved in rsync require the same password diff --git a/changelogs/fragments/393-rpm-ostree.yml b/changelogs/fragments/393-rpm-ostree.yml deleted file mode 100644 index e473b39..0000000 --- a/changelogs/fragments/393-rpm-ostree.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -minor_changes: - - rhel_facts - new facts module to handle RHEL specific facts - - rhel_rpm_ostree - new module to handle RHEL rpm-ostree specific package management functionality - - rpm_ostree_upgrade - new module to automate rpm-ostree upgrades diff --git a/changelogs/fragments/393_rhel_for_edge.yml b/changelogs/fragments/393_rhel_for_edge.yml deleted file mode 100644 index 118d377..0000000 --- a/changelogs/fragments/393_rhel_for_edge.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -minor_changes: -- r4e_rpm_ostree - new module for validating package state on RHEL for Edge -- rpm_ostree_upgrade - new module to manage upgrades for rpm-ostree based systems diff --git a/changelogs/fragments/400-fix-boolean-values-in-docs.yml b/changelogs/fragments/400-fix-boolean-values-in-docs.yml deleted file mode 100644 index 8ea04a7..0000000 --- a/changelogs/fragments/400-fix-boolean-values-in-docs.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Change boolean values in documentation to ``true/false`` (https://github.com/ansible-collections/ansible.posix/pull/400). diff --git a/changelogs/fragments/401_document_module_default_values.yml b/changelogs/fragments/401_document_module_default_values.yml deleted file mode 100644 index 8a631dc..0000000 --- a/changelogs/fragments/401_document_module_default_values.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -trivial: -- acl - document default value for the ``entry`` parameter -- rhel_rpm_ostree - document default value for the ``name`` parameter diff --git a/changelogs/fragments/407_fix_firewalld_port_test.yml b/changelogs/fragments/407_fix_firewalld_port_test.yml deleted file mode 100644 index 0b82489..0000000 --- a/changelogs/fragments/407_fix_firewalld_port_test.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: -- Fix firewalld port test cases to avoid port duplicatation. diff --git a/changelogs/fragments/409_update_azp_matrix.yml b/changelogs/fragments/409_update_azp_matrix.yml deleted file mode 100644 index 23d7a86..0000000 --- a/changelogs/fragments/409_update_azp_matrix.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - CI - Update AZP CI matrix (https://github.com/ansible-collections/ansible.posix/issues/408). From 8ccd0b800bf563fa9689fe403c26bdf265072f0f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 30 Jan 2023 22:07:10 +0100 Subject: [PATCH 051/109] Fix broken seealso in synchronize module Module references must always have FQCN. --- plugins/modules/synchronize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 260fac8..40fae71 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -212,7 +212,7 @@ notes: - link_destination is subject to the same limitations as the underlying rsync daemon. Hard links are only preserved if the relative subtrees of the source and destination are the same. Attempts to hardlink into a directory that is a subdirectory of the source will be prevented. seealso: -- module: copy +- module: ansible.builtin.copy - module: community.windows.win_robocopy author: - Timothy Appnel (@tima) From 42af89d019b959a4af4632ee9e74036040e21de2 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 30 Jan 2023 22:30:26 +0100 Subject: [PATCH 052/109] Add changelog fragment --- changelogs/fragments/413-synchronize-seealso.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/413-synchronize-seealso.yml diff --git a/changelogs/fragments/413-synchronize-seealso.yml b/changelogs/fragments/413-synchronize-seealso.yml new file mode 100644 index 0000000..ac680af --- /dev/null +++ b/changelogs/fragments/413-synchronize-seealso.yml @@ -0,0 +1,2 @@ +trivial: + - "synchronize - fix broken ``seealso`` module reference (https://github.com/ansible-collections/ansible.posix/pull/413)." From ee9df947629c1e7f644e403aa0a556d3b679cf93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rob=C3=A9rt=20S=2E=20Guhr?= <20595746+rsguhr@users.noreply.github.com> Date: Tue, 14 Feb 2023 23:20:47 +0100 Subject: [PATCH 053/109] Add support for protocol parameter --- .../fragments/xxx-add-protocol-parameter.yml | 2 + plugins/modules/firewalld.py | 73 ++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/xxx-add-protocol-parameter.yml diff --git a/changelogs/fragments/xxx-add-protocol-parameter.yml b/changelogs/fragments/xxx-add-protocol-parameter.yml new file mode 100644 index 0000000..ad78cea --- /dev/null +++ b/changelogs/fragments/xxx-add-protocol-parameter.yml @@ -0,0 +1,2 @@ +minor_changes: +- firewalld - add `protocol` parameter diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index 52a2a5a..765e575 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -19,6 +19,10 @@ options: - Name of a service to add/remove to/from firewalld. - The service must be listed in output of firewall-cmd --get-services. type: str + protocol: + description: + - Name of a protocol to add/remove to/from firewalld. + type: str port: description: - Name of a port or port range to add/remove to/from firewalld. @@ -144,6 +148,12 @@ EXAMPLES = r''' permanent: true state: enabled +- name: permit ospf traffic + ansible.posix.firewalld: + protocol: ospf + permanent: true + state: enabled + - name: do not permit traffic in default zone on port 8081/tcp ansible.posix.firewalld: port: 8081/tcp @@ -343,6 +353,47 @@ class ServiceTransaction(FirewallTransaction): self.update_fw_settings(fw_zone, fw_settings) +class ProtocolTransaction(FirewallTransaction): + """ + ProtocolTransaction + """ + + def __init__(self, module, action_args=None, zone=None, desired_state=None, permanent=False, immediate=False): + super(ProtocolTransaction, self).__init__( + module, action_args=action_args, desired_state=desired_state, zone=zone, permanent=permanent, immediate=immediate + ) + + def get_enabled_immediate(self, protocol, timeout): + if protocol in self.fw.getProtocols(self.zone): + return True + else: + return False + + def get_enabled_permanent(self, protocol, timeout): + fw_zone, fw_settings = self.get_fw_zone_settings() + + if protocol in fw_settings.getProtocols(): + return True + else: + return False + + def set_enabled_immediate(self, protocol, timeout): + self.fw.addProtocol(self.zone, protocol, timeout) + + def set_enabled_permanent(self, protocol, timeout): + fw_zone, fw_settings = self.get_fw_zone_settings() + fw_settings.addProtocol(protocol) + self.update_fw_settings(fw_zone, fw_settings) + + def set_disabled_immediate(self, protocol, timeout): + self.fw.removeProtocol(self.zone, protocol) + + def set_disabled_permanent(self, protocol, timeout): + fw_zone, fw_settings = self.get_fw_zone_settings() + fw_settings.removeProtocol(protocol) + self.update_fw_settings(fw_zone, fw_settings) + + class MasqueradeTransaction(FirewallTransaction): """ MasqueradeTransaction @@ -748,6 +799,7 @@ def main(): icmp_block=dict(type='str'), icmp_block_inversion=dict(type='str'), service=dict(type='str'), + protocol=dict(type='str'), port=dict(type='str'), port_forward=dict(type='list', elements='dict'), rich_rule=dict(type='str'), @@ -769,7 +821,7 @@ def main(): source=('permanent',), ), mutually_exclusive=[ - ['icmp_block', 'icmp_block_inversion', 'service', 'port', 'port_forward', 'rich_rule', + ['icmp_block', 'icmp_block_inversion', 'service', 'protocol' 'port', 'port_forward', 'rich_rule', 'interface', 'masquerade', 'source', 'target'] ], ) @@ -798,6 +850,7 @@ def main(): icmp_block = module.params['icmp_block'] icmp_block_inversion = module.params['icmp_block_inversion'] service = module.params['service'] + protocol = module.params['protocol'] rich_rule = module.params['rich_rule'] source = module.params['source'] zone = module.params['zone'] @@ -829,7 +882,7 @@ def main(): port_forward_toaddr = port_forward['toaddr'] modification = False - if any([icmp_block, icmp_block_inversion, service, port, port_forward, rich_rule, + if any([icmp_block, icmp_block_inversion, service, protocol, port, port_forward, rich_rule, interface, masquerade, source, target]): modification = True if modification and desired_state in ['absent', 'present'] and target is None: @@ -893,6 +946,22 @@ def main(): if changed is True: msgs.append("Changed service %s to %s" % (service, desired_state)) + if protocol is not None: + + transaction = ProtocolTransaction( + module, + action_args=(protocol, timeout), + zone=zone, + desired_state=desired_state, + permanent=permanent, + immediate=immediate, + ) + + changed, transaction_msgs = transaction.run() + msgs = msgs + transaction_msgs + if changed is True: + msgs.append("Changed protocol %s to %s" % (protocol, desired_state)) + if source is not None: transaction = SourceTransaction( From a9920ae1898f134d4f6fb4187e086a155c0abcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rob=C3=A9rt=20S=2E=20Guhr?= <20595746+rsguhr@users.noreply.github.com> Date: Tue, 14 Feb 2023 23:26:44 +0100 Subject: [PATCH 054/109] Changed changelog file name --- ...-add-protocol-parameter.yml => 417-add-protocol-parameter.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelogs/fragments/{xxx-add-protocol-parameter.yml => 417-add-protocol-parameter.yml} (100%) diff --git a/changelogs/fragments/xxx-add-protocol-parameter.yml b/changelogs/fragments/417-add-protocol-parameter.yml similarity index 100% rename from changelogs/fragments/xxx-add-protocol-parameter.yml rename to changelogs/fragments/417-add-protocol-parameter.yml From b2f053a856dc4dddddad45a1d16e320726593c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rob=C3=A9rt=20S=2E=20Guhr?= <20595746+rsguhr@users.noreply.github.com> Date: Tue, 14 Feb 2023 23:39:17 +0100 Subject: [PATCH 055/109] Adjust assert for firewalld source test permanent --- tests/integration/targets/firewalld/tasks/source_test_cases.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/firewalld/tasks/source_test_cases.yml b/tests/integration/targets/firewalld/tasks/source_test_cases.yml index 172a47e..4bc8b65 100644 --- a/tests/integration/targets/firewalld/tasks/source_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/source_test_cases.yml @@ -82,4 +82,4 @@ assert: that: - result is not changed - - "result.msg == 'parameters are mutually exclusive: icmp_block|icmp_block_inversion|service|port|port_forward|rich_rule|interface|masquerade|source|target'" + - "result.msg == 'parameters are mutually exclusive: icmp_block|icmp_block_inversion|service|protocol|port|port_forward|rich_rule|interface|masquerade|source|target'" From 2ac6fbb84bcf85333786ae1c389c227a17174b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rob=C3=A9rt=20S=2E=20Guhr?= <20595746+rsguhr@users.noreply.github.com> Date: Wed, 15 Feb 2023 00:26:57 +0100 Subject: [PATCH 056/109] added forgotten comma --- plugins/modules/firewalld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index 765e575..79c1440 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -821,7 +821,7 @@ def main(): source=('permanent',), ), mutually_exclusive=[ - ['icmp_block', 'icmp_block_inversion', 'service', 'protocol' 'port', 'port_forward', 'rich_rule', + ['icmp_block', 'icmp_block_inversion', 'service', 'protocol', 'port', 'port_forward', 'rich_rule', 'interface', 'masquerade', 'source', 'target'] ], ) From 0d2ff1d2d8bc62c428507330f50449054e2f204b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rob=C3=A9rt=20S=2E=20Guhr?= <20595746+rsguhr@users.noreply.github.com> Date: Wed, 15 Feb 2023 00:41:57 +0100 Subject: [PATCH 057/109] added integrations tests for protocol parameter --- .../firewalld/tasks/protocol_test_cases.yml | 65 +++++++++++++++++++ .../targets/firewalld/tasks/run_all_tests.yml | 3 + 2 files changed, 68 insertions(+) create mode 100644 tests/integration/targets/firewalld/tasks/protocol_test_cases.yml diff --git a/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml b/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml new file mode 100644 index 0000000..2af8921 --- /dev/null +++ b/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml @@ -0,0 +1,65 @@ +# Test playbook for the firewalld module - protocol operations +# (c) 2022, Robért S. Guhr + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- name: firewalld protocol test permanent enabled + firewalld: + protocol: ospf + permanent: true + state: enabled + register: result + +- name: assert firewalld protocol test permanent enabled worked + assert: + that: + - result is changed + +- name: firewalld protocol test permanent enabled rerun (verify not changed) + firewalld: + protocol: ospf + permanent: true + state: enabled + register: result + +- name: assert firewalld protocol test permanent enabled rerun worked (verify not changed) + assert: + that: + - result is not changed + +- name: firewalld protocol test permanent disabled + firewalld: + protocol: ospf + permanent: true + state: disabled + register: result + +- name: assert firewalld protocol test permanent disabled worked + assert: + that: + - result is changed + +- name: firewalld protocol test permanent disabled rerun (verify not changed) + firewalld: + protocol: ospf + permanent: true + state: disabled + register: result + +- name: assert firewalld protocol test permanent disabled rerun worked (verify not changed) + assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index 5027c1c..ff25847 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -10,6 +10,9 @@ # firewalld service operation test cases - include_tasks: service_test_cases.yml +# firewalld protocol operation test cases +- include_tasks: protocol_test_cases.yml + # firewalld port operation test cases - include_tasks: port_test_cases.yml From fd32da0e99b2e84c284e307cac6c90e2f7ac8f8d Mon Sep 17 00:00:00 2001 From: Akira Yokochi Date: Tue, 21 Feb 2023 12:06:22 +0000 Subject: [PATCH 058/109] fix document syntax --- plugins/modules/patch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/patch.py b/plugins/modules/patch.py index 0c6fe47..ecedbf6 100644 --- a/plugins/modules/patch.py +++ b/plugins/modules/patch.py @@ -37,7 +37,7 @@ options: src: description: - Path of the patch file as accepted by the GNU patch tool. If - C(remote_src) is 'no', the patch source file is looked up from the + C(remote_src) is C(false), the patch source file is looked up from the module's I(files) directory. type: path required: true From d64db13643f0ffee2a5012049922a955ab3bae26 Mon Sep 17 00:00:00 2001 From: Akira Yokochi Date: Tue, 21 Feb 2023 12:08:02 +0000 Subject: [PATCH 059/109] collection_prep for patch module --- docs/ansible.posix.patch_module.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/ansible.posix.patch_module.rst b/docs/ansible.posix.patch_module.rst index 60c30cf..07f672a 100644 --- a/docs/ansible.posix.patch_module.rst +++ b/docs/ansible.posix.patch_module.rst @@ -84,9 +84,9 @@ Parameters -
Setting to yes will disable patch's heuristic for transforming CRLF line endings into LF.
+
Setting to true will disable patch's heuristic for transforming CRLF line endings into LF.
Line endings of src and dest must match.
-
If set to no, patch will replace CRLF in src files on POSIX.
+
If set to false, patch will replace CRLF in src files on POSIX.
@@ -122,7 +122,7 @@ Parameters -
Setting to yes will ignore white space changes between patch and input..
+
Setting to true will ignore white space changes between patch and input.
@@ -141,7 +141,7 @@ Parameters -
If no, it will search for src at originating/controller machine, if yes it will go to the remote/target machine for the src.
+
If false, it will search for src at originating/controller machine, if true it will go to the remote/target machine for the src.
@@ -157,7 +157,7 @@ Parameters -
Path of the patch file as accepted by the GNU patch tool. If remote_src is 'no', the patch source file is looked up from the module's files directory.
+
Path of the patch file as accepted by the GNU patch tool. If remote_src is false, the patch source file is looked up from the module's files directory.

aliases: patchfile
From 14accca52f5ebc7dbd8d037e51385752db122b48 Mon Sep 17 00:00:00 2001 From: Akira Yokochi Date: Tue, 21 Feb 2023 12:46:54 +0000 Subject: [PATCH 060/109] add changelog fragment --- changelogs/fragments/419-fix-patch-doc.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/419-fix-patch-doc.yml diff --git a/changelogs/fragments/419-fix-patch-doc.yml b/changelogs/fragments/419-fix-patch-doc.yml new file mode 100644 index 0000000..7a39a27 --- /dev/null +++ b/changelogs/fragments/419-fix-patch-doc.yml @@ -0,0 +1,2 @@ +trivial: + - patch - fix format syntax and boolean values on document (https://github.com/ansible-collections/ansible.posix/pull/419). From 94523978d227838ce2e5a17ac6f5119f0678680f Mon Sep 17 00:00:00 2001 From: austlane Date: Wed, 22 Feb 2023 20:07:25 -0500 Subject: [PATCH 061/109] bindep - install rsync on all EL variants Adds support for installing rsync for centos and related EL variants (AlmaLinux, Rocky, Oracle, etc) rsync is an extremely common package, available in the base repos of all EL distros This is necessary to properly support AWX-EE and other community-built EL Execution Environments. --- bindep.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindep.txt b/bindep.txt index fc5997d..f589f51 100644 --- a/bindep.txt +++ b/bindep.txt @@ -1,4 +1,4 @@ # This is a cross-platform list tracking distribution packages needed by tests; # see https://docs.openstack.org/infra/bindep/ for additional information. -rsync [platform:rhel-8 platform:rhel-9] +rsync [platform:redhat] From 5eb019b2c1f38bec7940e29d302cd3eb70605b1a Mon Sep 17 00:00:00 2001 From: Akira Yokochi Date: Sun, 26 Feb 2023 02:47:41 +0000 Subject: [PATCH 062/109] Revert "collection_prep for patch module" This reverts commit d64db13643f0ffee2a5012049922a955ab3bae26. --- docs/ansible.posix.patch_module.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/ansible.posix.patch_module.rst b/docs/ansible.posix.patch_module.rst index 07f672a..60c30cf 100644 --- a/docs/ansible.posix.patch_module.rst +++ b/docs/ansible.posix.patch_module.rst @@ -84,9 +84,9 @@ Parameters -
Setting to true will disable patch's heuristic for transforming CRLF line endings into LF.
+
Setting to yes will disable patch's heuristic for transforming CRLF line endings into LF.
Line endings of src and dest must match.
-
If set to false, patch will replace CRLF in src files on POSIX.
+
If set to no, patch will replace CRLF in src files on POSIX.
@@ -122,7 +122,7 @@ Parameters -
Setting to true will ignore white space changes between patch and input.
+
Setting to yes will ignore white space changes between patch and input..
@@ -141,7 +141,7 @@ Parameters -
If false, it will search for src at originating/controller machine, if true it will go to the remote/target machine for the src.
+
If no, it will search for src at originating/controller machine, if yes it will go to the remote/target machine for the src.
@@ -157,7 +157,7 @@ Parameters -
Path of the patch file as accepted by the GNU patch tool. If remote_src is false, the patch source file is looked up from the module's files directory.
+
Path of the patch file as accepted by the GNU patch tool. If remote_src is 'no', the patch source file is looked up from the module's files directory.

aliases: patchfile
From 553b49245f6e78743717258b1fbaa29c15c942c9 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 13 Mar 2023 17:13:26 +0900 Subject: [PATCH 063/109] Support new test-sanity-docker-devel test * Remove unused module import Signed-off-by: Hideki Saito --- changelogs/fragments/425-support_test-sanity-docker-devel.yml | 2 ++ plugins/module_utils/version.py | 2 ++ plugins/modules/firewalld_info.py | 1 - tests/unit/compat/builtins.py | 1 + tests/unit/plugins/action/test_synchronize.py | 1 - 5 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/425-support_test-sanity-docker-devel.yml diff --git a/changelogs/fragments/425-support_test-sanity-docker-devel.yml b/changelogs/fragments/425-support_test-sanity-docker-devel.yml new file mode 100644 index 0000000..e66622c --- /dev/null +++ b/changelogs/fragments/425-support_test-sanity-docker-devel.yml @@ -0,0 +1,2 @@ +trivial: + - ansible.posix - removed unused module import from the code. diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py index 26d8c30..c6a5f68 100644 --- a/plugins/module_utils/version.py +++ b/plugins/module_utils/version.py @@ -16,3 +16,5 @@ __metaclass__ = type # from ansible.module_utils.compat.version import LooseVersion from ._version import LooseVersion, StrictVersion + +__all__ = ['LooseVersion', 'StrictVersion'] diff --git a/plugins/modules/firewalld_info.py b/plugins/modules/firewalld_info.py index 29257bc..024dd39 100644 --- a/plugins/modules/firewalld_info.py +++ b/plugins/modules/firewalld_info.py @@ -204,7 +204,6 @@ firewalld_info: ''' from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.six import raise_from from ansible.module_utils._text import to_native from ansible_collections.ansible.posix.plugins.module_utils.version import StrictVersion diff --git a/tests/unit/compat/builtins.py b/tests/unit/compat/builtins.py index f60ee67..f8e6c3d 100644 --- a/tests/unit/compat/builtins.py +++ b/tests/unit/compat/builtins.py @@ -31,3 +31,4 @@ except ImportError: BUILTINS = 'builtins' else: BUILTINS = '__builtin__' + __all__ = ['__builtin__'] diff --git a/tests/unit/plugins/action/test_synchronize.py b/tests/unit/plugins/action/test_synchronize.py index 40e489d..1c4a241 100644 --- a/tests/unit/plugins/action/test_synchronize.py +++ b/tests/unit/plugins/action/test_synchronize.py @@ -19,7 +19,6 @@ import os import unittest import yaml -import ansible.plugins from ansible_collections.ansible.posix.tests.unit.compat.mock import patch, MagicMock from ansible_collections.ansible.posix.plugins.action.synchronize import ActionModule From 01f19cde258cf316dac75a275c9a4d8070c5fb75 Mon Sep 17 00:00:00 2001 From: exploide Date: Tue, 14 Mar 2023 18:53:36 +0100 Subject: [PATCH 064/109] firewalld_info: fixed typo in default_zone and improved examples --- changelogs/fragments/426-firewalld_info-doc-update.yml | 4 ++++ plugins/modules/firewalld_info.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/426-firewalld_info-doc-update.yml diff --git a/changelogs/fragments/426-firewalld_info-doc-update.yml b/changelogs/fragments/426-firewalld_info-doc-update.yml new file mode 100644 index 0000000..71037f5 --- /dev/null +++ b/changelogs/fragments/426-firewalld_info-doc-update.yml @@ -0,0 +1,4 @@ +--- + +trivial: + - firewalld_info - fixed typo in return value and improved examples in documentation diff --git a/plugins/modules/firewalld_info.py b/plugins/modules/firewalld_info.py index 024dd39..334518d 100644 --- a/plugins/modules/firewalld_info.py +++ b/plugins/modules/firewalld_info.py @@ -37,6 +37,11 @@ EXAMPLES = r''' - name: Gather information about active zones ansible.posix.firewalld_info: active_zones: true + register: result + +- name: Print default zone for debugging + ansible.builtin.debug: + var: result.firewalld_info.default_zone - name: Gather information about specific zones ansible.posix.firewalld_info: @@ -44,6 +49,7 @@ EXAMPLES = r''' - public - external - internal + register: result ''' RETURN = r''' @@ -78,7 +84,7 @@ firewalld_info: returned: success type: str sample: 0.8.2 - default_zones: + default_zone: description: - The zone name of default zone. returned: success From a62acdfc5ad1564e9f4dbf79dd7ffb3158ce2983 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Tue, 21 Mar 2023 17:56:23 +0900 Subject: [PATCH 065/109] Added macOS 13.2 and remove macOS 12.0 - This commit fixes issue #431 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 9fb818b..e403638 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -205,8 +205,8 @@ stages: parameters: testFormat: devel/{0}/1 targets: - - name: MacOS 12.0 - test: macos/12.0 + - name: MacOS 13.2 + test: macos/13.2 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.7 From 583e4a6d6b4643f81bc4e86c9a468d7340039d1f Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Thu, 23 Mar 2023 15:52:16 -0600 Subject: [PATCH 066/109] rhel_facts module must use keyword arguments The rhel_facts module must use keyword arguments. The current code gives this error: ``` Traceback (most recent call last): ... File "/tmp/ansible_ansible.posix.rhel_facts_payload_y10oy_4m/.../rhel_facts.py", line 72, in main TypeError: exit_json() takes 1 positional argument but 2 were given ``` The fix is to use all keyword arguments like other facts plugins. --- plugins/modules/rhel_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/rhel_facts.py b/plugins/modules/rhel_facts.py index 57c15f7..a30622a 100644 --- a/plugins/modules/rhel_facts.py +++ b/plugins/modules/rhel_facts.py @@ -69,7 +69,7 @@ def main(): if os.path.exists("/run/ostree-booted"): ansible_facts['pkg_mgr'] = 'ansible.posix.rhel_rpm_ostree' - module.exit_json(ansible_facts, changed=False) + module.exit_json(ansible_facts=ansible_facts, changed=False) if __name__ == '__main__': From 0e92d30fd3904ab89a90a24c69636fa56e01006e Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Thu, 23 Mar 2023 17:31:31 -0600 Subject: [PATCH 067/109] add changelog fragment --- changelogs/fragments/434-fix-rhel_facts-exit_json.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/434-fix-rhel_facts-exit_json.yml diff --git a/changelogs/fragments/434-fix-rhel_facts-exit_json.yml b/changelogs/fragments/434-fix-rhel_facts-exit_json.yml new file mode 100644 index 0000000..dcf16d9 --- /dev/null +++ b/changelogs/fragments/434-fix-rhel_facts-exit_json.yml @@ -0,0 +1,2 @@ +bugfixes: + - rhel_facts - Call exit_json with all keyword arguments From 009ed3bed53c1e3d0a675d70b3e7fbdbbf71abb1 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Fri, 24 Mar 2023 11:46:44 +0100 Subject: [PATCH 068/109] docs: fix profile_tasks callback documentation Fixes: #412 Signed-off-by: Daniel Ziegenberg --- plugins/callback/profile_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/callback/profile_tasks.py b/plugins/callback/profile_tasks.py index b7fc3ac..944b222 100644 --- a/plugins/callback/profile_tasks.py +++ b/plugins/callback/profile_tasks.py @@ -17,7 +17,7 @@ DOCUMENTATION = ''' - Ansible callback plugin for timing individual tasks and overall execution time. - "Mashup of 2 excellent original works: https://github.com/jlafon/ansible-profile, https://github.com/junaid18183/ansible_home/blob/master/ansible_plugins/callback_plugins/timestamp.py.old" - - "Format: C( () )" + - "Format: C() C() C()" - It also lists the top/bottom time consuming tasks in the summary (configurable) - Before 2.4 only the environment variables were available for configuration. requirements: From a417ac80f07a8d5536e918ab6d2425d65658c4cc Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Wed, 29 Mar 2023 09:57:29 +0300 Subject: [PATCH 069/109] Add jsonl callback plugin to ansible.posix collection --- .../fragments/535-add-jsonl-callback.yml | 2 + plugins/callback/jsonl.py | 196 ++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 changelogs/fragments/535-add-jsonl-callback.yml create mode 100644 plugins/callback/jsonl.py diff --git a/changelogs/fragments/535-add-jsonl-callback.yml b/changelogs/fragments/535-add-jsonl-callback.yml new file mode 100644 index 0000000..64eb192 --- /dev/null +++ b/changelogs/fragments/535-add-jsonl-callback.yml @@ -0,0 +1,2 @@ +minor_changes: +- Add jsonl callback plugin to ansible.posix collection diff --git a/plugins/callback/jsonl.py b/plugins/callback/jsonl.py new file mode 100644 index 0000000..2403dba --- /dev/null +++ b/plugins/callback/jsonl.py @@ -0,0 +1,196 @@ +# (c) 2016, Matt Martz +# (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: jsonl + short_description: Ansible screen output as JSONL (lines in json format) + description: + - This callback converts all events into JSON output to stdout + - This callback in contrast with ansible.posix.json uses less memory, because it doesn't store results. + type: stdout + requirements: + - Set as stdout in config + options: + show_custom_stats: + name: Show custom stats + description: 'This adds the custom stats set via the set_stats plugin to the play recap' + default: False + env: + - name: ANSIBLE_SHOW_CUSTOM_STATS + ini: + - key: show_custom_stats + section: defaults + type: bool + notes: + - When using a strategy such as free, host_pinned, or a custom strategy, host results will + be added to new task results in ``.plays[].tasks[]``. As such, there will exist duplicate + task objects indicated by duplicate task IDs at ``.plays[].tasks[].task.id``, each with an + individual host result for the task. +''' + +import datetime +import json +import copy + +from functools import partial + +from ansible.inventory.host import Host +from ansible.module_utils._text import to_text +from ansible.parsing.ajson import AnsibleJSONEncoder +from ansible.plugins.callback import CallbackBase + + +LOCKSTEP_CALLBACKS = frozenset(('linear', 'debug')) + + +def current_time(): + return '%sZ' % datetime.datetime.utcnow().isoformat() + + +class CallbackModule(CallbackBase): + CALLBACK_VERSION = 2.0 + CALLBACK_TYPE = 'stdout' + CALLBACK_NAME = 'ansible.posix.jsonl' + + def __init__(self, display=None): + super(CallbackModule, self).__init__(display) + self.results = [] + self._task_map = {} + self._is_lockstep = False + + def _new_play(self, play): + self._is_lockstep = play.strategy in LOCKSTEP_CALLBACKS + return { + 'play': { + 'name': play.get_name(), + 'id': to_text(play._uuid), + 'duration': { + 'start': current_time() + } + }, + 'tasks': [] + } + + def _new_task(self, task): + return { + 'task': { + 'name': task.get_name(), + 'id': to_text(task._uuid), + 'duration': { + 'start': current_time() + } + }, + 'hosts': {} + } + + def _find_result_task(self, host, task): + key = (host.get_name(), task._uuid) + return self._task_map.get( + key, + self.results[-1]['tasks'][-1] + ) + + def v2_playbook_on_play_start(self, play): + play_result = self._new_play(play) + self.results.append(play_result) + self._write_event('v2_playbook_on_play_start', play_result) + + def v2_runner_on_start(self, host, task): + if self._is_lockstep: + return + key = (host.get_name(), task._uuid) + task_result = self._new_task(task) + self._task_map[key] = task_result + self.results[-1]['tasks'].append(task_result) + self._write_event('v2_runner_on_start', task_result) + + def v2_playbook_on_task_start(self, task, is_conditional): + if not self._is_lockstep: + return + task_result = self._new_task(task) + self.results[-1]['tasks'].append(task_result) + self._write_event('v2_playbook_on_task_start', task_result) + + def v2_playbook_on_handler_task_start(self, task): + if not self._is_lockstep: + return + task_result = self._new_task(task) + self.results[-1]['tasks'].append(task_result) + self._write_event('v2_playbook_on_handler_task_start', task_result) + + def _convert_host_to_name(self, key): + if isinstance(key, (Host,)): + return key.get_name() + return key + + def v2_playbook_on_stats(self, stats): + """Display info about playbook statistics""" + + hosts = sorted(stats.processed.keys()) + + summary = {} + for h in hosts: + s = stats.summarize(h) + summary[h] = s + + custom_stats = {} + global_custom_stats = {} + + if self.get_option('show_custom_stats') and stats.custom: + custom_stats.update(dict((self._convert_host_to_name(k), v) for k, v in stats.custom.items())) + global_custom_stats.update(custom_stats.pop('_run', {})) + + output = { + 'stats': summary, + 'custom_stats': custom_stats, + 'global_custom_stats': global_custom_stats, + } + + self._write_event('v2_playbook_on_stats', output) + + def _write_event(self, event_name, output): + output['_event'] = event_name + output['_timestamp'] = current_time() + self._display.display(json.dumps(output, cls=AnsibleJSONEncoder, separators=',:', sort_keys=True)) + + def _record_task_result(self, event_name, on_info, result, **kwargs): + """This function is used as a partial to add failed/skipped info in a single method""" + host = result._host + task = result._task + + result_copy = result._result.copy() + result_copy.update(on_info) + result_copy['action'] = task.action + + task_result = self._find_result_task(host, task) + + end_time = current_time() + task_result['task']['duration']['end'] = end_time + self.results[-1]['play']['duration']['end'] = end_time + + task_result_copy = copy.deepcopy(task_result) + task_result_copy['hosts'][host.name] = result_copy + + if not self._is_lockstep: + key = (host.get_name(), task._uuid) + del self._task_map[key] + + self._write_event(event_name, task_result_copy) + + def __getattribute__(self, name): + """Return ``_record_task_result`` partial with a dict containing skipped/failed if necessary""" + if name not in ('v2_runner_on_ok', 'v2_runner_on_failed', 'v2_runner_on_unreachable', 'v2_runner_on_skipped'): + return object.__getattribute__(self, name) + + on = name.rsplit('_', 1)[1] + + on_info = {} + if on in ('failed', 'skipped'): + on_info[on] = True + + return partial(self._record_task_result, name, on_info) From 26c182c8ef6b1c41b2dacd32789b8439533ba004 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Fri, 7 Apr 2023 13:57:13 +0900 Subject: [PATCH 070/109] Release 1.5.2 commit Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 14 -- CHANGELOG.rst | 23 +++ README.md | 3 + changelogs/changelog.yaml | 27 +++ ...ewalld_create_remove_zone_when_offline.yml | 3 - .../fragments/413-synchronize-seealso.yml | 2 - .../fragments/417-add-protocol-parameter.yml | 2 - changelogs/fragments/419-fix-patch-doc.yml | 2 - .../425-support_test-sanity-docker-devel.yml | 2 - .../426-firewalld_info-doc-update.yml | 4 - .../434-fix-rhel_facts-exit_json.yml | 2 - .../fragments/535-add-jsonl-callback.yml | 2 - docs/ansible.posix.acl_module.rst | 7 +- docs/ansible.posix.at_module.rst | 2 +- docs/ansible.posix.authorized_key_module.rst | 18 +- docs/ansible.posix.firewalld_info_module.rst | 10 +- docs/ansible.posix.firewalld_module.rst | 53 ++++-- docs/ansible.posix.mount_module.rst | 26 ++- docs/ansible.posix.patch_module.rst | 10 +- docs/ansible.posix.rhel_facts_module.rst | 103 +++++++++++ docs/ansible.posix.rhel_rpm_ostree_module.rst | 156 ++++++++++++++++ ...nsible.posix.rpm_ostree_upgrade_module.rst | 175 ++++++++++++++++++ docs/ansible.posix.seboolean_module.rst | 6 +- docs/ansible.posix.synchronize_module.rst | 28 +-- docs/ansible.posix.sysctl_module.rst | 12 +- galaxy.yml | 2 +- 26 files changed, 595 insertions(+), 99 deletions(-) delete mode 100644 changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml delete mode 100644 changelogs/fragments/413-synchronize-seealso.yml delete mode 100644 changelogs/fragments/417-add-protocol-parameter.yml delete mode 100644 changelogs/fragments/419-fix-patch-doc.yml delete mode 100644 changelogs/fragments/425-support_test-sanity-docker-devel.yml delete mode 100644 changelogs/fragments/426-firewalld_info-doc-update.yml delete mode 100644 changelogs/fragments/434-fix-rhel_facts-exit_json.yml delete mode 100644 changelogs/fragments/535-add-jsonl-callback.yml create mode 100644 docs/ansible.posix.rhel_facts_module.rst create mode 100644 docs/ansible.posix.rhel_rpm_ostree_module.rst create mode 100644 docs/ansible.posix.rpm_ostree_upgrade_module.rst diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index e403638..728ef40 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -135,18 +135,12 @@ stages: test: centos6 - name: CentOS 7 test: centos7 - - name: Fedora 32 - test: fedora32 - - name: Fedora 33 - test: fedora33 - name: openSUSE 15 py2 test: opensuse15py2 - name: openSUSE 15 py3 test: opensuse15 - name: Ubuntu 18.04 test: ubuntu1804 - - name: Ubuntu 20.04 - test: ubuntu2004 - stage: Docker_2_10 displayName: Docker 2.10 dependsOn: [] @@ -159,10 +153,6 @@ stages: test: centos6 - name: CentOS 7 test: centos7 - - name: Fedora 30 - test: fedora30 - - name: Fedora 31 - test: fedora31 - name: openSUSE 15 py2 test: opensuse15py2 - name: openSUSE 15 py3 @@ -183,10 +173,6 @@ stages: test: centos6 - name: CentOS 7 test: centos7 - - name: Fedora 30 - test: fedora30 - - name: Fedora 31 - test: fedora31 - name: openSUSE 15 py2 test: opensuse15py2 - name: openSUSE 15 py3 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 45421b2..06cdf22 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,29 @@ ansible.posix Release Notes .. contents:: Topics +v1.5.2 +====== + +Release Summary +--------------- + +This is the minor release of the ``ansible.posix`` collection. +This changelog contains all changes to the modules and plugins +in this collection that have been added after the release of +``ansible.posix`` 1.5.1. + +Minor Changes +------------- + +- Add jsonl callback plugin to ansible.posix collection +- firewalld - add `protocol` parameter + +Bugfixes +-------- + +- Fixed a bug where firewalld module fails to create/remove zones when the daemon is stopped +- rhel_facts - Call exit_json with all keyword arguments + v1.5.1 ====== diff --git a/README.md b/README.md index c0ee2b4..b0cd705 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ Name | Description [ansible.posix.firewalld_info](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.firewalld_info_module.rst)|Gather information about firewalld [ansible.posix.mount](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.mount_module.rst)|Control active and configured mount points [ansible.posix.patch](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.patch_module.rst)|Apply patch files using the GNU patch tool +[ansible.posix.rhel_facts](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.rhel_facts_module.rst)|Facts module to set or override RHEL specific facts. +[ansible.posix.rhel_rpm_ostree](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.rhel_rpm_ostree_module.rst)|Ensure packages exist in a RHEL for Edge rpm-ostree based system +[ansible.posix.rpm_ostree_upgrade](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.rpm_ostree_upgrade_module.rst)|Manage rpm-ostree upgrade transactions [ansible.posix.seboolean](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.seboolean_module.rst)|Toggles SELinux booleans [ansible.posix.selinux](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.selinux_module.rst)|Change policy and state of SELinux [ansible.posix.synchronize](https://github.com/ansible-collections/ansible.posix/blob/main/docs/ansible.posix.synchronize_module.rst)|A wrapper around rsync to make common tasks in your playbooks quick and easy diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index d313a88..0b59c25 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -294,3 +294,30 @@ releases: - 407_fix_firewalld_port_test.yml - 409_update_azp_matrix.yml release_date: '2023-01-20' + 1.5.2: + changes: + bugfixes: + - Fixed a bug where firewalld module fails to create/remove zones when the daemon + is stopped + - rhel_facts - Call exit_json with all keyword arguments + minor_changes: + - Add jsonl callback plugin to ansible.posix collection + - firewalld - add `protocol` parameter + release_summary: 'This is the minor release of the ``ansible.posix`` collection. + + This changelog contains all changes to the modules and plugins + + in this collection that have been added after the release of + + ``ansible.posix`` 1.5.1.' + fragments: + - 1.5.2.yml + - 399_firewalld_create_remove_zone_when_offline.yml + - 413-synchronize-seealso.yml + - 417-add-protocol-parameter.yml + - 419-fix-patch-doc.yml + - 425-support_test-sanity-docker-devel.yml + - 426-firewalld_info-doc-update.yml + - 434-fix-rhel_facts-exit_json.yml + - 535-add-jsonl-callback.yml + release_date: '2023-04-07' diff --git a/changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml b/changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml deleted file mode 100644 index 691fc65..0000000 --- a/changelogs/fragments/399_firewalld_create_remove_zone_when_offline.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - Fixed a bug where firewalld module fails to create/remove zones when the daemon is stopped diff --git a/changelogs/fragments/413-synchronize-seealso.yml b/changelogs/fragments/413-synchronize-seealso.yml deleted file mode 100644 index ac680af..0000000 --- a/changelogs/fragments/413-synchronize-seealso.yml +++ /dev/null @@ -1,2 +0,0 @@ -trivial: - - "synchronize - fix broken ``seealso`` module reference (https://github.com/ansible-collections/ansible.posix/pull/413)." diff --git a/changelogs/fragments/417-add-protocol-parameter.yml b/changelogs/fragments/417-add-protocol-parameter.yml deleted file mode 100644 index ad78cea..0000000 --- a/changelogs/fragments/417-add-protocol-parameter.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: -- firewalld - add `protocol` parameter diff --git a/changelogs/fragments/419-fix-patch-doc.yml b/changelogs/fragments/419-fix-patch-doc.yml deleted file mode 100644 index 7a39a27..0000000 --- a/changelogs/fragments/419-fix-patch-doc.yml +++ /dev/null @@ -1,2 +0,0 @@ -trivial: - - patch - fix format syntax and boolean values on document (https://github.com/ansible-collections/ansible.posix/pull/419). diff --git a/changelogs/fragments/425-support_test-sanity-docker-devel.yml b/changelogs/fragments/425-support_test-sanity-docker-devel.yml deleted file mode 100644 index e66622c..0000000 --- a/changelogs/fragments/425-support_test-sanity-docker-devel.yml +++ /dev/null @@ -1,2 +0,0 @@ -trivial: - - ansible.posix - removed unused module import from the code. diff --git a/changelogs/fragments/426-firewalld_info-doc-update.yml b/changelogs/fragments/426-firewalld_info-doc-update.yml deleted file mode 100644 index 71037f5..0000000 --- a/changelogs/fragments/426-firewalld_info-doc-update.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -trivial: - - firewalld_info - fixed typo in return value and improved examples in documentation diff --git a/changelogs/fragments/434-fix-rhel_facts-exit_json.yml b/changelogs/fragments/434-fix-rhel_facts-exit_json.yml deleted file mode 100644 index dcf16d9..0000000 --- a/changelogs/fragments/434-fix-rhel_facts-exit_json.yml +++ /dev/null @@ -1,2 +0,0 @@ -bugfixes: - - rhel_facts - Call exit_json with all keyword arguments diff --git a/changelogs/fragments/535-add-jsonl-callback.yml b/changelogs/fragments/535-add-jsonl-callback.yml deleted file mode 100644 index 64eb192..0000000 --- a/changelogs/fragments/535-add-jsonl-callback.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: -- Add jsonl callback plugin to ansible.posix collection diff --git a/docs/ansible.posix.acl_module.rst b/docs/ansible.posix.acl_module.rst index aab5a37..6a13d89 100644 --- a/docs/ansible.posix.acl_module.rst +++ b/docs/ansible.posix.acl_module.rst @@ -49,8 +49,8 @@ Parameters -
If the target is a directory, setting this to yes will make it the default ACL for entities created inside the directory.
-
Setting default to yes causes an error if the path is a file.
+
If the target is a directory, setting this to true will make it the default ACL for entities created inside the directory.
+
Setting default to true causes an error if the path is a file.
@@ -63,6 +63,7 @@ Parameters + Default:
""
The actual user or group that the ACL applies to when matching entity types user or group are selected.
@@ -285,7 +286,7 @@ Examples entity: joe etype: user permissions: rw - default: yes + default: true state: present - name: Same as previous but using entry shorthand diff --git a/docs/ansible.posix.at_module.rst b/docs/ansible.posix.at_module.rst index d9f3cc8..3d731a2 100644 --- a/docs/ansible.posix.at_module.rst +++ b/docs/ansible.posix.at_module.rst @@ -171,7 +171,7 @@ Examples command: ls -d / >/dev/null count: 20 units: minutes - unique: yes + unique: true diff --git a/docs/ansible.posix.authorized_key_module.rst b/docs/ansible.posix.authorized_key_module.rst index bfbb444..53efe25 100644 --- a/docs/ansible.posix.authorized_key_module.rst +++ b/docs/ansible.posix.authorized_key_module.rst @@ -139,8 +139,8 @@ Parameters
Whether this module should manage the directory of the authorized key file.
-
If set to yes, the module will create the directory, as well as set the owner and permissions of an existing directory.
-
Be sure to set manage_dir=no if you are using an alternate directory for authorized_keys, as set with path, since you could lock yourself out of SSH access.
+
If set to true, the module will create the directory, as well as set the owner and permissions of an existing directory.
+
Be sure to set manage_dir=false if you are using an alternate directory for authorized_keys, as set with path, since you could lock yourself out of SSH access.
See the example below.
@@ -212,9 +212,9 @@ Parameters
This only applies if using a https url as the source of the keys.
-
If set to no, the SSL certificates will not be validated.
-
This should only set to no used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
-
Prior to 2.1 the code worked as if this was set to yes.
+
If set to false, the SSL certificates will not be validated.
+
This should only set to false used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
+
Prior to 2.1 the code worked as if this was set to true.
@@ -252,7 +252,7 @@ Examples state: present key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" path: /etc/ssh/authorized_keys/charlie - manage_dir: False + manage_dir: false - name: Set up multiple authorized keys ansible.posix.authorized_key: @@ -275,14 +275,14 @@ Examples user: charlie state: present key: https://github.com/user.keys - validate_certs: False + validate_certs: false - name: Set authorized key, removing all the authorized keys already set ansible.posix.authorized_key: user: root key: "{{ lookup('file', 'public_keys/doe-jane') }}" state: present - exclusive: True + exclusive: true - name: Set authorized key for user ubuntu copying it from current user ansible.posix.authorized_key: @@ -460,7 +460,7 @@ Common return values are documented `here success -
This only applies if using a https url as the source of the keys. If set to no, the SSL certificates will not be validated.
+
This only applies if using a https url as the source of the keys. If set to false, the SSL certificates will not be validated.

Sample:
True
diff --git a/docs/ansible.posix.firewalld_info_module.rst b/docs/ansible.posix.firewalld_info_module.rst index 8bb6508..911acce 100644 --- a/docs/ansible.posix.firewalld_info_module.rst +++ b/docs/ansible.posix.firewalld_info_module.rst @@ -89,7 +89,12 @@ Examples - name: Gather information about active zones ansible.posix.firewalld_info: - active_zones: yes + active_zones: true + register: result + + - name: Print default zone for debugging + ansible.builtin.debug: + var: result.firewalld_info.default_zone - name: Gather information about specific zones ansible.posix.firewalld_info: @@ -97,6 +102,7 @@ Examples - public - external - internal + register: result @@ -163,7 +169,7 @@ Common return values are documented `here  
- default_zones + default_zone
string diff --git a/docs/ansible.posix.firewalld_module.rst b/docs/ansible.posix.firewalld_module.rst index ea58ff2..0932ac2 100644 --- a/docs/ansible.posix.firewalld_module.rst +++ b/docs/ansible.posix.firewalld_module.rst @@ -155,7 +155,7 @@ Parameters
Should this configuration be in the running firewalld configuration or persist across reboots.
As of Ansible 2.3, permanent operations can operate on firewalld configs when it is not running (requires firewalld >= 0.3.9).
-
Note that if this is no, immediate is assumed yes.
+
Note that if this is false, immediate is assumed true.
@@ -262,6 +262,21 @@ Parameters + + +
+ protocol + +
+ string +
+ + + + +
Name of a protocol to add/remove to/from firewalld.
+ +
@@ -414,29 +429,35 @@ Examples - name: permit traffic in default zone for https service ansible.posix.firewalld: service: https - permanent: yes + permanent: true + state: enabled + + - name: permit ospf traffic + ansible.posix.firewalld: + protocol: ospf + permanent: true state: enabled - name: do not permit traffic in default zone on port 8081/tcp ansible.posix.firewalld: port: 8081/tcp - permanent: yes + permanent: true state: disabled - ansible.posix.firewalld: port: 161-162/udp - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: zone: dmz service: http - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: rich_rule: rule service name="ftp" audit limit value="1/m" accept - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: @@ -447,44 +468,44 @@ Examples - ansible.posix.firewalld: zone: trusted interface: eth2 - permanent: yes + permanent: true state: enabled - ansible.posix.firewalld: - masquerade: yes + masquerade: true state: enabled - permanent: yes + permanent: true zone: dmz - ansible.posix.firewalld: zone: custom state: present - permanent: yes + permanent: true - ansible.posix.firewalld: zone: drop state: enabled - permanent: yes - icmp_block_inversion: yes + permanent: true + icmp_block_inversion: true - ansible.posix.firewalld: zone: drop state: enabled - permanent: yes + permanent: true icmp_block: echo-request - ansible.posix.firewalld: zone: internal state: present - permanent: yes + permanent: true target: ACCEPT - name: Redirect port 443 to 8443 with Rich Rule ansible.posix.firewalld: rich_rule: rule family=ipv4 forward-port port=443 protocol=tcp to-port=8443 zone: public - permanent: yes - immediate: yes + permanent: true + immediate: true state: enabled diff --git a/docs/ansible.posix.mount_module.rst b/docs/ansible.posix.mount_module.rst index 3ec3ce9..f38621f 100644 --- a/docs/ansible.posix.mount_module.rst +++ b/docs/ansible.posix.mount_module.rst @@ -73,6 +73,7 @@ Parameters
For Solaris systems, true will set yes as the value of mount at boot in /etc/vfstab.
For Linux, FreeBSD, NetBSD and OpenBSD systems, false will add noauto to mount options in /etc/fstab.
To avoid mount option conflicts, if noauto specified in opts, mount module will ignore boot.
+
This parameter is ignored when state is set to ephemeral.
@@ -90,7 +91,7 @@ Parameters
Dump (see fstab(5)).
Note that if set to null and state set to present, it will cease to work and duplicate entries will be made with subsequent runs.
-
Has no effect on Solaris systems.
+
Has no effect on Solaris systems or when used with ephemeral.
@@ -110,6 +111,7 @@ Parameters
This might be useful if you need to configure mountpoints in a chroot environment.
OpenBSD does not allow specifying alternate fstab files with mount so do not use this on OpenBSD with any state that operates on the live filesystem.
This parameter defaults to /etc/fstab or /etc/vfstab on Solaris.
+
This parameter is ignored when state is set to ephemeral.
@@ -125,7 +127,7 @@ Parameters
Filesystem type.
-
Required when state is present or mounted.
+
Required when state is present, mounted or ephemeral.
@@ -158,7 +160,7 @@ Parameters
Passno (see fstab(5)).
Note that if set to null and state set to present, it will cease to work and duplicate entries will be made with subsequent runs.
-
Deprecated on Solaris systems.
+
Deprecated on Solaris systems. Has no effect when used with ephemeral.
@@ -192,7 +194,7 @@ Parameters
Device (or NFS volume, or something else) to be mounted on path.
-
Required when state set to present or mounted.
+
Required when state set to present, mounted or ephemeral.
@@ -208,18 +210,22 @@ Parameters
    Choices:
  • absent
  • +
  • absent_from_fstab
  • mounted
  • present
  • unmounted
  • remounted
  • +
  • ephemeral
If mounted, the device will be actively mounted and appropriately configured in fstab. If the mount point is not present, the mount point will be created.
If unmounted, the device will be unmounted without changing fstab.
present only specifies that the device is to be configured in fstab and does not trigger or require a mount.
+
ephemeral only specifies that the device is to be mounted, without changing fstab. If it is already mounted, a remount will be triggered. This will always return changed=True. If the mount point path has already a device mounted on, and its source is different than src, the module will fail to avoid unexpected unmount or mount point override. If the mount point is not present, the mount point will be created. The fstab is completely ignored. This option is added in version 1.5.0.
absent specifies that the device mount's entry will be removed from fstab and will also unmount the device and remove the mount point.
-
remounted specifies that the device will be remounted for when you want to force a refresh on the mount itself (added in 2.9). This will always return changed=true. If opts is set, the options will be applied to the remount, but will not change fstab. Additionally, if opts is set, and the remount command fails, the module will error to prevent unexpected mount changes. Try using mounted instead to work around this issue.
+
remounted specifies that the device will be remounted for when you want to force a refresh on the mount itself (added in 2.9). This will always return changed=true. If opts is set, the options will be applied to the remount, but will not change fstab. Additionally, if opts is set, and the remount command fails, the module will error to prevent unexpected mount changes. Try using mounted instead to work around this issue. remounted expects the mount point to be present in the fstab. To remount a mount point not registered in fstab, use ephemeral instead, especially with BSD nodes.
+
absent_from_fstab specifies that the device mount's entry will be removed from fstab. This option does not unmount it or delete the mountpoint.
@@ -304,10 +310,18 @@ Examples src: 192.168.1.100:/nfs/ssd/shared_data path: /mnt/shared_data opts: rw,sync,hard - boot: no + boot: false state: mounted fstype: nfs + - name: Mount ephemeral SMB volume + ansible.posix.mount: + src: //192.168.1.200/share + path: /mnt/smb_share + opts: "rw,vers=3,file_mode=0600,dir_mode=0700,dom={{ ad_domain }},username={{ ad_username }},password={{ ad_password }}" + fstype: cifs + state: ephemeral + diff --git a/docs/ansible.posix.patch_module.rst b/docs/ansible.posix.patch_module.rst index 60c30cf..07f672a 100644 --- a/docs/ansible.posix.patch_module.rst +++ b/docs/ansible.posix.patch_module.rst @@ -84,9 +84,9 @@ Parameters -
Setting to yes will disable patch's heuristic for transforming CRLF line endings into LF.
+
Setting to true will disable patch's heuristic for transforming CRLF line endings into LF.
Line endings of src and dest must match.
-
If set to no, patch will replace CRLF in src files on POSIX.
+
If set to false, patch will replace CRLF in src files on POSIX.
@@ -122,7 +122,7 @@ Parameters -
Setting to yes will ignore white space changes between patch and input..
+
Setting to true will ignore white space changes between patch and input.
@@ -141,7 +141,7 @@ Parameters -
If no, it will search for src at originating/controller machine, if yes it will go to the remote/target machine for the src.
+
If false, it will search for src at originating/controller machine, if true it will go to the remote/target machine for the src.
@@ -157,7 +157,7 @@ Parameters -
Path of the patch file as accepted by the GNU patch tool. If remote_src is 'no', the patch source file is looked up from the module's files directory.
+
Path of the patch file as accepted by the GNU patch tool. If remote_src is false, the patch source file is looked up from the module's files directory.

aliases: patchfile
diff --git a/docs/ansible.posix.rhel_facts_module.rst b/docs/ansible.posix.rhel_facts_module.rst new file mode 100644 index 0000000..d4c8fb6 --- /dev/null +++ b/docs/ansible.posix.rhel_facts_module.rst @@ -0,0 +1,103 @@ +.. _ansible.posix.rhel_facts_module: + + +************************ +ansible.posix.rhel_facts +************************ + +**Facts module to set or override RHEL specific facts.** + + +Version added: 1.5.0 + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- +- Compatibility layer for using the "package" module for rpm-ostree based systems via setting the "pkg_mgr" fact correctly. + + + +Requirements +------------ +The below requirements are needed on the host that executes this module. + +- rpm-ostree + + + + +See Also +-------- + +.. seealso:: + + :ref:`ansible.builtin.package_module` + The official documentation on the **ansible.builtin.package** module. + + +Examples +-------- + +.. code-block:: yaml + + - name: Playbook to use the package module on all RHEL footprints + vars: + ansible_facts_modules: + - setup # REQUIRED to be run before all custom fact modules + - ansible.posix.rhel_facts + tasks: + - name: Ensure packages are installed + ansible.builtin.package: + name: + - htop + - ansible + state: present + + +Returned Facts +-------------- +Facts returned by this module are added/updated in the ``hostvars`` host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them. + +.. raw:: html + + + + + + + + + + + + +
FactReturnedDescription
+
+ pkg_mgr + +
+ string +
+
when needed +
System-level package manager override +
+
+
Sample:
+
{'pkg_mgr': 'ansible.posix.rhel_facts'}
+
+

+ + + +Status +------ + + +Authors +~~~~~~~ + +- Adam Miller (@maxamillion) diff --git a/docs/ansible.posix.rhel_rpm_ostree_module.rst b/docs/ansible.posix.rhel_rpm_ostree_module.rst new file mode 100644 index 0000000..b170b15 --- /dev/null +++ b/docs/ansible.posix.rhel_rpm_ostree_module.rst @@ -0,0 +1,156 @@ +.. _ansible.posix.rhel_rpm_ostree_module: + + +***************************** +ansible.posix.rhel_rpm_ostree +***************************** + +**Ensure packages exist in a RHEL for Edge rpm-ostree based system** + + +Version added: 1.5.0 + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- +- Compatibility layer for using the "package" module for RHEL for Edge systems utilizing the RHEL System Roles. + + + +Requirements +------------ +The below requirements are needed on the host that executes this module. + +- rpm-ostree + + +Parameters +---------- + +.. raw:: html + + + + + + + + + + + + + + + + + +
ParameterChoices/DefaultsComments
+
+ name + +
+ list + / elements=string +
+
+ Default:
[]
+
+
A package name or package specifier with version, like name-1.0.
+
Comparison operators for package version are valid here >, <, >=, <=. Example - name>=1.0
+
If a previous version is specified, the task also needs to turn allow_downgrade on. See the allow_downgrade documentation for caveats with downgrading packages.
+
When using state=latest, this can be '*' which means run yum -y update.
+
You can also pass a url or a local path to a rpm file (using state=present). To operate on several packages this can accept a comma separated string of packages or (as of 2.0) a list of packages.
+

aliases: pkg
+
+
+ state + +
+ string +
+
+
    Choices: +
  • absent
  • +
  • installed
  • +
  • latest
  • +
  • present
  • +
  • removed
  • +
+
+
Whether to install (present or installed, latest), or remove (absent or removed) a package.
+
present and installed will simply ensure that a desired package is installed.
+
latest will update the specified package if it's not of the latest available version.
+
absent and removed will remove the specified package.
+
Default is None, however in effect the default action is present unless the autoremove option is enabled for this module, then absent is inferred.
+
+
+ + +Notes +----- + +.. note:: + - This module does not support installing or removing packages to/from an overlay as this is not supported by RHEL for Edge, packages needed should be defined in the osbuild Blueprint and provided to Image Builder at build time. This module exists only for ``package`` module compatibility. + + + +Examples +-------- + +.. code-block:: yaml + + - name: Ensure htop and ansible are installed on rpm-ostree based RHEL + ansible.posix.rhel_rpm_ostree: + name: + - htop + - ansible + state: present + + + +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + +
KeyReturnedDescription
+
+ msg + +
+ string +
+
always +
status of rpm transaction
+
+
Sample:
+
No changes made.
+
+

+ + +Status +------ + + +Authors +~~~~~~~ + +- Adam Miller (@maxamillion) diff --git a/docs/ansible.posix.rpm_ostree_upgrade_module.rst b/docs/ansible.posix.rpm_ostree_upgrade_module.rst new file mode 100644 index 0000000..d683166 --- /dev/null +++ b/docs/ansible.posix.rpm_ostree_upgrade_module.rst @@ -0,0 +1,175 @@ +.. _ansible.posix.rpm_ostree_upgrade_module: + + +******************************** +ansible.posix.rpm_ostree_upgrade +******************************** + +**Manage rpm-ostree upgrade transactions** + + +Version added: 1.5.0 + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- +- Manage an rpm-ostree upgrade transactions. + + + +Requirements +------------ +The below requirements are needed on the host that executes this module. + +- rpm-ostree + + +Parameters +---------- + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterChoices/DefaultsComments
+
+ allow_downgrade + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Allow for the upgrade to be a chronologically older tree.
+
+
+ cache_only + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Perform the transaction using only pre-cached data, do not download.
+
+
+ os + +
+ string +
+
+ Default:
""
+
+
The OSNAME upon which to operate.
+
+
+ peer + +
+ boolean +
+
+
    Choices: +
  • no ←
  • +
  • yes
  • +
+
+
Force peer-to-peer connection instead of using a system message bus.
+
+
+ + + + +Examples +-------- + +.. code-block:: yaml + + - name: Upgrade the rpm-ostree image without options, accept all defaults + ansible.posix.rpm_ostree_upgrade: + + - name: Upgrade the rpm-ostree image allowing downgrades + ansible.posix.rpm_ostree_upgrade: + allow_downgrade: true + + + +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + +
KeyReturnedDescription
+
+ msg + +
+ string +
+
always +
The command standard output
+
+
Sample:
+
No upgrade available.
+
+

+ + +Status +------ + + +Authors +~~~~~~~ + +- Adam Miller (@maxamillion) diff --git a/docs/ansible.posix.seboolean_module.rst b/docs/ansible.posix.seboolean_module.rst index 03a9b33..330d091 100644 --- a/docs/ansible.posix.seboolean_module.rst +++ b/docs/ansible.posix.seboolean_module.rst @@ -92,7 +92,7 @@ Parameters -
Set to yes if the boolean setting should survive a reboot.
+
Set to true if the boolean setting should survive a reboot.
@@ -135,8 +135,8 @@ Examples - name: Set httpd_can_network_connect flag on and keep it persistent across reboots ansible.posix.seboolean: name: httpd_can_network_connect - state: yes - persistent: yes + state: true + persistent: true diff --git a/docs/ansible.posix.synchronize_module.rst b/docs/ansible.posix.synchronize_module.rst index 82458df..7cb3059 100644 --- a/docs/ansible.posix.synchronize_module.rst +++ b/docs/ansible.posix.synchronize_module.rst @@ -150,7 +150,7 @@ Parameters
Delete files in dest that do not exist (after transfer, not before) in the src path.
-
This option requires recursive=yes.
+
This option requires recursive=true.
This option ignores excluded files and behaves like the rsync opt --delete-after.
@@ -465,7 +465,7 @@ Parameters
Put user@ for the remote paths.
-
If you have a custom ssh config to define the remote user for a host that does not match the inventory user, you should set this parameter to no.
+
If you have a custom ssh config to define the remote user for a host that does not match the inventory user, you should set this parameter to false.
@@ -502,8 +502,8 @@ Parameters
SSH connection multiplexing for rsync is disabled by default to prevent misconfigured ControlSockets from resulting in failed SSH connections. This is accomplished by setting the SSH ControlSocket to none.
-
Set this option to yes to allow multiplexing and reduce SSH connection overhead.
-
Note that simply setting this option to yes is not enough; You must also configure SSH connection multiplexing in your SSH client config by setting values for ControlMaster, ControlPersist and ControlPath.
+
Set this option to true to allow multiplexing and reduce SSH connection overhead.
+
Note that simply setting this option to true is not enough; You must also configure SSH connection multiplexing in your SSH client config by setting values for ControlMaster, ControlPersist and ControlPath.
@@ -595,8 +595,8 @@ See Also .. seealso:: - :ref:`copy_module` - The official documentation on the **copy** module. + :ref:`ansible.builtin.copy_module` + The official documentation on the **ansible.builtin.copy** module. :ref:`community.windows.win_robocopy_module` The official documentation on the **community.windows.win_robocopy** module. @@ -639,27 +639,27 @@ Examples ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - archive: no + archive: false - name: Synchronization with --archive options enabled except for --recursive ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - recursive: no + recursive: false - name: Synchronization with --archive options enabled except for --times, with --checksum option enabled ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - checksum: yes - times: no + checksum: true + times: false - name: Synchronization without --archive options enabled except use --links ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - archive: no - links: yes + archive: false + links: true - name: Synchronization of two paths both on the control machine ansible.posix.synchronize: @@ -689,8 +689,8 @@ Examples ansible.posix.synchronize: src: some/relative/path dest: /some/absolute/path - delete: yes - recursive: yes + delete: true + recursive: true # This specific command is granted su privileges on the destination - name: Synchronize using an alternate rsync command diff --git a/docs/ansible.posix.sysctl_module.rst b/docs/ansible.posix.sysctl_module.rst index 1f49cf6..1a3b111 100644 --- a/docs/ansible.posix.sysctl_module.rst +++ b/docs/ansible.posix.sysctl_module.rst @@ -85,7 +85,7 @@ Parameters -
If yes, performs a /sbin/sysctl -p if the sysctl_file is updated. If no, does not reload sysctl even if the sysctl_file is updated.
+
If true, performs a /sbin/sysctl -p if the sysctl_file is updated. If false, does not reload sysctl even if the sysctl_file is updated.
@@ -139,7 +139,7 @@ Parameters -
Verify token value with the sysctl command and set with -w if necessary
+
Verify token value with the sysctl command and set with -w if necessary.
@@ -186,21 +186,21 @@ Examples name: kernel.panic value: '3' sysctl_file: /tmp/test_sysctl.conf - reload: no + reload: false # Set ip forwarding on in /proc and verify token value with the sysctl command - ansible.posix.sysctl: name: net.ipv4.ip_forward value: '1' - sysctl_set: yes + sysctl_set: true # Set ip forwarding on in /proc and in the sysctl file and reload if necessary - ansible.posix.sysctl: name: net.ipv4.ip_forward value: '1' - sysctl_set: yes + sysctl_set: true state: present - reload: yes + reload: true diff --git a/galaxy.yml b/galaxy.yml index 9520636..e31ae2e 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: ansible name: posix -version: 1.5.0 +version: 1.5.2 readme: README.md authors: - Ansible (github.com/ansible) From 38dd009615e27a1b81e695ef8f071dcdefdba446 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 10 Apr 2023 17:45:13 +0900 Subject: [PATCH 071/109] Bump release version in galaxy.yml for the next release number. Signed-off-by: Hideki Saito --- galaxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.yml b/galaxy.yml index e31ae2e..5eec30c 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: ansible name: posix -version: 1.5.2 +version: 1.5.3 readme: README.md authors: - Ansible (github.com/ansible) From 7d069b597fdecc922dc69cc077f1568455abd3d4 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Mon, 10 Apr 2023 15:13:22 +0200 Subject: [PATCH 072/109] add changelog fragment Signed-off-by: Daniel Ziegenberg --- .../fragments/343-fix-profile_tasks-callback-documentation.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml diff --git a/changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml b/changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml new file mode 100644 index 0000000..06d1c8d --- /dev/null +++ b/changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml @@ -0,0 +1,3 @@ +--- +trivial: + - fix profile_tasks callback documentation by using correct markup From 940d914904489365ff1e6c93194979f1ad889170 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Sat, 8 Apr 2023 07:28:11 -0400 Subject: [PATCH 073/109] json[l] callback: add play/task path info Add the play and task path info (i.e., filename and line number) to the JSON that is emitted from the json and jsonl callback plugins, allowing more accurate post-mortem analysis. Signed-off-by: Jeff Squyres --- changelogs/fragments/440-json-add-path-field.yaml | 2 ++ plugins/callback/json.py | 2 ++ plugins/callback/jsonl.py | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 changelogs/fragments/440-json-add-path-field.yaml diff --git a/changelogs/fragments/440-json-add-path-field.yaml b/changelogs/fragments/440-json-add-path-field.yaml new file mode 100644 index 0000000..4c15dcc --- /dev/null +++ b/changelogs/fragments/440-json-add-path-field.yaml @@ -0,0 +1,2 @@ +minor_changes: + - json and jsonl - Add the ``path`` attribute into the play and task output diff --git a/plugins/callback/json.py b/plugins/callback/json.py index f0c56b4..512f25b 100644 --- a/plugins/callback/json.py +++ b/plugins/callback/json.py @@ -67,6 +67,7 @@ class CallbackModule(CallbackBase): 'play': { 'name': play.get_name(), 'id': to_text(play._uuid), + 'path': to_text(play.get_path()), 'duration': { 'start': current_time() } @@ -79,6 +80,7 @@ class CallbackModule(CallbackBase): 'task': { 'name': task.get_name(), 'id': to_text(task._uuid), + 'path': to_text(task.get_path()), 'duration': { 'start': current_time() } diff --git a/plugins/callback/jsonl.py b/plugins/callback/jsonl.py index 2403dba..dc77b03 100644 --- a/plugins/callback/jsonl.py +++ b/plugins/callback/jsonl.py @@ -69,6 +69,7 @@ class CallbackModule(CallbackBase): 'play': { 'name': play.get_name(), 'id': to_text(play._uuid), + 'path': to_text(play.get_path()), 'duration': { 'start': current_time() } @@ -81,6 +82,7 @@ class CallbackModule(CallbackBase): 'task': { 'name': task.get_name(), 'id': to_text(task._uuid), + 'path': to_text(task.get_path()), 'duration': { 'start': current_time() } From 91a6e30d7852d0a122d4b0b0ef1525cec9b2d754 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 12 Apr 2023 15:52:02 +0900 Subject: [PATCH 074/109] Update AZP to support stable-2.15 branch - Fixes #444 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 40 +++++++++++++++++++ .../fragments/445_ci_support_stable-215.yml | 3 ++ tests/utils/shippable/shippable.sh | 4 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/445_ci_support_stable-215.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 728ef40..7b352f5 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -61,6 +61,24 @@ stages: test: ubuntu2004 - name: Ubuntu 22.04 test: ubuntu2204 + - stage: Docker_2_15 + displayName: Docker 2.15 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.15/linux/{0}/1 + targets: + - name: CentOS 7 + test: centos7 + - name: Fedora 37 + test: fedora37 + - name: openSUSE 15 py3 + test: opensuse15 + - name: Ubuntu 20.04 + test: ubuntu2004 + - name: Ubuntu 22.04 + test: ubuntu2204 - stage: Docker_2_14 displayName: Docker 2.14 dependsOn: [] @@ -203,6 +221,26 @@ stages: test: freebsd/12.4 - name: FreeBSD 13.1 test: freebsd/13.1 + - stage: Remote_2_15 + displayName: Remote 2.15 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.15/{0}/1 + targets: + - name: MacOS 13.2 + test: macos/13.2 + - name: RHEL 7.9 + test: rhel/7.9 + - name: RHEL 8.7 + test: rhel/8.7 + - name: RHEL 9.1 + test: rhel/9.1 + - name: FreeBSD 12.4 + test: freebsd/12.4 + - name: FreeBSD 13.1 + test: freebsd/13.1 - stage: Remote_2_14 displayName: Remote 2.14 dependsOn: [] @@ -321,6 +359,8 @@ stages: - Docker_2_13 - Remote_2_14 - Docker_2_14 + - Remote_2_15 + - Docker_2_15 - Remote_devel - Docker_devel jobs: diff --git a/changelogs/fragments/445_ci_support_stable-215.yml b/changelogs/fragments/445_ci_support_stable-215.yml new file mode 100644 index 0000000..7ee3c5f --- /dev/null +++ b/changelogs/fragments/445_ci_support_stable-215.yml @@ -0,0 +1,3 @@ +--- +trivial: + - CI - update AZP to support stable-2.15 branch (https://github.com/ansible-collections/ansible.posix/issues/444). diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index 8dfec24..1a8be27 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -145,9 +145,9 @@ function cleanup fi if [ "${process_coverage}" ]; then - # use python 3.7 for coverage to avoid running out of memory during coverage xml processing + # use python 3.9 for coverage to avoid running out of memory during coverage xml processing # only use it for coverage to avoid the additional overhead of setting up a virtual environment for a potential no-op job - virtualenv --python /usr/bin/python3.7 ~/ansible-venv + virtualenv --python /usr/bin/python3.9 ~/ansible-venv set +ux . ~/ansible-venv/bin/activate set -ux From 1c560e93d2471e93a6541a4706e229d278f54116 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 17 Apr 2023 16:13:33 +0900 Subject: [PATCH 075/109] Support sanity docker test on devel(2.16.0.dev0) branch - Fixes #446 Signed-off-by: Hideki Saito --- changelogs/fragments/448_support_new_sanity_test.yml | 3 +++ tests/sanity/ignore-2.16.txt | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 changelogs/fragments/448_support_new_sanity_test.yml create mode 100644 tests/sanity/ignore-2.16.txt diff --git a/changelogs/fragments/448_support_new_sanity_test.yml b/changelogs/fragments/448_support_new_sanity_test.yml new file mode 100644 index 0000000..a7faa91 --- /dev/null +++ b/changelogs/fragments/448_support_new_sanity_test.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Support new sanity test for the ansible-core devel branch CI test (https://github.com/ansible-collections/ansible.posix/issues/446). diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt new file mode 100644 index 0000000..4f0aa92 --- /dev/null +++ b/tests/sanity/ignore-2.16.txt @@ -0,0 +1,5 @@ +plugins/modules/synchronize.py use-argspec-type-path +plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec +plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented +plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc +plugins/modules/synchronize.py validate-modules:undocumented-parameter From 281f957ece95fae16bb7d12b863e6e9b89523b14 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Sat, 8 Apr 2023 08:01:06 -0400 Subject: [PATCH 076/109] json[l] callback: add parameter to set JSON prettyprint indent level Add ANSIBLE_JSON_INDENT parameter to both the json and jsonl callback plugins. The default values are different between the two modules to maintain their existing behavior: * json: indent==4, causing a prettyprint output * jsonl: indent==0, causing a 1-line output One specific use-case that is enabled by this feature: if a user chooses to use the jsonl plugin so that they still get output at the end of each task (vs. only at the end of the play), they may also want human-readable output so that they can monitor the status of their play. For example, setting the jsonl indent level to 4 gives a) output at the end of each task, and b) making that output be both machine readable and human readable. Signed-off-by: Jeff Squyres --- .../441-json-add-indent-parameter.yaml | 2 ++ plugins/callback/json.py | 18 +++++++++++++++++- plugins/callback/jsonl.py | 18 +++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/441-json-add-indent-parameter.yaml diff --git a/changelogs/fragments/441-json-add-indent-parameter.yaml b/changelogs/fragments/441-json-add-indent-parameter.yaml new file mode 100644 index 0000000..8a0359b --- /dev/null +++ b/changelogs/fragments/441-json-add-indent-parameter.yaml @@ -0,0 +1,2 @@ +minor_changes: + - json and jsonl - Add the ``ANSIBLE_JSON_INDENT`` parameter diff --git a/plugins/callback/json.py b/plugins/callback/json.py index f0c56b4..f57a7d6 100644 --- a/plugins/callback/json.py +++ b/plugins/callback/json.py @@ -25,6 +25,16 @@ DOCUMENTATION = ''' - key: show_custom_stats section: defaults type: bool + json_indent: + name: Use indenting for the JSON output + description: 'If specified, use this many spaces for indenting in the JSON output. If <= 0, write to a single line.' + default: 4 + env: + - name: ANSIBLE_JSON_INDENT + ini: + - key: json_indent + section: defaults + type: integer notes: - When using a strategy such as free, host_pinned, or a custom strategy, host results will be added to new task results in ``.plays[].tasks[]``. As such, there will exist duplicate @@ -61,6 +71,12 @@ class CallbackModule(CallbackBase): self._task_map = {} self._is_lockstep = False + self.set_options() + + self._json_indent = self.get_option('json_indent') + if self._json_indent <= 0: + self._json_indent = None + def _new_play(self, play): self._is_lockstep = play.strategy in LOCKSTEP_CALLBACKS return { @@ -143,7 +159,7 @@ class CallbackModule(CallbackBase): 'global_custom_stats': global_custom_stats, } - self._display.display(json.dumps(output, cls=AnsibleJSONEncoder, indent=4, sort_keys=True)) + self._display.display(json.dumps(output, cls=AnsibleJSONEncoder, indent=self._json_indent, sort_keys=True)) def _record_task_result(self, on_info, result, **kwargs): """This function is used as a partial to add failed/skipped info in a single method""" diff --git a/plugins/callback/jsonl.py b/plugins/callback/jsonl.py index 2403dba..febeca1 100644 --- a/plugins/callback/jsonl.py +++ b/plugins/callback/jsonl.py @@ -26,6 +26,16 @@ DOCUMENTATION = ''' - key: show_custom_stats section: defaults type: bool + json_indent: + name: Use indenting for the JSON output + description: 'If specified, use this many spaces for indenting in the JSON output. If not specified or <= 0, write to a single line.' + default: 0 + env: + - name: ANSIBLE_JSON_INDENT + ini: + - key: json_indent + section: defaults + type: integer notes: - When using a strategy such as free, host_pinned, or a custom strategy, host results will be added to new task results in ``.plays[].tasks[]``. As such, there will exist duplicate @@ -63,6 +73,12 @@ class CallbackModule(CallbackBase): self._task_map = {} self._is_lockstep = False + self.set_options() + + self._json_indent = self.get_option('json_indent') + if self._json_indent <= 0: + self._json_indent = None + def _new_play(self, play): self._is_lockstep = play.strategy in LOCKSTEP_CALLBACKS return { @@ -156,7 +172,7 @@ class CallbackModule(CallbackBase): def _write_event(self, event_name, output): output['_event'] = event_name output['_timestamp'] = current_time() - self._display.display(json.dumps(output, cls=AnsibleJSONEncoder, separators=',:', sort_keys=True)) + self._display.display(json.dumps(output, cls=AnsibleJSONEncoder, indent=self._json_indent, separators=',:', sort_keys=True)) def _record_task_result(self, event_name, on_info, result, **kwargs): """This function is used as a partial to add failed/skipped info in a single method""" From 41ce2cc8f9a3518499bc0acbde0e610540e2da2b Mon Sep 17 00:00:00 2001 From: Reto Kupferschmid Date: Wed, 3 May 2023 19:04:35 +0200 Subject: [PATCH 077/109] fix firewalld protocol --- plugins/modules/firewalld.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index 3546749..a90d808 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -858,10 +858,10 @@ def main(): if module.params['port'] is not None: if '/' in module.params['port']: - port, protocol = module.params['port'].strip().split('/') + port, port_protocol = module.params['port'].strip().split('/') else: - protocol = None - if not protocol: + port_protocol = None + if not port_protocol: module.fail_json(msg='improper port format (missing protocol?)') else: port = None @@ -981,7 +981,7 @@ def main(): transaction = PortTransaction( module, - action_args=(port, protocol, timeout), + action_args=(port, port_protocol, timeout), zone=zone, desired_state=desired_state, permanent=permanent, @@ -993,7 +993,7 @@ def main(): if changed is True: msgs.append( "Changed port %s to %s" % ( - "%s/%s" % (port, protocol), desired_state + "%s/%s" % (port, port_protocol), desired_state ) ) From 15954f8def606fa19bfcd04dcbddb70562e1b213 Mon Sep 17 00:00:00 2001 From: Reto Kupferschmid Date: Wed, 3 May 2023 19:25:06 +0200 Subject: [PATCH 078/109] add changelog fragment --- changelogs/fragments/451_firewall_fix_protocol_parameter.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/451_firewall_fix_protocol_parameter.yml diff --git a/changelogs/fragments/451_firewall_fix_protocol_parameter.yml b/changelogs/fragments/451_firewall_fix_protocol_parameter.yml new file mode 100644 index 0000000..9dfc6bd --- /dev/null +++ b/changelogs/fragments/451_firewall_fix_protocol_parameter.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - firewall - Fix issue where opening a specific port resulted in opening the whole protocol of the specified port From 0eb6a7a437624b60e04ab445c3e66cfcde0f308d Mon Sep 17 00:00:00 2001 From: Reto Kupferschmid Date: Wed, 3 May 2023 19:31:05 +0200 Subject: [PATCH 079/109] fixup! fix firewalld protocol --- plugins/modules/firewalld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index a90d808..b69cc8d 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -864,7 +864,7 @@ def main(): if not port_protocol: module.fail_json(msg='improper port format (missing protocol?)') else: - port = None + port_protocol = None port_forward_toaddr = '' port_forward = None From f1b36ba1c2b523afb1ef977a486c57b9aff47188 Mon Sep 17 00:00:00 2001 From: Reto Kupferschmid Date: Thu, 4 May 2023 07:34:08 +0200 Subject: [PATCH 080/109] fix unbound variable error --- plugins/modules/firewalld.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index b69cc8d..cf55e1c 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -856,6 +856,7 @@ def main(): zone = module.params['zone'] target = module.params['target'] + port = None if module.params['port'] is not None: if '/' in module.params['port']: port, port_protocol = module.params['port'].strip().split('/') From 07f1e11015658f87aed1cc5bb205989a626c871f Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Fri, 5 May 2023 11:59:04 -0500 Subject: [PATCH 081/109] fix sysctl integration test failing on newer versions of core Previously NoneType was allowable, now it fails to convert to a str type. Signed-off-by: Adam Miller --- tests/integration/targets/sysctl/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/sysctl/tasks/main.yml b/tests/integration/targets/sysctl/tasks/main.yml index c9a63c4..0c40fc3 100644 --- a/tests/integration/targets/sysctl/tasks/main.yml +++ b/tests/integration/targets/sysctl/tasks/main.yml @@ -170,7 +170,7 @@ - name: Try sysctl with no name sysctl: - name: + name: "" value: 1 sysctl_set: yes ignore_errors: True @@ -180,7 +180,7 @@ assert: that: - sysctl_no_name is failed - - "sysctl_no_name.msg == 'name cannot be None'" + - "sysctl_no_name.msg == 'name cannot be blank'" - name: Try sysctl with no value sysctl: From 4f46ff218fd55db68e42e18c61f98a0dc0e99e4e Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Fri, 5 May 2023 12:02:54 -0500 Subject: [PATCH 082/109] add changelog fragment Signed-off-by: Adam Miller --- changelogs/fragments/456_sysctl_fix_nonetype.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/456_sysctl_fix_nonetype.yml diff --git a/changelogs/fragments/456_sysctl_fix_nonetype.yml b/changelogs/fragments/456_sysctl_fix_nonetype.yml new file mode 100644 index 0000000..0bcb27f --- /dev/null +++ b/changelogs/fragments/456_sysctl_fix_nonetype.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "Fix sysctl integration test failing on newer versions of core. Previously NoneType was allowable, now it fails to convert to a str type." From 3bbf2e3cd56775096fc8ce69e281142472b73cac Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Wed, 10 May 2023 13:17:59 -0500 Subject: [PATCH 083/109] Release 1.5.4 Signed-off-by: Adam Miller --- CHANGELOG.rst | 18 +++++++++++++ changelogs/changelog.yaml | 26 +++++++++++++++++++ ...x-profile_tasks-callback-documentation.yml | 3 --- ...402_firewall_fix_offline_interface_add.yml | 3 --- ...squerade_icmp_block_inversion_bugfixes.yml | 3 --- .../fragments/440-json-add-path-field.yaml | 2 -- .../441-json-add-indent-parameter.yaml | 2 -- .../fragments/445_ci_support_stable-215.yml | 3 --- .../fragments/448_support_new_sanity_test.yml | 3 --- .../451_firewall_fix_protocol_parameter.yml | 3 --- .../fragments/456_sysctl_fix_nonetype.yml | 3 --- galaxy.yml | 2 +- 12 files changed, 45 insertions(+), 26 deletions(-) delete mode 100644 changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml delete mode 100644 changelogs/fragments/402_firewall_fix_offline_interface_add.yml delete mode 100644 changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml delete mode 100644 changelogs/fragments/440-json-add-path-field.yaml delete mode 100644 changelogs/fragments/441-json-add-indent-parameter.yaml delete mode 100644 changelogs/fragments/445_ci_support_stable-215.yml delete mode 100644 changelogs/fragments/448_support_new_sanity_test.yml delete mode 100644 changelogs/fragments/451_firewall_fix_protocol_parameter.yml delete mode 100644 changelogs/fragments/456_sysctl_fix_nonetype.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 06cdf22..ffb9afa 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,24 @@ ansible.posix Release Notes .. contents:: Topics +v1.5.4 +====== + +Minor Changes +------------- + +- json and jsonl - Add the ``ANSIBLE_JSON_INDENT`` parameter +- json and jsonl - Add the ``path`` attribute into the play and task output + +Bugfixes +-------- + +- Fix sysctl integration test failing on newer versions of core. Previously NoneType was allowable, now it fails to convert to a str type. +- Support new sanity test for the ansible-core devel branch CI test (https://github.com/ansible-collections/ansible.posix/issues/446). +- firewall - Fix issue where adding an interface to a zone would fail when the daemon is offline +- firewall - Fix issue where opening a specific port resulted in opening the whole protocol of the specified port +- firewalld - Consider value of masquerade and icmp_block_inversion parameters when a boolean like value is passed + v1.5.2 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 0b59c25..299f168 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -321,3 +321,29 @@ releases: - 434-fix-rhel_facts-exit_json.yml - 535-add-jsonl-callback.yml release_date: '2023-04-07' + 1.5.4: + changes: + bugfixes: + - Fix sysctl integration test failing on newer versions of core. Previously + NoneType was allowable, now it fails to convert to a str type. + - Support new sanity test for the ansible-core devel branch CI test (https://github.com/ansible-collections/ansible.posix/issues/446). + - firewall - Fix issue where adding an interface to a zone would fail when the + daemon is offline + - firewall - Fix issue where opening a specific port resulted in opening the + whole protocol of the specified port + - firewalld - Consider value of masquerade and icmp_block_inversion parameters + when a boolean like value is passed + minor_changes: + - json and jsonl - Add the ``ANSIBLE_JSON_INDENT`` parameter + - json and jsonl - Add the ``path`` attribute into the play and task output + fragments: + - 343-fix-profile_tasks-callback-documentation.yml + - 402_firewall_fix_offline_interface_add.yml + - 404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml + - 440-json-add-path-field.yaml + - 441-json-add-indent-parameter.yaml + - 445_ci_support_stable-215.yml + - 448_support_new_sanity_test.yml + - 451_firewall_fix_protocol_parameter.yml + - 456_sysctl_fix_nonetype.yml + release_date: '2023-05-10' diff --git a/changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml b/changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml deleted file mode 100644 index 06d1c8d..0000000 --- a/changelogs/fragments/343-fix-profile_tasks-callback-documentation.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - fix profile_tasks callback documentation by using correct markup diff --git a/changelogs/fragments/402_firewall_fix_offline_interface_add.yml b/changelogs/fragments/402_firewall_fix_offline_interface_add.yml deleted file mode 100644 index e59a45d..0000000 --- a/changelogs/fragments/402_firewall_fix_offline_interface_add.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - firewall - Fix issue where adding an interface to a zone would fail when the daemon is offline diff --git a/changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml b/changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml deleted file mode 100644 index 144b80e..0000000 --- a/changelogs/fragments/404_firewalld_masquerade_icmp_block_inversion_bugfixes.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - firewalld - Consider value of masquerade and icmp_block_inversion parameters when a boolean like value is passed diff --git a/changelogs/fragments/440-json-add-path-field.yaml b/changelogs/fragments/440-json-add-path-field.yaml deleted file mode 100644 index 4c15dcc..0000000 --- a/changelogs/fragments/440-json-add-path-field.yaml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: - - json and jsonl - Add the ``path`` attribute into the play and task output diff --git a/changelogs/fragments/441-json-add-indent-parameter.yaml b/changelogs/fragments/441-json-add-indent-parameter.yaml deleted file mode 100644 index 8a0359b..0000000 --- a/changelogs/fragments/441-json-add-indent-parameter.yaml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: - - json and jsonl - Add the ``ANSIBLE_JSON_INDENT`` parameter diff --git a/changelogs/fragments/445_ci_support_stable-215.yml b/changelogs/fragments/445_ci_support_stable-215.yml deleted file mode 100644 index 7ee3c5f..0000000 --- a/changelogs/fragments/445_ci_support_stable-215.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - CI - update AZP to support stable-2.15 branch (https://github.com/ansible-collections/ansible.posix/issues/444). diff --git a/changelogs/fragments/448_support_new_sanity_test.yml b/changelogs/fragments/448_support_new_sanity_test.yml deleted file mode 100644 index a7faa91..0000000 --- a/changelogs/fragments/448_support_new_sanity_test.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - Support new sanity test for the ansible-core devel branch CI test (https://github.com/ansible-collections/ansible.posix/issues/446). diff --git a/changelogs/fragments/451_firewall_fix_protocol_parameter.yml b/changelogs/fragments/451_firewall_fix_protocol_parameter.yml deleted file mode 100644 index 9dfc6bd..0000000 --- a/changelogs/fragments/451_firewall_fix_protocol_parameter.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - firewall - Fix issue where opening a specific port resulted in opening the whole protocol of the specified port diff --git a/changelogs/fragments/456_sysctl_fix_nonetype.yml b/changelogs/fragments/456_sysctl_fix_nonetype.yml deleted file mode 100644 index 0bcb27f..0000000 --- a/changelogs/fragments/456_sysctl_fix_nonetype.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - "Fix sysctl integration test failing on newer versions of core. Previously NoneType was allowable, now it fails to convert to a str type." diff --git a/galaxy.yml b/galaxy.yml index 5eec30c..1d937fb 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: ansible name: posix -version: 1.5.3 +version: 1.5.4 readme: README.md authors: - Ansible (github.com/ansible) From 8ec2c261bda9672795950864ddc35088e114dd4c Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sun, 14 May 2023 05:19:38 +0000 Subject: [PATCH 084/109] add helper to respawn modules with system python The seboolean, selinux, firewalld, and firewalld_info modules depend on system bindings that are only available for the default system python interpreter. ansible-core is not packaged for the default system python interpreter on RHEL 8 and 9. When automatic interpreter discovery does not occur (e.g. when using implicit localhost [1]), ansible-core will not use the system interpreter to run ansible modules and the aforementioned modules will not work even if the bindings are installed. The RHEL ansible-core maintainers as well as the EPEL ansible and ansible-collection-* package maintainers (inc. me) have gotten multiple bug reports about this. We have been telling people to fix their setup to use the correct Python interpreter. Fortunately, ansible-core 2.11 and above have a module utility that'll respawn modules to use the correct system interpreter. [1] https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html --- plugins/module_utils/_respawn.py | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 plugins/module_utils/_respawn.py diff --git a/plugins/module_utils/_respawn.py b/plugins/module_utils/_respawn.py new file mode 100644 index 0000000..55abaf5 --- /dev/null +++ b/plugins/module_utils/_respawn.py @@ -0,0 +1,45 @@ +# Copyright (c) 2023 Maxwell G +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +""" +Helpers to respawn a module to run using the system interpreter +""" + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +try: + from ansible.module_utils.common import respawn +except ImportError: + HAS_RESPAWN_UTIL = False +else: + HAS_RESPAWN_UTIL = True + + +SYSTEM_PYTHON_INTERPRETERS = ( + "/usr/bin/libexec/platform-python", + "/usr/bin/python3", + "/usr/bin/python2", + "/usr/bin/python", +) + + +def respawn_module(module): + """ + Respawn an ansible module to using the first interpreter in + SYSTEM_PYTHON_INTERPRETERS that contains `module`. + + Args: + module (str): Name of python module to search for + + Returns: + Returns None if the module cannot be respawned. + """ + if respawn.has_respawned(): + return + interpreter = respawn.probe_interpreters_for_module( + SYSTEM_PYTHON_INTERPRETERS, module + ) + if interpreter: + respawn.respawn_module(interpreter) From 63fba50912a2aec9f342ffc03447e7df7ec63b60 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 13 May 2023 18:47:07 +0000 Subject: [PATCH 085/109] respawn seboolean module when selinux is missing --- changelogs/fragments/460-respawn.yaml | 4 ++++ plugins/modules/seboolean.py | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/460-respawn.yaml diff --git a/changelogs/fragments/460-respawn.yaml b/changelogs/fragments/460-respawn.yaml new file mode 100644 index 0000000..cd0b29a --- /dev/null +++ b/changelogs/fragments/460-respawn.yaml @@ -0,0 +1,4 @@ +--- +minor_changes: + - "seboolean - respawn module to use the system python interpreter when the ``selinux`` python module is not available for ``ansible_python_interpreter`` + (https://github.com/ansible-collections/ansible.posix/pull/460)." diff --git a/plugins/modules/seboolean.py b/plugins/modules/seboolean.py index 657b7fa..0d23073 100644 --- a/plugins/modules/seboolean.py +++ b/plugins/modules/seboolean.py @@ -75,6 +75,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.six import binary_type from ansible.module_utils._text import to_bytes, to_text +from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL def get_runtime_status(ignore_selinux_state=False): @@ -281,6 +282,12 @@ def main(): supports_check_mode=True, ) + if not HAVE_SELINUX and not HAVE_SEMANAGE and HAS_RESPAWN_UTIL: + # Only respawn the module if both libraries are missing. + # If only one is available, then usage of the "wrong" (i.e. not the system one) + # python interpreter is likely not the problem. + respawn_module("selinux") + if not HAVE_SELINUX: module.fail_json(msg=missing_required_lib('libselinux-python'), exception=SELINUX_IMP_ERR) From 34a9cf3e4d8cf1181a506618d1c5e2a5807b37d9 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 13 May 2023 18:56:38 +0000 Subject: [PATCH 086/109] respawn selinux module when selinux is missing --- changelogs/fragments/460-respawn.yaml | 2 ++ plugins/modules/selinux.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/changelogs/fragments/460-respawn.yaml b/changelogs/fragments/460-respawn.yaml index cd0b29a..7223b5d 100644 --- a/changelogs/fragments/460-respawn.yaml +++ b/changelogs/fragments/460-respawn.yaml @@ -2,3 +2,5 @@ minor_changes: - "seboolean - respawn module to use the system python interpreter when the ``selinux`` python module is not available for ``ansible_python_interpreter`` (https://github.com/ansible-collections/ansible.posix/pull/460)." + - "selinux - respawn module to use the system python interpreter when the ``selinux`` python module is not available for ``ansible_python_interpreter`` + (https://github.com/ansible-collections/ansible.posix/pull/460)." diff --git a/plugins/modules/selinux.py b/plugins/modules/selinux.py index 14110fe..0609462 100644 --- a/plugins/modules/selinux.py +++ b/plugins/modules/selinux.py @@ -107,6 +107,8 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.process import get_bin_path from ansible.module_utils.facts.utils import get_file_lines +from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL + # getter subroutines def get_config_state(configfile): @@ -236,6 +238,8 @@ def main(): ) if not HAS_SELINUX: + if HAS_RESPAWN_UTIL: + respawn_module("selinux") module.fail_json(msg=missing_required_lib('libselinux-python'), exception=SELINUX_IMP_ERR) # global vars From ad414c87b4ed35ac00c6b9087e03bc6e8f8b771d Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 13 May 2023 19:02:18 +0000 Subject: [PATCH 087/109] respawn firewalld module when selinux is missing --- changelogs/fragments/460-respawn.yaml | 2 ++ plugins/module_utils/firewalld.py | 3 +++ tests/integration/targets/firewalld/tasks/main.yml | 7 ------- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/changelogs/fragments/460-respawn.yaml b/changelogs/fragments/460-respawn.yaml index 7223b5d..00f8028 100644 --- a/changelogs/fragments/460-respawn.yaml +++ b/changelogs/fragments/460-respawn.yaml @@ -4,3 +4,5 @@ minor_changes: (https://github.com/ansible-collections/ansible.posix/pull/460)." - "selinux - respawn module to use the system python interpreter when the ``selinux`` python module is not available for ``ansible_python_interpreter`` (https://github.com/ansible-collections/ansible.posix/pull/460)." + - "firewalld - respawn module to use the system python interpreter when the ``firewall`` python module is not available for ``ansible_python_interpreter`` + (https://github.com/ansible-collections/ansible.posix/pull/460)." diff --git a/plugins/module_utils/firewalld.py b/plugins/module_utils/firewalld.py index 6a76c32..011b140 100644 --- a/plugins/module_utils/firewalld.py +++ b/plugins/module_utils/firewalld.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function from ansible_collections.ansible.posix.plugins.module_utils.version import LooseVersion +from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL from ansible.module_utils.basic import missing_required_lib __metaclass__ = type @@ -314,6 +315,8 @@ class FirewallTransaction(object): installed version (%s) likely too old. Requires firewalld >= 0.2.11" % FW_VERSION) if import_failure: + if HAS_RESPAWN_UTIL: + respawn_module("firewall") module.fail_json( msg=missing_required_lib('firewall') + '. Version 0.2.11 or newer required (0.3.9 or newer for offline operations)' ) diff --git a/tests/integration/targets/firewalld/tasks/main.yml b/tests/integration/targets/firewalld/tasks/main.yml index 17f14c2..5f81c62 100644 --- a/tests/integration/targets/firewalld/tasks/main.yml +++ b/tests/integration/targets/firewalld/tasks/main.yml @@ -10,11 +10,6 @@ state: present # This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6 - - name: Check to make sure the firewalld python module is available. - shell: "{{ansible_python.executable}} -c 'import firewall'" - register: check_output - ignore_errors: true - - name: Enable dbus-broker daemon service: name: dbus-broker @@ -30,7 +25,6 @@ state: started - import_tasks: run_all_tests.yml - when: check_output.rc == 0 - name: Test Offline Operations block: @@ -40,7 +34,6 @@ state: stopped - import_tasks: run_all_tests.yml - when: check_output.rc == 0 when: - ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=') From 85c958ccb8caba8610604a976b268a760d4a50eb Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 13 May 2023 19:51:57 +0000 Subject: [PATCH 088/109] respawn firewalld_info module when selinux is missing --- changelogs/fragments/460-respawn.yaml | 2 ++ plugins/modules/firewalld_info.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/changelogs/fragments/460-respawn.yaml b/changelogs/fragments/460-respawn.yaml index 00f8028..b88763b 100644 --- a/changelogs/fragments/460-respawn.yaml +++ b/changelogs/fragments/460-respawn.yaml @@ -6,3 +6,5 @@ minor_changes: (https://github.com/ansible-collections/ansible.posix/pull/460)." - "firewalld - respawn module to use the system python interpreter when the ``firewall`` python module is not available for ``ansible_python_interpreter`` (https://github.com/ansible-collections/ansible.posix/pull/460)." + - "firewalld_info - respawn module to use the system python interpreter when the ``firewall`` python module is not available for ``ansible_python_interpreter`` + (https://github.com/ansible-collections/ansible.posix/pull/460)." diff --git a/plugins/modules/firewalld_info.py b/plugins/modules/firewalld_info.py index 334518d..8b5c80c 100644 --- a/plugins/modules/firewalld_info.py +++ b/plugins/modules/firewalld_info.py @@ -211,6 +211,7 @@ firewalld_info: from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils._text import to_native +from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL from ansible_collections.ansible.posix.plugins.module_utils.version import StrictVersion @@ -322,6 +323,12 @@ def main(): ) # Exit with failure message if requirements modules are not installed. + if not HAS_DBUS and not HAS_FIREWALLD and HAS_RESPAWN_UTIL: + # Only respawn the module if both libraries are missing. + # If only one is available, then usage of the "wrong" (i.e. not the system one) + # python interpreter is likely not the problem. + respawn_module("firewall") + if not HAS_DBUS: module.fail_json(msg=missing_required_lib('python-dbus')) if not HAS_FIREWALLD: From 4106ec65f9844eaf30fc9f855a4e8fd8c2bfd5df Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 21 May 2023 13:17:13 +0200 Subject: [PATCH 089/109] Replace 'include:' with 'include_tasks:'. 'include:' is removed for ansible-core 2.16. --- changelogs/fragments/466-tests.yml | 2 ++ tests/integration/targets/acl/tasks/main.yml | 2 +- tests/integration/targets/seboolean/tasks/main.yml | 2 +- tests/integration/targets/selinux/tasks/main.yml | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/466-tests.yml diff --git a/changelogs/fragments/466-tests.yml b/changelogs/fragments/466-tests.yml new file mode 100644 index 0000000..3c08961 --- /dev/null +++ b/changelogs/fragments/466-tests.yml @@ -0,0 +1,2 @@ +trivial: + - "Fix integration tests so they work with ansible-core devel / 2.16 (https://github.com/ansible-collections/ansible.posix/pull/466)." diff --git a/tests/integration/targets/acl/tasks/main.yml b/tests/integration/targets/acl/tasks/main.yml index 84af286..264f04a 100644 --- a/tests/integration/targets/acl/tasks/main.yml +++ b/tests/integration/targets/acl/tasks/main.yml @@ -17,7 +17,7 @@ - block: - - include: acl.yml + - include_tasks: acl.yml when: ansible_system == 'Linux' # TODO enable acls mount option on FreeBSD to test it there too always: diff --git a/tests/integration/targets/seboolean/tasks/main.yml b/tests/integration/targets/seboolean/tasks/main.yml index df21691..c8a5ffe 100644 --- a/tests/integration/targets/seboolean/tasks/main.yml +++ b/tests/integration/targets/seboolean/tasks/main.yml @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- include: seboolean.yml +- include_tasks: seboolean.yml when: - ansible_selinux is defined - ansible_selinux != False diff --git a/tests/integration/targets/selinux/tasks/main.yml b/tests/integration/targets/selinux/tasks/main.yml index 41fdca5..a5fed6b 100644 --- a/tests/integration/targets/selinux/tasks/main.yml +++ b/tests/integration/targets/selinux/tasks/main.yml @@ -23,13 +23,13 @@ msg: SELinux is {{ ansible_selinux.status }} when: ansible_selinux is defined and ansible_selinux != False -- include: selinux.yml +- include_tasks: selinux.yml when: - ansible_selinux is defined - ansible_selinux != False - ansible_selinux.status == 'enabled' -- include: selogin.yml +- include_tasks: selogin.yml when: - ansible_selinux is defined - ansible_selinux != False From ab1bc5df9f947f78d2a0dc608218967148af0486 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Wed, 24 May 2023 19:41:58 +0100 Subject: [PATCH 090/109] remove FreeBSD 12.2 targets --- .azure-pipelines/azure-pipelines.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 7b352f5..85fb8e5 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -293,8 +293,6 @@ stages: test: rhel/7.9 - name: RHEL 8.4 test: rhel/8.4 - - name: FreeBSD 12.2 - test: freebsd/12.2 - name: FreeBSD 13.0 test: freebsd/13.0 - stage: Remote_2_11 @@ -311,8 +309,6 @@ stages: test: rhel/7.9 - name: RHEL 8.3 test: rhel/8.3 - - name: FreeBSD 12.2 - test: freebsd/12.2 - stage: Remote_2_10 displayName: Remote 2.10 dependsOn: [] From 622aef2aad34b4d28dfb08f27a18cdd5cbd87f3a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 21 May 2023 13:13:51 +0200 Subject: [PATCH 091/109] Switch to Ansible Galaxy compatible requirements files for tests. --- changelogs/fragments/test-reqs.yml | 2 ++ tests/integration/requirements.yml | 3 +++ tests/requirements.yml | 4 ---- tests/unit/requirements.yml | 3 +++ 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/test-reqs.yml create mode 100644 tests/integration/requirements.yml delete mode 100644 tests/requirements.yml create mode 100644 tests/unit/requirements.yml diff --git a/changelogs/fragments/test-reqs.yml b/changelogs/fragments/test-reqs.yml new file mode 100644 index 0000000..11598f7 --- /dev/null +++ b/changelogs/fragments/test-reqs.yml @@ -0,0 +1,2 @@ +trivial: + - "Move Galaxy test requirements from old transitional format in tests/requirements.yml to standard Ansible Galaxy requirements files in tests/integration/requirements.yml and tests/unit/requirements.yml." diff --git a/tests/integration/requirements.yml b/tests/integration/requirements.yml new file mode 100644 index 0000000..08e2610 --- /dev/null +++ b/tests/integration/requirements.yml @@ -0,0 +1,3 @@ +--- +collections: +- community.general diff --git a/tests/requirements.yml b/tests/requirements.yml deleted file mode 100644 index 47e12a9..0000000 --- a/tests/requirements.yml +++ /dev/null @@ -1,4 +0,0 @@ -integration_tests_dependencies: -- community.general -unit_tests_dependencies: -- community.general diff --git a/tests/unit/requirements.yml b/tests/unit/requirements.yml new file mode 100644 index 0000000..08e2610 --- /dev/null +++ b/tests/unit/requirements.yml @@ -0,0 +1,3 @@ +--- +collections: +- community.general From 806ab9ef9d8ef7cda742bd6b98b51dbff94a24d4 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 29 Jun 2023 10:57:49 -0500 Subject: [PATCH 092/109] Update azure-pipelines for new RHEL versions Change to the CI system annnounced in the following required this change: https://github.com/ansible-collections/news-for-maintainers/issues/47 Signed-off-by: Adam Miller --- .azure-pipelines/azure-pipelines.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 85fb8e5..c0c3b43 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -213,10 +213,10 @@ stages: test: macos/13.2 - name: RHEL 7.9 test: rhel/7.9 - - name: RHEL 8.7 - test: rhel/8.7 - - name: RHEL 9.1 - test: rhel/9.1 + - name: RHEL 8.8 + test: rhel/8.8 + - name: RHEL 9.2 + test: rhel/9.2 - name: FreeBSD 12.4 test: freebsd/12.4 - name: FreeBSD 13.1 @@ -233,10 +233,10 @@ stages: test: macos/13.2 - name: RHEL 7.9 test: rhel/7.9 - - name: RHEL 8.7 - test: rhel/8.7 - - name: RHEL 9.1 - test: rhel/9.1 + - name: RHEL 8.8 + test: rhel/8.8 + - name: RHEL 9.2 + test: rhel/9.2 - name: FreeBSD 12.4 test: freebsd/12.4 - name: FreeBSD 13.1 From 4f1e6b4a6dd7e8138273661d626a0bc7be0facb2 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Tue, 27 Jun 2023 16:04:09 +0900 Subject: [PATCH 093/109] Drop Python3.9 and update versions of RHEL,Fedora and FreeBSD for ansible-core:devel * Addresses issue #476 * Drop Python3.9 * Replace Fedora 37 with 38 * Replace FreeBSD13.1 with 13.2 * Replace RHEL 8.7 with 8.8 * Replace RHEL 9.1 with 9.2 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 16 ++++++++-------- changelogs/fragments/477_ci_update.yml | 3 +++ tests/utils/shippable/shippable.sh | 4 +--- 3 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/477_ci_update.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 85fb8e5..9fe3cb4 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -53,8 +53,8 @@ stages: targets: - name: CentOS 7 test: centos7 - - name: Fedora 37 - test: fedora37 + - name: Fedora 38 + test: fedora38 - name: openSUSE 15 py3 test: opensuse15 - name: Ubuntu 20.04 @@ -213,14 +213,14 @@ stages: test: macos/13.2 - name: RHEL 7.9 test: rhel/7.9 - - name: RHEL 8.7 - test: rhel/8.7 - - name: RHEL 9.1 - test: rhel/9.1 + - name: RHEL 8.8 + test: rhel/8.8 + - name: RHEL 9.2 + test: rhel/9.2 - name: FreeBSD 12.4 test: freebsd/12.4 - - name: FreeBSD 13.1 - test: freebsd/13.1 + - name: FreeBSD 13.2 + test: freebsd/13.2 - stage: Remote_2_15 displayName: Remote 2.15 dependsOn: [] diff --git a/changelogs/fragments/477_ci_update.yml b/changelogs/fragments/477_ci_update.yml new file mode 100644 index 0000000..9429030 --- /dev/null +++ b/changelogs/fragments/477_ci_update.yml @@ -0,0 +1,3 @@ +--- +trivial: + - "Drop Python3.9 and update versions of RHEL,Fedora and FreeBSD for ansible-core:devel test(https://github.com/ansible-collections/ansible.posix/issues/476)." diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index 1a8be27..1cff6d8 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -145,9 +145,7 @@ function cleanup fi if [ "${process_coverage}" ]; then - # use python 3.9 for coverage to avoid running out of memory during coverage xml processing - # only use it for coverage to avoid the additional overhead of setting up a virtual environment for a potential no-op job - virtualenv --python /usr/bin/python3.9 ~/ansible-venv + python3 -m venv ~/ansible-venv set +ux . ~/ansible-venv/bin/activate set -ux From 7062be892e33c4851c0f34cebb0f59c2a1c38259 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 6 Jul 2023 10:19:58 -0500 Subject: [PATCH 094/109] only for devel Signed-off-by: Adam Miller --- .azure-pipelines/azure-pipelines.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index c0c3b43..9bc8868 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -233,10 +233,10 @@ stages: test: macos/13.2 - name: RHEL 7.9 test: rhel/7.9 - - name: RHEL 8.8 - test: rhel/8.8 - - name: RHEL 9.2 - test: rhel/9.2 + - name: RHEL 8.7 + test: rhel/8.7 + - name: RHEL 9.1 + test: rhel/9.1 - name: FreeBSD 12.4 test: freebsd/12.4 - name: FreeBSD 13.1 From 2cde4cdb26caf2ffbede29933a64a70d6320f59e Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Tue, 1 Aug 2023 19:53:49 +0900 Subject: [PATCH 095/109] Drop OSX10.11 and FreeBSD12.4 from CI - Fixes #476 - Fixes #486 - Drop OSX10.11 from ansible:2.9 and ansible-core:2.10 - Drop FreeBSD12.4 from ansible-core:devel Signed-off-by: Hideki Saito test --- .azure-pipelines/azure-pipelines.yml | 8 +------- changelogs/fragments/487_ci_update.yml | 3 +++ 2 files changed, 4 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/487_ci_update.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 9fe3cb4..06db55e 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -36,7 +36,7 @@ variables: resources: containers: - container: default - image: quay.io/ansible/azure-pipelines-test-container:3.0.0 + image: quay.io/ansible/azure-pipelines-test-container:4.0.1 pool: Standard @@ -217,8 +217,6 @@ stages: test: rhel/8.8 - name: RHEL 9.2 test: rhel/9.2 - - name: FreeBSD 12.4 - test: freebsd/12.4 - name: FreeBSD 13.2 test: freebsd/13.2 - stage: Remote_2_15 @@ -317,8 +315,6 @@ stages: parameters: testFormat: 2.10/{0}/1 targets: - - name: OS X 10.11 - test: osx/10.11 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.2 @@ -331,8 +327,6 @@ stages: parameters: testFormat: 2.9/{0}/1 targets: - - name: OS X 10.11 - test: osx/10.11 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.1 diff --git a/changelogs/fragments/487_ci_update.yml b/changelogs/fragments/487_ci_update.yml new file mode 100644 index 0000000..b68da22 --- /dev/null +++ b/changelogs/fragments/487_ci_update.yml @@ -0,0 +1,3 @@ +--- +trivial: + - "Drop FreeBSD12.4 from CI for ansible-core:devel(https://github.com/ansible-collections/ansible.posix/issues/486)." From 7dd5087e7bff297b4f08ec6e3713c7618dd44c07 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Thu, 16 Nov 2023 10:33:59 +0900 Subject: [PATCH 096/109] Refactoring remote and docker CI tests. * Removed tests for Ansible Core 2.10 and 2.11 fromn remote and container targets * Modoifed remote and container test target OS * Fixed #506 Signed-off-by: Hideki Saito --- .azure-pipelines/azure-pipelines.yml | 132 ++++++------------------- changelogs/fragments/508_ci_update.yml | 3 + 2 files changed, 33 insertions(+), 102 deletions(-) create mode 100644 changelogs/fragments/508_ci_update.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 06db55e..a0d8068 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -51,16 +51,29 @@ stages: parameters: testFormat: devel/linux/{0}/1 targets: - - name: CentOS 7 - test: centos7 - name: Fedora 38 test: fedora38 - - name: openSUSE 15 py3 - test: opensuse15 - name: Ubuntu 20.04 test: ubuntu2004 - name: Ubuntu 22.04 test: ubuntu2204 + - stage: Docker_2_16 + displayName: Docker 2.16 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.16/linux/{0}/1 + targets: + - name: CentOS 7 + test: centos7 + - name: Fedora 38 + test: fedora38 + - name: Ubuntu 20.04 + test: ubuntu2004 + - name: Ubuntu 22.04 + test: ubuntu2204 + - stage: Docker_2_15 displayName: Docker 2.15 dependsOn: [] @@ -141,44 +154,6 @@ stages: test: ubuntu1804 - name: Ubuntu 20.04 test: ubuntu2004 - - stage: Docker_2_11 - displayName: Docker 2.11 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.11/linux/{0}/1 - targets: - - name: CentOS 6 - test: centos6 - - name: CentOS 7 - test: centos7 - - name: openSUSE 15 py2 - test: opensuse15py2 - - name: openSUSE 15 py3 - test: opensuse15 - - name: Ubuntu 18.04 - test: ubuntu1804 - - stage: Docker_2_10 - displayName: Docker 2.10 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.10/linux/{0}/1 - targets: - - name: CentOS 6 - test: centos6 - - name: CentOS 7 - test: centos7 - - name: openSUSE 15 py2 - test: opensuse15py2 - - name: openSUSE 15 py3 - test: opensuse15 - - name: Ubuntu 16.04 - test: ubuntu1604 - - name: Ubuntu 18.04 - test: ubuntu1804 - stage: Docker_2_9 displayName: Docker 2.9 dependsOn: [] @@ -209,16 +184,21 @@ stages: parameters: testFormat: devel/{0}/1 targets: - - name: MacOS 13.2 - test: macos/13.2 - - name: RHEL 7.9 - test: rhel/7.9 + - name: RHEL 9.3 + test: rhel/9.3 + - stage: Remote_2_16 + displayName: Remote 2.16 + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + testFormat: 2.16/{0}/1 + targets: - name: RHEL 8.8 test: rhel/8.8 - name: RHEL 9.2 test: rhel/9.2 - - name: FreeBSD 13.2 - test: freebsd/13.2 + - stage: Remote_2_15 displayName: Remote 2.15 dependsOn: [] @@ -227,18 +207,12 @@ stages: parameters: testFormat: 2.15/{0}/1 targets: - - name: MacOS 13.2 - test: macos/13.2 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.7 test: rhel/8.7 - name: RHEL 9.1 test: rhel/9.1 - - name: FreeBSD 12.4 - test: freebsd/12.4 - - name: FreeBSD 13.1 - test: freebsd/13.1 - stage: Remote_2_14 displayName: Remote 2.14 dependsOn: [] @@ -247,18 +221,10 @@ stages: parameters: testFormat: 2.14/{0}/1 targets: - - name: MacOS 12.0 - test: macos/12.0 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.6 test: rhel/8.6 - - name: RHEL 9.0 - test: rhel/9.0 - - name: FreeBSD 12.3 - test: freebsd/12.3 - - name: FreeBSD 13.1 - test: freebsd/13.1 - stage: Remote_2_13 displayName: Remote 2.13 dependsOn: [] @@ -267,16 +233,10 @@ stages: parameters: testFormat: 2.13/{0}/1 targets: - - name: MacOS 12.0 - test: macos/12.0 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.5 test: rhel/8.5 - - name: FreeBSD 12.3 - test: freebsd/12.3 - - name: FreeBSD 13.0 - test: freebsd/13.0 - stage: Remote_2_12 displayName: Remote 2.12 dependsOn: [] @@ -285,40 +245,10 @@ stages: parameters: testFormat: 2.12/{0}/1 targets: - - name: MacOS 11.1 - test: macos/11.1 - name: RHEL 7.9 test: rhel/7.9 - name: RHEL 8.4 test: rhel/8.4 - - name: FreeBSD 13.0 - test: freebsd/13.0 - - stage: Remote_2_11 - displayName: Remote 2.11 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.11/{0}/1 - targets: - - name: MacOS 11.1 - test: macos/11.1 - - name: RHEL 7.9 - test: rhel/7.9 - - name: RHEL 8.3 - test: rhel/8.3 - - stage: Remote_2_10 - displayName: Remote 2.10 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.10/{0}/1 - targets: - - name: RHEL 7.9 - test: rhel/7.9 - - name: RHEL 8.2 - test: rhel/8.2 - stage: Remote_2_9 displayName: Remote 2.9 dependsOn: [] @@ -339,10 +269,6 @@ stages: dependsOn: - Remote_2_9 - Docker_2_9 - - Remote_2_10 - - Docker_2_10 - - Remote_2_11 - - Docker_2_11 - Remote_2_12 - Docker_2_12 - Remote_2_13 @@ -351,6 +277,8 @@ stages: - Docker_2_14 - Remote_2_15 - Docker_2_15 + - Remote_2_16 + - Docker_2_16 - Remote_devel - Docker_devel jobs: diff --git a/changelogs/fragments/508_ci_update.yml b/changelogs/fragments/508_ci_update.yml new file mode 100644 index 0000000..a4af511 --- /dev/null +++ b/changelogs/fragments/508_ci_update.yml @@ -0,0 +1,3 @@ +--- +trivial: + - "Refactoring remote CI targets." From 5cae7aa946bba8c55456189846e775c1df14fdbb Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 22 Nov 2023 17:07:11 +0900 Subject: [PATCH 097/109] Replace Fedora 38 with 39 for devel branch container test --- .azure-pipelines/azure-pipelines.yml | 4 ++-- changelogs/fragments/510_ci_update.yml | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/510_ci_update.yml diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index a0d8068..e66ea57 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -51,8 +51,8 @@ stages: parameters: testFormat: devel/linux/{0}/1 targets: - - name: Fedora 38 - test: fedora38 + - name: Fedora 39 + test: fedora39 - name: Ubuntu 20.04 test: ubuntu2004 - name: Ubuntu 22.04 diff --git a/changelogs/fragments/510_ci_update.yml b/changelogs/fragments/510_ci_update.yml new file mode 100644 index 0000000..ada69ef --- /dev/null +++ b/changelogs/fragments/510_ci_update.yml @@ -0,0 +1,3 @@ +--- +trivial: + - "Replace Fedora 38 with 39 for container test(https://github.com/ansible-collections/ansible.posix/issues/509)." From 695fa213b3f050bc5ab4a0faee983c1cfb1b2e36 Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Wed, 26 Jul 2023 03:34:27 +0000 Subject: [PATCH 098/109] firewalld: make offline do something --- .../fragments/484-firewalld-offline.yml | 2 + plugins/modules/firewalld.py | 39 ++++++++++++++----- .../firewalld/tasks/service_test_cases.yml | 8 ++++ 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/484-firewalld-offline.yml diff --git a/changelogs/fragments/484-firewalld-offline.yml b/changelogs/fragments/484-firewalld-offline.yml new file mode 100644 index 0000000..c17d4ea --- /dev/null +++ b/changelogs/fragments/484-firewalld-offline.yml @@ -0,0 +1,2 @@ +minor_changes: + - firewalld - added offline flag implementation (https://github.com/ansible-collections/ansible.posix/pull/484) diff --git a/plugins/modules/firewalld.py b/plugins/modules/firewalld.py index cf55e1c..146990f 100644 --- a/plugins/modules/firewalld.py +++ b/plugins/modules/firewalld.py @@ -84,13 +84,15 @@ options: type: str permanent: description: - - Should this configuration be in the running firewalld configuration or persist across reboots. + - Whether to apply this change to the permanent firewalld configuration. - As of Ansible 2.3, permanent operations can operate on firewalld configs when it is not running (requires firewalld >= 0.3.9). - - Note that if this is C(false), immediate is assumed C(true). + - Note that if this is C(false), I(immediate) defaults to C(true). type: bool + default: false immediate: description: - - Should this configuration be applied immediately, if set as permanent. + - Whether to apply this change to the runtime firewalld configuration. + - Defaults to C(true) if I(permanent=false). type: bool default: false state: @@ -112,8 +114,9 @@ options: type: str offline: description: - - Whether to run this module even when firewalld is offline. + - Ignores I(immediate) if I(permanent=true) and firewalld is not running. type: bool + default: false target: description: - firewalld Zone target @@ -142,6 +145,14 @@ author: ''' EXAMPLES = r''' +- name: permanently enable https service, also enable it immediately if possible + ansible.posix.firewalld: + service: https + state: enabled + permanent: true + immediate: true + offline: true + - name: permit traffic in default zone for https service ansible.posix.firewalld: service: https @@ -806,12 +817,12 @@ def main(): zone=dict(type='str'), immediate=dict(type='bool', default=False), source=dict(type='str'), - permanent=dict(type='bool'), + permanent=dict(type='bool', default=False), state=dict(type='str', required=True, choices=['absent', 'disabled', 'enabled', 'present']), timeout=dict(type='int', default=0), interface=dict(type='str'), masquerade=dict(type='str'), - offline=dict(type='bool'), + offline=dict(type='bool', default=False), target=dict(type='str', choices=['default', 'ACCEPT', 'DROP', '%%REJECT%%']), ), supports_check_mode=True, @@ -832,19 +843,29 @@ def main(): timeout = module.params['timeout'] interface = module.params['interface'] masquerade = module.params['masquerade'] + offline = module.params['offline'] # Sanity checks FirewallTransaction.sanity_check(module) - # If neither permanent or immediate is provided, assume immediate (as - # written in the module's docs) + # `offline`, `immediate`, and `permanent` have a weird twisty relationship. + if offline: + # specifying offline without permanent makes no sense + if not permanent: + module.fail_json(msg='offline cannot be enabled unless permanent changes are allowed') + + # offline overrides immediate to false if firewalld is offline + if fw_offline: + immediate = False + + # immediate defaults to true if permanent is not enabled if not permanent and not immediate: immediate = True - # Verify required params are provided if immediate and fw_offline: module.fail_json(msg='firewall is not currently running, unable to perform immediate actions without a running firewall daemon') + # Verify required params are provided changed = False msgs = [] icmp_block = module.params['icmp_block'] diff --git a/tests/integration/targets/firewalld/tasks/service_test_cases.yml b/tests/integration/targets/firewalld/tasks/service_test_cases.yml index 3c95d81..1998a82 100644 --- a/tests/integration/targets/firewalld/tasks/service_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/service_test_cases.yml @@ -20,6 +20,8 @@ firewalld: service: https permanent: true + immediate: true + offline: true state: enabled register: result @@ -32,6 +34,8 @@ firewalld: service: https permanent: true + immediate: true + offline: true state: enabled register: result @@ -44,6 +48,8 @@ firewalld: service: https permanent: true + immediate: true + offline: true state: disabled register: result @@ -56,6 +62,8 @@ firewalld: service: https permanent: true + immediate: true + offline: true state: disabled register: result From 748bad22adf305d9802ecc36b468ca0db3434c61 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 30 Nov 2023 16:25:07 -0600 Subject: [PATCH 099/109] fix sanity tests for core 2.16 (#514) Signed-off-by: Adam Miller --- tests/sanity/ignore-2.16.txt | 2 ++ tests/unit/mock/loader.py | 2 +- tests/utils/shippable/timing.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index 4f0aa92..d196952 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -1,5 +1,7 @@ +plugins/modules/synchronize.py pylint:disallowed-name plugins/modules/synchronize.py use-argspec-type-path plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc plugins/modules/synchronize.py validate-modules:undocumented-parameter +tests/utils/shippable/timing.py shebang diff --git a/tests/unit/mock/loader.py b/tests/unit/mock/loader.py index e5dff78..edeac45 100644 --- a/tests/unit/mock/loader.py +++ b/tests/unit/mock/loader.py @@ -30,7 +30,7 @@ class DictDataLoader(DataLoader): def __init__(self, file_mapping=None): file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict + assert isinstance(file_mapping, dict) super(DictDataLoader, self).__init__() diff --git a/tests/utils/shippable/timing.py b/tests/utils/shippable/timing.py index fb53827..1bfd310 100755 --- a/tests/utils/shippable/timing.py +++ b/tests/utils/shippable/timing.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.7 +#!/usr/bin/env python3 from __future__ import (absolute_import, division, print_function) __metaclass__ = type From c394f6778d27881eee402c31270692e096978c7b Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 30 Nov 2023 16:23:06 -0600 Subject: [PATCH 100/109] remove old pipelines, run sanity in pipelines because we're dropping zuul Signed-off-by: Adam Miller --- .azure-pipelines/azure-pipelines.yml | 158 ++++++++++-------- tests/sanity/ignore-2.10.txt | 8 - tests/sanity/ignore-2.11.txt | 8 - tests/sanity/ignore-2.13.txt | 8 - .../{ignore-2.12.txt => ignore-2.17.txt} | 1 - tests/utils/shippable/lint.sh | 14 ++ tests/utils/shippable/sanity.sh | 16 +- tests/utils/shippable/units.sh | 107 +----------- 8 files changed, 116 insertions(+), 204 deletions(-) delete mode 100644 tests/sanity/ignore-2.10.txt delete mode 100644 tests/sanity/ignore-2.11.txt delete mode 100644 tests/sanity/ignore-2.13.txt rename tests/sanity/{ignore-2.12.txt => ignore-2.17.txt} (89%) create mode 100755 tests/utils/shippable/lint.sh diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index e66ea57..e1ba4a0 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -36,12 +36,79 @@ variables: resources: containers: - container: default - image: quay.io/ansible/azure-pipelines-test-container:4.0.1 + image: quay.io/ansible/azure-pipelines-test-container:main pool: Standard stages: + - stage: Sanity_devel + displayName: Ansible devel sanity + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + nameFormat: "{0}" + testFormat: "devel/{0}" + targets: + - name: Sanity + test: sanity + - name: Units + test: units +# - name: Lint +# test: lint + - stage: Sanity_2_16 + displayName: Ansible 2.16 sanity + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + nameFormat: "{0}" + testFormat: "2.16/{0}" + targets: + - name: Sanity + test: sanity + - name: Units + test: units + - stage: Sanity_2_15 + displayName: Ansible 2.15 sanity + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + nameFormat: "{0}" + testFormat: "2.15/{0}" + targets: + - name: Sanity + test: sanity + - name: Units + test: units + - stage: Sanity_2_14 + displayName: Ansible 2.14 sanity + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + nameFormat: "{0}" + testFormat: "2.14/{0}" + targets: + - name: Sanity + test: sanity + - name: Units + test: units + - stage: Sanity_2_9 + displayName: Ansible 2.9 sanity + dependsOn: [] + jobs: + - template: templates/matrix.yml + parameters: + nameFormat: "{0}" + testFormat: "2.9/{0}" + targets: + - name: Sanity + test: sanity + - name: Units + test: units ## Docker - stage: Docker_devel displayName: Docker devel @@ -110,50 +177,6 @@ stages: test: ubuntu2004 - name: Ubuntu 22.04 test: ubuntu2204 - - stage: Docker_2_13 - displayName: Docker 2.13 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.13/linux/{0}/1 - targets: - - name: CentOS 7 - test: centos7 - - name: Fedora 34 - test: fedora34 - - name: Fedora 35 - test: fedora35 - - name: openSUSE 15 py3 - test: opensuse15 - - name: Ubuntu 18.04 - test: ubuntu1804 - - name: Ubuntu 20.04 - test: ubuntu2004 - - stage: Docker_2_12 - displayName: Docker 2.12 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.12/linux/{0}/1 - targets: - - name: CentOS 6 - test: centos6 - - name: CentOS 7 - test: centos7 - - name: Fedora 33 - test: fedora33 - - name: Fedora 34 - test: fedora34 - - name: openSUSE 15 py2 - test: opensuse15py2 - - name: openSUSE 15 py3 - test: opensuse15 - - name: Ubuntu 18.04 - test: ubuntu1804 - - name: Ubuntu 20.04 - test: ubuntu2004 - stage: Docker_2_9 displayName: Docker 2.9 dependsOn: [] @@ -186,6 +209,8 @@ stages: targets: - name: RHEL 9.3 test: rhel/9.3 + - name: FreeBSD 13.2 + test: freebsd/13.2 - stage: Remote_2_16 displayName: Remote 2.16 dependsOn: [] @@ -198,6 +223,8 @@ stages: test: rhel/8.8 - name: RHEL 9.2 test: rhel/9.2 + - name: FreeBSD 13.2 + test: freebsd/13.2 - stage: Remote_2_15 displayName: Remote 2.15 @@ -213,6 +240,10 @@ stages: test: rhel/8.7 - name: RHEL 9.1 test: rhel/9.1 + - name: FreeBSD 13.1 + test: freebsd/13.1 + - name: FreeBSD 12.4 + test: freebsd/12.4 - stage: Remote_2_14 displayName: Remote 2.14 dependsOn: [] @@ -225,30 +256,10 @@ stages: test: rhel/7.9 - name: RHEL 8.6 test: rhel/8.6 - - stage: Remote_2_13 - displayName: Remote 2.13 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.13/{0}/1 - targets: - - name: RHEL 7.9 - test: rhel/7.9 - - name: RHEL 8.5 - test: rhel/8.5 - - stage: Remote_2_12 - displayName: Remote 2.12 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.12/{0}/1 - targets: - - name: RHEL 7.9 - test: rhel/7.9 - - name: RHEL 8.4 - test: rhel/8.4 + - name: FreeBSD 13.1 + test: freebsd/13.1 + - name: FreeBSD 12.4 + test: freebsd/12.4 - stage: Remote_2_9 displayName: Remote 2.9 dependsOn: [] @@ -267,18 +278,19 @@ stages: - stage: Summary condition: succeededOrFailed() dependsOn: + - Sanity_2_9 - Remote_2_9 - Docker_2_9 - - Remote_2_12 - - Docker_2_12 - - Remote_2_13 - - Docker_2_13 + - Sanity_2_14 - Remote_2_14 - Docker_2_14 + - Sanity_2_15 - Remote_2_15 - Docker_2_15 + - Sanity_2_16 - Remote_2_16 - Docker_2_16 + - Sanity_devel - Remote_devel - Docker_devel jobs: diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt deleted file mode 100644 index 013403f..0000000 --- a/tests/sanity/ignore-2.10.txt +++ /dev/null @@ -1,8 +0,0 @@ -plugins/modules/synchronize.py pylint:blacklisted-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter -tests/utils/shippable/check_matrix.py replace-urlopen -tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt deleted file mode 100644 index 013403f..0000000 --- a/tests/sanity/ignore-2.11.txt +++ /dev/null @@ -1,8 +0,0 @@ -plugins/modules/synchronize.py pylint:blacklisted-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter -tests/utils/shippable/check_matrix.py replace-urlopen -tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.13.txt b/tests/sanity/ignore-2.13.txt deleted file mode 100644 index 0b6905e..0000000 --- a/tests/sanity/ignore-2.13.txt +++ /dev/null @@ -1,8 +0,0 @@ -plugins/modules/synchronize.py pylint:disallowed-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter -tests/utils/shippable/check_matrix.py replace-urlopen -tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.17.txt similarity index 89% rename from tests/sanity/ignore-2.12.txt rename to tests/sanity/ignore-2.17.txt index 0b6905e..d196952 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.17.txt @@ -4,5 +4,4 @@ plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc plugins/modules/synchronize.py validate-modules:undocumented-parameter -tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang diff --git a/tests/utils/shippable/lint.sh b/tests/utils/shippable/lint.sh new file mode 100755 index 0000000..6ab1187 --- /dev/null +++ b/tests/utils/shippable/lint.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -o pipefail -eux + +echo "${PATH/\~/${HOME}}" +echo "${HOME}" +command -v ansible + +pip install --upgrade --user pip +pip install --upgrade --user ansible-lint + +PATH="${PATH/\~/${HOME}}" ansible-lint \ + --exclude changelogs/ \ + --profile=production diff --git a/tests/utils/shippable/sanity.sh b/tests/utils/shippable/sanity.sh index 82cf8c9..50a74a2 100755 --- a/tests/utils/shippable/sanity.sh +++ b/tests/utils/shippable/sanity.sh @@ -1,7 +1,21 @@ #!/usr/bin/env bash +# Following logic in https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml set -o pipefail -eux +if [ "${BASE_BRANCH:-}" ]; then + base_branch="origin/${BASE_BRANCH}" +else + base_branch="" +fi + +# Run sanity tests inside a Docker container. +# The docker container has all the pinned dependencies that are +# required and all Python versions Ansible supports. + +# See the documentation for the following GitHub action on +# https://github.com/ansible-community/ansible-test-gh-action/blob/main/README.md + # shellcheck disable=SC2086 ansible-test sanity --color -v --junit ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ - --docker + --docker --base-branch "${base_branch}" --allow-disabled diff --git a/tests/utils/shippable/units.sh b/tests/utils/shippable/units.sh index e2ff963..bcf7a77 100755 --- a/tests/utils/shippable/units.sh +++ b/tests/utils/shippable/units.sh @@ -2,109 +2,6 @@ set -o pipefail -eux -declare -a args -IFS='/:' read -ra args <<< "$1" - -version="${args[1]}" -group="${args[2]}" - -if [[ "${COVERAGE:-}" == "--coverage" ]]; then - timeout=90 -else - timeout=30 -fi - -group1=() -group2=() -group3=() - -# create three groups by putting network tests into separate groups -# add or remove network platforms as needed to balance the groups - -networks2=( - aireos - apconos - aruba - asa - avi - check_point - cloudengine - cloudvision - cnos - cumulus - dellos10 - dellos6 - dellos9 - edgeos - edgeswitch - enos - eos - eric_eccli - exos - f5 - fortimanager - frr - ftd - icx - ingate - ios - iosxr - ironware - itential - junos - netact - netscaler - netvisor - nos - nso - nuage - nxos - onyx - opx - ovs - radware - routeros - slxos - voss - vyos -) - -networks3=( - fortios -) - -for network in "${networks2[@]}"; do - test_path="test/units/modules/network/${network}/" - - if [ -d "${test_path}" ]; then - group1+=(--exclude "${test_path}") - group2+=("${test_path}") - fi -done - -for network in "${networks3[@]}"; do - test_path="test/units/modules/network/${network}/" - - if [ -d "${test_path}" ]; then - group1+=(--exclude "${test_path}") - group3+=("${test_path}") - fi -done - -case "${group}" in - 1) options=("${group1[@]:+${group1[@]}}") ;; - 2) options=("${group2[@]:+${group2[@]}}") ;; - 3) options=("${group3[@]:+${group3[@]}}") ;; -esac - -if [ ${#options[@]} -eq 0 ] && [ "${group}" -gt 1 ]; then - # allow collection migration unit tests for groups other than 1 to "pass" without updating shippable.yml or this script during migration - echo "No unit tests found for group ${group}." - exit -fi - -ansible-test env --timeout "${timeout}" --color -v - # shellcheck disable=SC2086 -ansible-test units --color -v --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ - "${options[@]:+${options[@]}}" \ +ansible-test units --color -v --docker default ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} + From a85f736f6a7ec60d8b31bea3d5af27c092d31a40 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 30 Nov 2023 23:23:16 -0600 Subject: [PATCH 101/109] refactor to comply with current ansible-lint and sanity guidelines Signed-off-by: Adam Miller --- .azure-pipelines/azure-pipelines.yml | 72 +- .github/BOTMETA.yml | 1 + README.md | 20 +- changelogs/fragments/dropping-ansible29.yml | 2 + codecov.yml | 1 + galaxy.yml | 1 + meta/runtime.yml | 4 +- plugins/action/synchronize.py | 4 +- plugins/modules/synchronize.py | 64 +- shippable.yml | 13 +- tests/integration/requirements.yml | 2 +- tests/integration/targets/acl/tasks/acl.yml | 138 ++- tests/integration/targets/acl/tasks/main.yml | 30 +- tests/integration/targets/at/meta/main.yml | 1 + tests/integration/targets/at/tasks/main.yml | 66 +- .../targets/authorized_key/defaults/main.yml | 31 +- .../targets/authorized_key/meta/main.yml | 1 + .../authorized_key/tasks/check_mode.yml | 19 +- .../targets/authorized_key/tasks/comments.yml | 20 +- .../targets/authorized_key/tasks/main.yml | 11 +- .../authorized_key/tasks/multiple_keys.yml | 89 +- .../authorized_key/tasks/setup_steps.yml | 48 +- .../targets/authorized_key/tasks/ssh_dss.yml | 205 ++-- .../targets/firewalld/meta/main.yml | 1 + .../tasks/icmp_block_inversion_test_cases.yml | 265 ++--- .../firewalld/tasks/interface_test_cases.yml | 133 +-- .../targets/firewalld/tasks/main.yml | 34 +- .../firewalld/tasks/masquerade_test_cases.yml | 265 ++--- .../tasks/port_forward_test_cases.yml | 41 +- .../firewalld/tasks/port_test_cases.yml | 85 +- .../firewalld/tasks/protocol_test_cases.yml | 41 +- .../targets/firewalld/tasks/run_all_tests.yml | 34 +- .../firewalld/tasks/service_test_cases.yml | 41 +- .../firewalld/tasks/source_test_cases.yml | 64 +- .../tasks/zone_target_test_cases.yml | 105 +- .../firewalld/tasks/zone_test_cases.yml | 49 +- .../targets/firewalld_info/tasks/main.yml | 43 +- .../tasks/run_tests_in_started.yml | 17 +- .../tasks/run_tests_in_stopped.yml | 21 +- .../integration/targets/mount/tasks/main.yml | 1030 +++++++++-------- .../integration/targets/patch/tasks/main.yml | 169 +-- .../targets/seboolean/tasks/main.yml | 6 +- .../targets/seboolean/tasks/seboolean.yml | 77 +- .../targets/selinux/tasks/main.yml | 21 +- .../targets/selinux/tasks/selinux.yml | 230 ++-- .../targets/selinux/tasks/selogin.yml | 89 +- .../targets/setup_pkg_mgr/tasks/main.yml | 10 +- .../targets/synchronize/meta/main.yml | 1 + .../targets/synchronize/tasks/main.yml | 564 ++++----- .../integration/targets/sysctl/meta/main.yml | 1 + .../integration/targets/sysctl/tasks/main.yml | 214 ++-- tests/sanity/ignore-2.14.txt | 6 - tests/sanity/ignore-2.15.txt | 6 - tests/sanity/ignore-2.16.txt | 6 - tests/sanity/ignore-2.17.txt | 6 - tests/sanity/ignore-2.9.txt | 8 - .../fixtures/synchronize/basic/meta.yaml | 27 +- .../synchronize/basic_become/meta.yaml | 65 +- .../synchronize/basic_become_cli/meta.yaml | 65 +- .../synchronize/basic_vagrant/meta.yaml | 47 +- .../basic_vagrant_become_cli/meta.yaml | 51 +- .../synchronize/basic_vagrant_sudo/meta.yaml | 47 +- .../basic_with_private_key/meta.yaml | 37 +- .../synchronize/delegate_remote/meta.yaml | 39 +- .../meta.yaml | 43 +- .../synchronize/delegate_remote_su/meta.yaml | 53 +- .../meta.yaml | 45 +- tests/unit/requirements.yml | 2 +- 68 files changed, 2640 insertions(+), 2407 deletions(-) create mode 100644 changelogs/fragments/dropping-ansible29.yml delete mode 100644 tests/sanity/ignore-2.9.txt diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index e1ba4a0..d02f9de 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -1,3 +1,4 @@ +--- trigger: batch: true branches: @@ -13,7 +14,7 @@ pr: - stable-* schedules: - - cron: 0 9 * * * + - cron: "0 9 * * *" displayName: Nightly always: true branches: @@ -41,7 +42,6 @@ resources: pool: Standard stages: - - stage: Sanity_devel displayName: Ansible devel sanity dependsOn: [] @@ -49,14 +49,14 @@ stages: - template: templates/matrix.yml parameters: nameFormat: "{0}" - testFormat: "devel/{0}" + testFormat: devel/{0} targets: - name: Sanity test: sanity - name: Units test: units -# - name: Lint -# test: lint + - name: Lint + test: lint - stage: Sanity_2_16 displayName: Ansible 2.16 sanity dependsOn: [] @@ -64,12 +64,14 @@ stages: - template: templates/matrix.yml parameters: nameFormat: "{0}" - testFormat: "2.16/{0}" + testFormat: 2.16/{0} targets: - name: Sanity test: sanity - name: Units test: units + - name: Lint + test: lint - stage: Sanity_2_15 displayName: Ansible 2.15 sanity dependsOn: [] @@ -77,7 +79,7 @@ stages: - template: templates/matrix.yml parameters: nameFormat: "{0}" - testFormat: "2.15/{0}" + testFormat: 2.15/{0} targets: - name: Sanity test: sanity @@ -90,26 +92,13 @@ stages: - template: templates/matrix.yml parameters: nameFormat: "{0}" - testFormat: "2.14/{0}" + testFormat: 2.14/{0} targets: - name: Sanity test: sanity - name: Units test: units - - stage: Sanity_2_9 - displayName: Ansible 2.9 sanity - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - nameFormat: "{0}" - testFormat: "2.9/{0}" - targets: - - name: Sanity - test: sanity - - name: Units - test: units -## Docker + ## Docker - stage: Docker_devel displayName: Docker devel dependsOn: [] @@ -177,28 +166,8 @@ stages: test: ubuntu2004 - name: Ubuntu 22.04 test: ubuntu2204 - - stage: Docker_2_9 - displayName: Docker 2.9 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.9/linux/{0}/1 - targets: - - name: CentOS 6 - test: centos6 - - name: CentOS 7 - test: centos7 - - name: openSUSE 15 py2 - test: opensuse15py2 - - name: openSUSE 15 py3 - test: opensuse15 - - name: Ubuntu 16.04 - test: ubuntu1604 - - name: Ubuntu 18.04 - test: ubuntu1804 -## Remote + ## Remote - stage: Remote_devel displayName: Remote devel dependsOn: [] @@ -260,27 +229,12 @@ stages: test: freebsd/13.1 - name: FreeBSD 12.4 test: freebsd/12.4 - - stage: Remote_2_9 - displayName: Remote 2.9 - dependsOn: [] - jobs: - - template: templates/matrix.yml - parameters: - testFormat: 2.9/{0}/1 - targets: - - name: RHEL 7.9 - test: rhel/7.9 - - name: RHEL 8.1 - test: rhel/8.1 -## Finally + ## Finally - stage: Summary condition: succeededOrFailed() dependsOn: - - Sanity_2_9 - - Remote_2_9 - - Docker_2_9 - Sanity_2_14 - Remote_2_14 - Docker_2_14 diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 62b9194..60ae92a 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -1,3 +1,4 @@ +--- automerge: false files: $module_utils/mount.py: diff --git a/README.md b/README.md index b0cd705..3683489 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,7 @@ An Ansible Collection of modules and plugins that target POSIX UNIX/Linux and de ## Ansible version compatibility -This collection has been tested against following Ansible versions: **>=2.9**. - -For collections that support Ansible 2.9, please ensure you update your `network_os` to use the -fully qualified collection name (for example, `cisco.ios.ios`). -Plugins and modules within a collection may be tested with only specific Ansible versions. -A collection may contain metadata that identifies these versions. -PEP440 is the schema used to describe the versions of Ansible. +This collection has been tested against following Ansible versions: **>=2.14**. ## Included content @@ -63,8 +57,6 @@ collections: See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details. -**NOTE**: For Ansible 2.9, you may not see deprecation warnings when you run your playbooks with this collection. Use this documentation to track when a module is deprecated. - ## Contributing to this collection @@ -91,12 +83,10 @@ None -- ansible-core 2.14 (devel) -- ansible-core 2.13 (stable) -- ansible-core 2.12 (stable) -- ansible-core 2.11 (stable) -- ansible-base 2.10 (stable) -- ansible 2.9 (stable) +- ansible-core 2.17 (devel) +- ansible-core 2.16 (stable) +- ansible-core 2.15 (stable) +- ansible-core 2.14 (stable) ## Roadmap diff --git a/changelogs/fragments/dropping-ansible29.yml b/changelogs/fragments/dropping-ansible29.yml new file mode 100644 index 0000000..78cd428 --- /dev/null +++ b/changelogs/fragments/dropping-ansible29.yml @@ -0,0 +1,2 @@ +major_changes: + - "Dropping support for Ansible 2.9, ansible-core 2.14 will be minimum required version for this release" diff --git a/codecov.yml b/codecov.yml index 69cb760..6cfc360 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1 +1,2 @@ +--- comment: false diff --git a/galaxy.yml b/galaxy.yml index 1d937fb..6b7009b 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,3 +1,4 @@ +--- namespace: ansible name: posix version: 1.5.4 diff --git a/meta/runtime.yml b/meta/runtime.yml index f43de48..a96714c 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,8 +1,8 @@ --- -requires_ansible: '>=2.9' +requires_ansible: ">=2.14.0" plugin_routing: callback: skippy: deprecation: - removal_date: '2022-06-01' + removal_date: "2022-06-01" warning_text: See the plugin documentation for more details diff --git a/plugins/action/synchronize.py b/plugins/action/synchronize.py index c70db5f..dd780b9 100644 --- a/plugins/action/synchronize.py +++ b/plugins/action/synchronize.py @@ -177,7 +177,7 @@ class ActionModule(ActionBase): # Store remote connection type self._remote_transport = self._connection.transport - use_ssh_args = _tmp_args.pop('use_ssh_args', None) + use_ssh_args = _tmp_args.pop('use_ssh_args', False) if use_ssh_args and self._connection.transport == 'ssh': ssh_args = [ @@ -185,7 +185,7 @@ class ActionModule(ActionBase): self._connection.get_option('ssh_common_args'), self._connection.get_option('ssh_extra_args'), ] - _tmp_args['ssh_args'] = ' '.join([a for a in ssh_args if a]) + _tmp_args['_ssh_args'] = ' '.join([a for a in ssh_args if a]) # Handle docker connection options if self._remote_transport in DOCKER: diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 40fae71..3d8d0fe 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -26,13 +26,13 @@ options: description: - Path on the source host that will be synchronized to the destination. - The path can be absolute or relative. - type: str + type: path required: true dest: description: - Path on the destination host that will be synchronized from the source. - The path can be absolute or relative. - type: str + type: path required: true dest_port: description: @@ -135,13 +135,6 @@ options: that does not match the inventory user, you should set this parameter to C(false). type: bool default: true - use_ssh_args: - description: - - In Ansible 2.10 and lower, it uses the ssh_args specified in C(ansible.cfg). - - In Ansible 2.11 and onwards, when set to C(true), it uses all SSH connection configurations like - C(ansible_ssh_args), C(ansible_ssh_common_args), and C(ansible_ssh_extra_args). - type: bool - default: false ssh_connection_multiplexing: description: - SSH connection multiplexing for rsync is disabled by default to prevent misconfigured ControlSockets from resulting in failed SSH connections. @@ -157,7 +150,7 @@ options: - Specify additional rsync options by passing in an array. - Note that an empty string in C(rsync_opts) will end up transfer the current working directory. type: list - default: + default: [] elements: str partial: description: @@ -178,7 +171,7 @@ options: - Add a destination to hard link against during the rsync. type: list default: - elements: str + elements: path delay_updates: description: - This option puts the temporary file from each updated file into a holding directory until the end of the transfer, @@ -186,6 +179,30 @@ options: type: bool default: true version_added: '1.3.0' + use_ssh_args: + description: + - In Ansible 2.10 and lower, it uses the ssh_args specified in C(ansible.cfg). + - In Ansible 2.11 and onwards, when set to C(true), it uses all SSH connection configurations like + C(ansible_ssh_args), C(ansible_ssh_common_args), and C(ansible_ssh_extra_args). + type: bool + default: false + _local_rsync_path: + description: Internal use only. + type: path + default: 'rsync' + required: false + _local_rsync_password: + description: Internal use only, never logged. + type: str + required: false + _substitute_controller: + description: Internal use only. + type: bool + default: false + _ssh_args: + description: Internal use only. See C(use_ssh_args) for ssh arg settings. + type: str + required: false notes: - rsync must be installed on both the local and remote host. @@ -235,7 +252,7 @@ EXAMPLES = r''' src: rsync://somehost.com/path/ dest: /some/absolute/path/ -- name: Synchronization using rsync protocol on delegate host (push) +- name: Synchronization using rsync protocol on delegate host (push) ansible.posix.synchronize: src: /some/absolute/path/ dest: rsync://somehost.com/path/ @@ -362,11 +379,11 @@ def substitute_controller(path): if not client_addr: ssh_env_string = os.environ.get('SSH_CLIENT', None) try: - client_addr, _ = ssh_env_string.split(None, 1) + client_addr, _ = ssh_env_string.split(None, 1) # pylint: disable=disallowed-name except AttributeError: ssh_env_string = os.environ.get('SSH_CONNECTION', None) try: - client_addr, _ = ssh_env_string.split(None, 1) + client_addr, _ = ssh_env_string.split(None, 1) # pylint: disable=disallowed-name except AttributeError: pass if not client_addr: @@ -388,8 +405,8 @@ def is_rsh_needed(source, dest): def main(): module = AnsibleModule( argument_spec=dict( - src=dict(type='str', required=True), - dest=dict(type='str', required=True), + src=dict(type='path', required=True), + dest=dict(type='path', required=True), dest_port=dict(type='int'), delete=dict(type='bool', default=False), private_key=dict(type='path'), @@ -412,13 +429,14 @@ def main(): set_remote_user=dict(type='bool', default=True), rsync_timeout=dict(type='int', default=0), rsync_opts=dict(type='list', default=[], elements='str'), - ssh_args=dict(type='str'), + _ssh_args=dict(type='str'), + use_ssh_args=dict(type='bool', default=False), ssh_connection_multiplexing=dict(type='bool', default=False), partial=dict(type='bool', default=False), verify_host=dict(type='bool', default=False), delay_updates=dict(type='bool', default=True), mode=dict(type='str', default='push', choices=['pull', 'push']), - link_dest=dict(type='list', elements='str'), + link_dest=dict(type='list', elements='path'), ), supports_check_mode=True, ) @@ -454,7 +472,7 @@ def main(): owner = module.params['owner'] group = module.params['group'] rsync_opts = module.params['rsync_opts'] - ssh_args = module.params['ssh_args'] + ssh_args = module.params['_ssh_args'] ssh_connection_multiplexing = module.params['ssh_connection_multiplexing'] verify_host = module.params['verify_host'] link_dest = module.params['link_dest'] @@ -572,7 +590,7 @@ def main(): # hardlink is actually a change cmd.append('-vv') for x in link_dest: - link_path = os.path.abspath(os.path.expanduser(x)) + link_path = os.path.abspath(x) destination_path = os.path.abspath(os.path.dirname(dest)) if destination_path.find(link_path) == 0: module.fail_json(msg='Hardlinking into a subdirectory of the source would cause recursion. %s and %s' % (destination_path, dest)) @@ -581,12 +599,6 @@ def main(): changed_marker = '<>' cmd.append('--out-format=%s' % shlex_quote(changed_marker + '%i %n%L')) - # expand the paths - if '@' not in source: - source = os.path.expanduser(source) - if '@' not in dest: - dest = os.path.expanduser(dest) - cmd.append(shlex_quote(source)) cmd.append(shlex_quote(dest)) cmdstr = ' '.join(cmd) diff --git a/shippable.yml b/shippable.yml index 0eda5dc..823a76b 100644 --- a/shippable.yml +++ b/shippable.yml @@ -1,3 +1,4 @@ +--- language: python env: @@ -15,14 +16,14 @@ matrix: - env: T=2.9/freebsd/12.0/1 - env: T=2.9/linux/centos6/1 - env: T=2.9/linux/centos7/1 -# - env: T=2.9/linux/centos8/1 + # - env: T=2.9/linux/centos8/1 - env: T=2.9/linux/fedora30/1 - env: T=2.9/linux/fedora31/1 - env: T=2.9/linux/opensuse15py2/1 - env: T=2.9/linux/opensuse15/1 - env: T=2.9/linux/ubuntu1604/1 - env: T=2.9/linux/ubuntu1804/1 -# - env: T=2.10/aix/7.2/1 + # - env: T=2.10/aix/7.2/1 - env: T=2.10/osx/10.11/1 - env: T=2.10/rhel/7.6/1 - env: T=2.10/rhel/8.2/1 @@ -30,14 +31,14 @@ matrix: - env: T=2.10/freebsd/12.1/1 - env: T=2.10/linux/centos6/1 - env: T=2.10/linux/centos7/1 -# - env: T=2.10/linux/centos8/1 + # - env: T=2.10/linux/centos8/1 - env: T=2.10/linux/fedora30/1 - env: T=2.10/linux/fedora31/1 - env: T=2.10/linux/opensuse15py2/1 - env: T=2.10/linux/opensuse15/1 - env: T=2.10/linux/ubuntu1604/1 - env: T=2.10/linux/ubuntu1804/1 -# - env: T=devel/aix/7.2/1 + # - env: T=devel/aix/7.2/1 - env: T=devel/osx/10.11/1 - env: T=devel/rhel/7.6/1 - env: T=devel/rhel/8.1/1 @@ -45,7 +46,7 @@ matrix: - env: T=devel/freebsd/12.1/1 - env: T=devel/linux/centos6/1 - env: T=devel/linux/centos7/1 -# - env: T=devel/linux/centos8/1 + # - env: T=devel/linux/centos8/1 - env: T=devel/linux/fedora30/1 - env: T=devel/linux/fedora31/1 - env: T=devel/linux/opensuse15py2/1 @@ -56,7 +57,7 @@ matrix: branches: except: - "*-patch-*" - - "revert-*-*" + - revert-*-* build: ci: diff --git a/tests/integration/requirements.yml b/tests/integration/requirements.yml index 08e2610..8dd5161 100644 --- a/tests/integration/requirements.yml +++ b/tests/integration/requirements.yml @@ -1,3 +1,3 @@ --- collections: -- community.general + - community.general diff --git a/tests/integration/targets/acl/tasks/acl.yml b/tests/integration/targets/acl/tasks/acl.yml index 30cfebb..24846d0 100644 --- a/tests/integration/targets/acl/tasks/acl.yml +++ b/tests/integration/targets/acl/tasks/acl.yml @@ -1,3 +1,4 @@ +--- # (c) 2017, Martin Krizek # This file is part of Ansible @@ -16,35 +17,38 @@ # along with Ansible. If not, see . - name: Create ansible user - user: + ansible.builtin.user: name: "{{ test_user }}" - name: Create ansible group - group: + ansible.builtin.group: name: "{{ test_group }}" - name: Clean up working directory and files - file: + ansible.builtin.file: path: "{{ output_dir }}" state: absent - name: Create working directory - file: + ansible.builtin.file: path: "{{ output_dir }}" state: directory + mode: "0755" - name: Create ansible file - file: + ansible.builtin.file: path: "{{ test_file }}" state: touch + mode: "0644" - name: Create ansible dir - file: + ansible.builtin.file: path: "{{ test_dir }}" state: directory + mode: "0755" ############################################################################## - name: Grant ansible user read access to a file - acl: + ansible.posix.acl: path: "{{ test_file }}" entity: "{{ test_user }}" etype: user @@ -52,12 +56,21 @@ state: present register: output -- name: get getfacl output - shell: "getfacl {{ test_file | quote }}" +- name: Debug ansible.posix.acl output + ansible.builtin.debug: + msg: "{{ output }}" + +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_file | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Debug getfacl output + ansible.builtin.debug: + msg: "{{ getfacl_output.stdout_lines }}" + +- name: Verify Output + ansible.builtin.assert: that: - output is changed - output is not failed @@ -65,16 +78,25 @@ - "'user:{{ test_user }}:r--' in getfacl_output.stdout_lines" ############################################################################## - name: Obtain the acl for a specific file - acl: + ansible.posix.acl: path: "{{ test_file }}" register: output -- name: get getfacl output - shell: "getfacl {{ test_file | quote }}" +- name: Debug ansible.posix.acl output + ansible.builtin.debug: + msg: "{{ output }}" + +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_file | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Debug getfacl output + ansible.builtin.debug: + msg: "{{ getfacl_output.stdout_lines }}" + +- name: Verify output + ansible.builtin.assert: that: - output is not changed - output is not failed @@ -89,20 +111,22 @@ - "'mask::r--' in getfacl_output.stdout_lines" - "'other::r--' in getfacl_output.stdout_lines" ############################################################################## +# - name: Removes the acl for ansible user on a specific file - acl: + ansible.posix.acl: path: "{{ test_file }}" entity: "{{ test_user }}" etype: user state: absent register: output -- name: get getfacl output - shell: "getfacl {{ test_file | quote }}" +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_file | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Verify output + ansible.builtin.assert: that: - output is changed - output is not failed @@ -110,21 +134,22 @@ - "'user:{{ test_user }}:r--' not in getfacl_output.stdout_lines" ############################################################################## - name: Sets default acl for ansible user on ansible dir - acl: + ansible.posix.acl: path: "{{ test_dir }}" entity: "{{ test_user }}" etype: user permissions: rw - default: yes + default: true state: present register: output -- name: get getfacl output - shell: "getfacl {{ test_dir | quote }}" +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_dir | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Verify output + ansible.builtin.assert: that: - output is changed - output is not failed @@ -132,22 +157,24 @@ - "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines" ############################################################################## - name: Cleanup - shell: "setfacl -b {{ test_dir | quote }}" + ansible.builtin.command: setfacl -b {{ test_dir | quote }} + changed_when: false ############################################################################## - name: Same as previous but using entry shorthand - acl: + ansible.posix.acl: path: "{{ test_dir }}" - entry: "user:{{ test_user }}:rw-" - default: yes + entry: user:{{ test_user }}:rw- + default: true state: present register: output -- name: get getfacl output - shell: "getfacl {{ test_dir | quote }}" +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_dir | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Verify output + ansible.builtin.assert: that: - output is changed - output is not failed @@ -155,19 +182,20 @@ - "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines" ############################################################################## - name: Same as previous, to test idempotence - acl: + ansible.posix.acl: path: "{{ test_dir }}" - entry: "user:{{ test_user }}:rw-" - default: yes + entry: user:{{ test_user }}:rw- + default: true state: present register: output -- name: get getfacl output - shell: "getfacl {{ test_dir | quote }}" +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_dir | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Verify output + ansible.builtin.assert: that: - output is not changed - output is not failed @@ -175,32 +203,34 @@ - "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines" ############################################################################## - name: Cleanup - shell: "setfacl -b {{ test_dir | quote }}" + ansible.builtin.command: setfacl -b {{ test_dir | quote }} + changed_when: false ############################################################################## - name: Set default acls - acl: + ansible.posix.acl: path: "{{ test_dir }}" entry: "{{ item }}" - default: yes + default: true state: present with_items: - - "user:{{ test_user }}:rw-" - - "group:{{ test_group }}:rw-" + - user:{{ test_user }}:rw- + - group:{{ test_group }}:rw- - name: Remove default group test_user acl - acl: + ansible.posix.acl: path: "{{ test_dir }}" - entry: "group:{{ test_group }}:rw-" - default: yes + entry: group:{{ test_group }}:rw- + default: true state: absent register: output -- name: get getfacl output - shell: "getfacl {{ test_dir | quote }}" +- name: Get getfacl output + ansible.builtin.command: getfacl {{ test_dir | quote }} + changed_when: false register: getfacl_output -- name: verify output - assert: +- name: Verify output + ansible.builtin.assert: that: - output is changed - output is not failed diff --git a/tests/integration/targets/acl/tasks/main.yml b/tests/integration/targets/acl/tasks/main.yml index 264f04a..d463d22 100644 --- a/tests/integration/targets/acl/tasks/main.yml +++ b/tests/integration/targets/acl/tasks/main.yml @@ -1,3 +1,4 @@ +--- # (c) 2017, Martin Krizek # This file is part of Ansible @@ -15,22 +16,21 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- block: - - - include_tasks: acl.yml - when: ansible_system == 'Linux' # TODO enable acls mount option on FreeBSD to test it there too - - always: - - name: delete created directory and file - file: - path: '{{ item }}' - state: absent - with_items: - - '{{ test_dir }}' - - '{{ test_file }}' - +- name: Test ACL vars: test_user: ansible_user test_group: ansible_group - test_file: '{{ output_dir }}/ansible file' + test_file: "{{ output_dir }}/ansible file" test_dir: "{{ output_dir }}/ansible_dir/with some space" + block: + - name: Include tests task file + ansible.builtin.include_tasks: acl.yml + when: ansible_system == 'Linux' # TODO enable acls mount option on FreeBSD to test it there too + always: + - name: Delete created directory and file + ansible.builtin.file: + path: "{{ item }}" + state: absent + with_items: + - "{{ test_dir }}" + - "{{ test_file }}" diff --git a/tests/integration/targets/at/meta/main.yml b/tests/integration/targets/at/meta/main.yml index 07faa21..8828391 100644 --- a/tests/integration/targets/at/meta/main.yml +++ b/tests/integration/targets/at/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - prepare_tests diff --git a/tests/integration/targets/at/tasks/main.yml b/tests/integration/targets/at/tasks/main.yml index cd09e11..7504e17 100644 --- a/tests/integration/targets/at/tasks/main.yml +++ b/tests/integration/targets/at/tasks/main.yml @@ -1,3 +1,4 @@ +--- # Test code for the at module. # (c) 2017, James Tanner @@ -16,47 +17,56 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- set_fact: output_dir_test={{output_dir}}/at +- name: Set output_dir_test fast + ansible.builtin.set_fact: + output_dir_test: "{{ output_dir }}/at" -- name: make sure our testing sub-directory does not exist - file: path="{{ output_dir_test }}" state=absent +- name: Make sure our testing sub-directory does not exist + ansible.builtin.file: + path: "{{ output_dir_test }}" + state: absent -- name: create our testing sub-directory - file: path="{{ output_dir_test }}" state=directory +- name: Create our testing sub-directory + ansible.builtin.file: + path: "{{ output_dir_test }}" + state: directory + mode: "0755" ## ## at ## -- name: define distros to attempt installing at on - set_fact: +- name: Define distros to attempt installing at on + ansible.builtin.set_fact: package_distros: - - RedHat - - CentOS - - ScientificLinux - - Fedora - - Ubuntu - - Debian - - openSUSE Leap + - RedHat + - CentOS + - ScientificLinux + - Fedora + - Ubuntu + - Debian + - openSUSE Leap -- name: ensure at is installed - package: +- name: Ensure at is installed + ansible.builtin.package: name: at state: present when: ansible_distribution in package_distros -- name: run the first example - at: - command: "ls -d / > /dev/null" +- name: Run the first example + ansible.posix.at: + command: ls -d / > /dev/null count: 20 units: minutes register: at_test0 -- debug: var=at_test0 -- name: validate results - assert: - that: - - 'at_test0.changed is defined' - - 'at_test0.count is defined' - - 'at_test0.script_file is defined' - - 'at_test0.state is defined' - - 'at_test0.units is defined' +- name: Debug var=at_test0 + ansible.builtin.debug: + var: at_test0 +- name: Validate results + ansible.builtin.assert: + that: + - at_test0.changed is defined + - at_test0.count is defined + - at_test0.script_file is defined + - at_test0.state is defined + - at_test0.units is defined diff --git a/tests/integration/targets/authorized_key/defaults/main.yml b/tests/integration/targets/authorized_key/defaults/main.yml index d99e298..1b60f8c 100644 --- a/tests/integration/targets/authorized_key/defaults/main.yml +++ b/tests/integration/targets/authorized_key/defaults/main.yml @@ -1,3 +1,4 @@ +--- dss_key_basic: ssh-dss DATA_BASIC root@testing dss_key_unquoted_option: idle-timeout=5m ssh-dss DATA_UNQUOTED_OPTION root@testing dss_key_command: command="/bin/true" ssh-dss DATA_COMMAND root@testing @@ -8,27 +9,27 @@ dss_key_trailing: ssh-dss DATA_TRAILING root@testing foo bar baz rsa_key_basic: ssh-rsa DATA_BASIC root@testing multiple_key_base: | - ssh-rsa DATA_BASIC 1@testing - ssh-dss DATA_TRAILING 2@testing foo bar baz - ssh-dss DATA_TRAILING 3@testing foo bar baz - ecdsa-sha2-nistp521 ECDSA_DATA 4@testing + ssh-rsa DATA_BASIC 1@testing + ssh-dss DATA_TRAILING 2@testing foo bar baz + ssh-dss DATA_TRAILING 3@testing foo bar baz + ecdsa-sha2-nistp521 ECDSA_DATA 4@testing multiple_key_different_order: | - ssh-dss DATA_TRAILING 2@testing foo bar baz - ssh-dss DATA_TRAILING 3@testing foo bar baz - ssh-rsa DATA_BASIC 1@testing - ecdsa-sha2-nistp521 ECDSA_DATA 4@testing + ssh-dss DATA_TRAILING 2@testing foo bar baz + ssh-dss DATA_TRAILING 3@testing foo bar baz + ssh-rsa DATA_BASIC 1@testing + ecdsa-sha2-nistp521 ECDSA_DATA 4@testing multiple_key_different_order_2: | - ssh-dss DATA_TRAILING 2@testing foo bar baz - ssh-rsa WHATEVER 2.5@testing - ssh-dss DATA_TRAILING 3@testing foo bar baz - ssh-rsa DATA_BASIC 1@testing - ecdsa-sha2-nistp521 ECDSA_DATA 4@testing + ssh-dss DATA_TRAILING 2@testing foo bar baz + ssh-rsa WHATEVER 2.5@testing + ssh-dss DATA_TRAILING 3@testing foo bar baz + ssh-rsa DATA_BASIC 1@testing + ecdsa-sha2-nistp521 ECDSA_DATA 4@testing multiple_key_exclusive: | - ssh-rsa DATA_BASIC 1@testing - ecdsa-sha2-nistp521 ECDSA_DATA 4@testing + ssh-rsa DATA_BASIC 1@testing + ecdsa-sha2-nistp521 ECDSA_DATA 4@testing multiple_keys_comments: | ssh-rsa DATA_BASIC 1@testing diff --git a/tests/integration/targets/authorized_key/meta/main.yml b/tests/integration/targets/authorized_key/meta/main.yml index 07faa21..8828391 100644 --- a/tests/integration/targets/authorized_key/meta/main.yml +++ b/tests/integration/targets/authorized_key/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - prepare_tests diff --git a/tests/integration/targets/authorized_key/tasks/check_mode.yml b/tests/integration/targets/authorized_key/tasks/check_mode.yml index ce51074..6b67949 100644 --- a/tests/integration/targets/authorized_key/tasks/check_mode.yml +++ b/tests/integration/targets/authorized_key/tasks/check_mode.yml @@ -1,34 +1,37 @@ +--- # ------------------------------------------------------------- # check mode - name: CHECK MODE | copy an existing file in place with comments - copy: + ansible.builtin.copy: src: existing_authorized_keys dest: "{{ output_dir | expanduser }}/authorized_keys" + mode: "0600" - name: CHECK MODE | add key in check mode to validate return codes - authorized_key: + ansible.posix.authorized_key: user: root key: "{{ multiple_key_different_order_2 }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" - check_mode: True + check_mode: true register: result - name: CHECK MODE | assert that authorized_keys return values are consistent - assert: + ansible.builtin.assert: that: - - 'result.changed == True' + - result.changed == True - '"user" in result' - '"key" in result' - name: CHECK MODE | recopy authorized_keys to ensure it was not changed - copy: + ansible.builtin.copy: src: existing_authorized_keys dest: "{{ output_dir | expanduser }}/authorized_keys" + mode: "0600" register: result - name: CHECK MODE | assert that the authorized_keys file was not changed - assert: + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False diff --git a/tests/integration/targets/authorized_key/tasks/comments.yml b/tests/integration/targets/authorized_key/tasks/comments.yml index 6c58961..f75caee 100644 --- a/tests/integration/targets/authorized_key/tasks/comments.yml +++ b/tests/integration/targets/authorized_key/tasks/comments.yml @@ -1,8 +1,9 @@ +--- # ------------------------------------------------------------- # comments - name: Add rsa key with existing comment - authorized_key: + ansible.posix.authorized_key: user: root key: "{{ rsa_key_basic }}" state: present @@ -10,7 +11,7 @@ register: result - name: Change the comment on an existing key - authorized_key: + ansible.posix.authorized_key: user: root key: "{{ rsa_key_basic }}" comment: user@acme.com @@ -18,18 +19,18 @@ path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: get the file content - shell: cat "{{ output_dir | expanduser }}/authorized_keys" | fgrep DATA_BASIC - changed_when: no +- name: Get the file content + ansible.builtin.command: fgrep DATA_BASIC "{{ output_dir | expanduser }}/authorized_keys" + changed_when: false register: content - name: Assert that comment on an existing key was changed - assert: + ansible.builtin.assert: that: - "'user@acme.com' in content.stdout" - name: Set the same key with comment to ensure no changes are reported - authorized_key: + ansible.posix.authorized_key: user: root key: "{{ rsa_key_basic }}" comment: user@acme.com @@ -38,11 +39,12 @@ register: result - name: Assert that no changes were made when running again - assert: + ansible.builtin.assert: that: - not result.changed -- debug: +- name: Debug the result and content + ansible.builtin.debug: var: "{{ item }}" verbosity: 1 with_items: diff --git a/tests/integration/targets/authorized_key/tasks/main.yml b/tests/integration/targets/authorized_key/tasks/main.yml index 70752cf..6a22838 100644 --- a/tests/integration/targets/authorized_key/tasks/main.yml +++ b/tests/integration/targets/authorized_key/tasks/main.yml @@ -1,3 +1,4 @@ +--- # test code for the authorized_key module # - (c) 2014, James Cammarata # - (c) 2021, Hideki Saito @@ -17,16 +18,16 @@ # along with Ansible. If not, see . - name: Setup testing environment - import_tasks: setup_steps.yml + ansible.builtin.import_tasks: setup_steps.yml - name: Test for multiple keys handling - import_tasks: multiple_keys.yml + ansible.builtin.import_tasks: multiple_keys.yml - name: Test for ssh-dss key handling - import_tasks: ssh_dss.yml + ansible.builtin.import_tasks: ssh_dss.yml - name: Test for check mode - import_tasks: check_mode.yml + ansible.builtin.import_tasks: check_mode.yml - name: Test for the management of comments with key - import_tasks: comments.yml + ansible.builtin.import_tasks: comments.yml diff --git a/tests/integration/targets/authorized_key/tasks/multiple_keys.yml b/tests/integration/targets/authorized_key/tasks/multiple_keys.yml index fc57dea..e03abe5 100644 --- a/tests/integration/targets/authorized_key/tasks/multiple_keys.yml +++ b/tests/integration/targets/authorized_key/tasks/multiple_keys.yml @@ -1,38 +1,39 @@ +--- # ------------------------------------------------------------- # multiple keys -- name: add multiple keys - authorized_key: +- name: Add multiple keys + ansible.posix.authorized_key: user: root key: "{{ multiple_key_base }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == multiple_key_base' - - 'result.key_options == None' + - result.changed == True + - result.key == multiple_key_base + - result.key_options == None -- name: add multiple keys different order - authorized_key: +- name: Add multiple keys different order + ansible.posix.authorized_key: user: root key: "{{ multiple_key_different_order }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == multiple_key_different_order' - - 'result.key_options == None' + - result.changed == True + - result.key == multiple_key_different_order + - result.key_options == None -- name: add multiple keys exclusive - authorized_key: +- name: Add multiple keys exclusive + ansible.posix.authorized_key: user: root key: "{{ multiple_key_exclusive }}" state: present @@ -40,42 +41,42 @@ exclusive: true register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == multiple_key_exclusive' - - 'result.key_options == None' + - result.changed == True + - result.key == multiple_key_exclusive + - result.key_options == None -- name: add multiple keys in different calls - authorized_key: +- name: Add multiple keys in different calls + ansible.posix.authorized_key: user: root - key: "ecdsa-sha2-nistp521 ECDSA_DATA 4@testing" + key: ecdsa-sha2-nistp521 ECDSA_DATA 4@testing state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: add multiple keys in different calls - authorized_key: +- name: Add multiple keys in different calls + ansible.posix.authorized_key: user: root - key: "ssh-rsa DATA_BASIC 1@testing" + key: ssh-rsa DATA_BASIC 1@testing state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: get the file content - shell: cat "{{ output_dir | expanduser }}/authorized_keys" - changed_when: no +- name: Get the file content + ansible.builtin.command: /bin/cat "{{ output_dir | expanduser }}/authorized_keys" + changed_when: false register: multiple_keys_at_a_time -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == false' - - 'multiple_keys_at_a_time.stdout == multiple_key_exclusive.strip()' + - result.changed == false + - multiple_keys_at_a_time.stdout == multiple_key_exclusive.strip() -- name: add multiple keys comment - authorized_key: +- name: Add multiple keys comment + ansible.posix.authorized_key: user: root key: "{{ multiple_keys_comments }}" state: present @@ -83,14 +84,14 @@ exclusive: true register: result -- name: get the file content - shell: cat "{{ output_dir | expanduser }}/authorized_keys" - changed_when: no +- name: Get the file content + ansible.builtin.command: /bin/cat "{{ output_dir | expanduser }}/authorized_keys" + changed_when: false register: multiple_keys_comments -- name: assert that the keys exist and comment only lines were not added - assert: +- name: Assert that the keys exist and comment only lines were not added + ansible.builtin.assert: that: - - 'result.changed == False' - - 'multiple_keys_comments.stdout == multiple_key_exclusive.strip()' - - 'result.key_options == None' + - result.changed == False + - multiple_keys_comments.stdout == multiple_key_exclusive.strip() + - result.key_options == None diff --git a/tests/integration/targets/authorized_key/tasks/setup_steps.yml b/tests/integration/targets/authorized_key/tasks/setup_steps.yml index 2144b7a..30a8914 100644 --- a/tests/integration/targets/authorized_key/tasks/setup_steps.yml +++ b/tests/integration/targets/authorized_key/tasks/setup_steps.yml @@ -1,37 +1,40 @@ +--- # ------------------------------------------------------------- # Setup steps - name: Clean up the working directory and files - file: - path: '{{ output_dir }}' + ansible.builtin.file: + path: "{{ output_dir }}" state: absent - name: Create the working directory - file: - path: '{{ output_dir }}' + ansible.builtin.file: + path: "{{ output_dir }}" state: directory + mode: "0744" -- name: copy an existing file in place with comments - copy: +- name: Copy an existing file in place with comments + ansible.builtin.copy: src: existing_authorized_keys dest: "{{ output_dir | expanduser }}/authorized_keys" + mode: "0600" -- name: add multiple keys different order - authorized_key: +- name: Add multiple keys different order + ansible.posix.authorized_key: user: root key: "{{ multiple_key_different_order_2 }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: get the file content - shell: cat "{{ output_dir | expanduser }}/authorized_keys" - changed_when: no +- name: Get the file content + ansible.builtin.command: /bin/cat "{{ output_dir | expanduser }}/authorized_keys" + changed_when: false register: multiple_keys_existing -- name: assert that the key was added and comments and ordering preserved - assert: +- name: Assert that the key was added and comments and ordering preserved + ansible.builtin.assert: that: - - 'result.changed == True' + - result.changed == True - '"# I like candy" in multiple_keys_existing.stdout' - '"# I like candy" in multiple_keys_existing.stdout_lines[0]' - '"ssh-rsa DATA_BASIC 1@testing" in multiple_keys_existing.stdout' @@ -41,19 +44,20 @@ # start afresh -- name: remove file foo.txt - file: +- name: Remove file foo.txt + ansible.builtin.file: path: "{{ output_dir | expanduser }}/authorized_keys" state: absent -- name: touch the authorized_keys file - file: +- name: Touch the authorized_keys file + ansible.builtin.file: dest: "{{ output_dir }}/authorized_keys" state: touch + mode: "0600" register: result -- name: assert that the authorized_keys file was created - assert: +- name: Assert that the authorized_keys file was created + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.state == "file"' + - result.changed == True + - result.state == "file" diff --git a/tests/integration/targets/authorized_key/tasks/ssh_dss.yml b/tests/integration/targets/authorized_key/tasks/ssh_dss.yml index 1683f99..537af8c 100644 --- a/tests/integration/targets/authorized_key/tasks/ssh_dss.yml +++ b/tests/integration/targets/authorized_key/tasks/ssh_dss.yml @@ -1,241 +1,250 @@ +--- # ------------------------------------------------------------- # basic ssh-dss key -- name: add basic ssh-dss key - authorized_key: user=root key="{{ dss_key_basic }}" state=present path="{{ output_dir | expanduser }}/authorized_keys" +- name: Add basic ssh-dss key + ansible.posix.authorized_key: + user: root + key: "{{ dss_key_basic }}" + state: present + path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_basic' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_basic + - result.key_options == None -- name: re-add basic ssh-dss key - authorized_key: user=root key="{{ dss_key_basic }}" state=present path="{{ output_dir | expanduser }}/authorized_keys" +- name: Re-add basic ssh-dss key + ansible.posix.authorized_key: + user: root + key: "{{ dss_key_basic }}" + state: present + path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # ssh-dss key with an unquoted option -- name: add ssh-dss key with an unquoted option - authorized_key: +- name: Add ssh-dss key with an unquoted option + ansible.posix.authorized_key: user: root key: "{{ dss_key_unquoted_option }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_unquoted_option' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_unquoted_option + - result.key_options == None -- name: re-add ssh-dss key with an unquoted option - authorized_key: +- name: Re-add ssh-dss key with an unquoted option + ansible.posix.authorized_key: user: root key: "{{ dss_key_unquoted_option }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # ssh-dss key with a leading command="/bin/foo" -- name: add ssh-dss key with a leading command - authorized_key: +- name: Add ssh-dss key with a leading command + ansible.posix.authorized_key: user: root key: "{{ dss_key_command }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_command' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_command + - result.key_options == None -- name: re-add ssh-dss key with a leading command - authorized_key: +- name: Re-add ssh-dss key with a leading command + ansible.posix.authorized_key: user: root key: "{{ dss_key_command }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # ssh-dss key with a complex quoted leading command # ie. command="/bin/echo foo 'bar baz'" -- name: add ssh-dss key with a complex quoted leading command - authorized_key: +- name: Add ssh-dss key with a complex quoted leading command + ansible.posix.authorized_key: user: root key: "{{ dss_key_complex_command }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_complex_command' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_complex_command + - result.key_options == None -- name: re-add ssh-dss key with a complex quoted leading command - authorized_key: +- name: Re-add ssh-dss key with a complex quoted leading command + ansible.posix.authorized_key: user: root key: "{{ dss_key_complex_command }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # ssh-dss key with a command and a single option, which are # in a comma-separated list -- name: add ssh-dss key with a command and a single option - authorized_key: +- name: Add ssh-dss key with a command and a single option + ansible.posix.authorized_key: user: root key: "{{ dss_key_command_single_option }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_command_single_option' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_command_single_option + - result.key_options == None -- name: re-add ssh-dss key with a command and a single option - authorized_key: +- name: Re-add ssh-dss key with a command and a single option + ansible.posix.authorized_key: user: root key: "{{ dss_key_command_single_option }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # ssh-dss key with a command and multiple other options -- name: add ssh-dss key with a command and multiple options - authorized_key: +- name: Add ssh-dss key with a command and multiple options + ansible.posix.authorized_key: user: root key: "{{ dss_key_command_multiple_options }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_command_multiple_options' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_command_multiple_options + - result.key_options == None -- name: re-add ssh-dss key with a command and multiple options - authorized_key: +- name: Re-add ssh-dss key with a command and multiple options + ansible.posix.authorized_key: user: root key: "{{ dss_key_command_multiple_options }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # ssh-dss key with multiple trailing parts, which are space- # separated and not quoted in any way -- name: add ssh-dss key with trailing parts - authorized_key: +- name: Add ssh-dss key with trailing parts + ansible.posix.authorized_key: user: root key: "{{ dss_key_trailing }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key was added - assert: +- name: Assert that the key was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_trailing' - - 'result.key_options == None' + - result.changed == True + - result.key == dss_key_trailing + - result.key_options == None -- name: re-add ssh-dss key with trailing parts - authorized_key: +- name: Re-add ssh-dss key with trailing parts + ansible.posix.authorized_key: user: root key: "{{ dss_key_trailing }}" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that nothing changed - assert: +- name: Assert that nothing changed + ansible.builtin.assert: that: - - 'result.changed == False' + - result.changed == False # ------------------------------------------------------------- # basic ssh-dss key with mutliple permit-open options # https://github.com/ansible/ansible-modules-core/issues/1715 -- name: add basic ssh-dss key with multi-opts - authorized_key: +- name: Add basic ssh-dss key with multi-opts + ansible.posix.authorized_key: user: root key: "{{ dss_key_basic }}" - key_options: 'no-agent-forwarding,no-X11-forwarding,permitopen="10.9.8.1:8080",permitopen="10.9.8.1:9001"' + key_options: no-agent-forwarding,no-X11-forwarding,permitopen="10.9.8.1:8080",permitopen="10.9.8.1:9001" state: present path: "{{ output_dir | expanduser }}/authorized_keys" register: result -- name: assert that the key with multi-opts was added - assert: +- name: Assert that the key with multi-opts was added + ansible.builtin.assert: that: - - 'result.changed == True' - - 'result.key == dss_key_basic' - - 'result.key_options == "no-agent-forwarding,no-X11-forwarding,permitopen=\"10.9.8.1:8080\",permitopen=\"10.9.8.1:9001\""' + - result.changed == True + - result.key == dss_key_basic + - result.key_options == "no-agent-forwarding,no-X11-forwarding,permitopen=\"10.9.8.1:8080\",permitopen=\"10.9.8.1:9001\"" -- name: get the file content - shell: cat "{{ output_dir | expanduser }}/authorized_keys" | fgrep DATA_BASIC - changed_when: no +- name: Get the file content + ansible.builtin.command: fgrep DATA_BASIC "{{ output_dir | expanduser }}/authorized_keys" + changed_when: false register: content -- name: validate content - assert: +- name: Validate content + ansible.builtin.assert: that: - - 'content.stdout == "no-agent-forwarding,no-X11-forwarding,permitopen=\"10.9.8.1:8080\",permitopen=\"10.9.8.1:9001\" ssh-dss DATA_BASIC root@testing"' + - content.stdout == "no-agent-forwarding,no-X11-forwarding,permitopen=\"10.9.8.1:8080\",permitopen=\"10.9.8.1:9001\" ssh-dss DATA_BASIC root@testing" diff --git a/tests/integration/targets/firewalld/meta/main.yml b/tests/integration/targets/firewalld/meta/main.yml index 5438ced..b63c3d0 100644 --- a/tests/integration/targets/firewalld/meta/main.yml +++ b/tests/integration/targets/firewalld/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - setup_pkg_mgr diff --git a/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml b/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml index 62fcbe4..3bd5bf0 100644 --- a/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/icmp_block_inversion_test_cases.yml @@ -1,172 +1,173 @@ +--- # Test playbook for the firewalld module - icmp block inversion operations # (c) 2022, Gregory Furlong # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Icmp block inversion enabled when icmp block inversion is truthy and state is enabled block: - - name: Testing enable icmp block inversion - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: yes - permanent: yes - state: enabled - register: result + - name: Testing enable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: true + permanent: true + state: enabled + register: result - - name: assert icmp block inversion is enabled - assert: - that: - - result is changed + - name: Assert icmp block inversion is enabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing enable icmp block inversion (verify not changed) - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: yes - permanent: yes - state: enabled - register: result + - name: Testing enable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: true + permanent: true + state: enabled + register: result - - name: assert icmp block inversion is enabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert icmp block inversion is enabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Icmp block inversion disabled when icmp block inversion is falsy and state is enabled block: - - name: Testing disable icmp block inversion - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: no - permanent: yes - state: enabled - register: result + - name: Testing disable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: false + permanent: true + state: enabled + register: result - - name: assert icmp block inversion is disabled - assert: - that: - - result is changed + - name: Assert icmp block inversion is disabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing disable icmp block inversion (verify not changed) - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: no - permanent: yes - state: enabled - register: result + - name: Testing disable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: false + permanent: true + state: enabled + register: result - - name: assert icmp block inversion is disabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert icmp block inversion is disabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Icmp block inversion enabled when icmp block inversion is falsy and state is disabled block: - - name: Testing enable icmp block inversion - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: no - permanent: yes - state: disabled - register: result + - name: Testing enable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: false + permanent: true + state: disabled + register: result - - name: assert icmp block inversion is enabled - assert: - that: - - result is changed + - name: Assert icmp block inversion is enabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing enable icmp block inversion (verify not changed) - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: no - permanent: yes - state: disabled - register: result + - name: Testing enable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: false + permanent: true + state: disabled + register: result - - name: assert icmp block inversion is enabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert icmp block inversion is enabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Icmp block inversion disabled when icmp block inversion is truthy and state is disabled block: - - name: Testing disable icmp block inversion - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: yes - permanent: yes - state: disabled - register: result + - name: Testing disable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: true + permanent: true + state: disabled + register: result - - name: assert icmp block inversion is disabled - assert: - that: - - result is changed + - name: Assert icmp block inversion is disabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing disable icmp block inversion (verify not changed) - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: yes - permanent: yes - state: disabled - register: result + - name: Testing disable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: true + permanent: true + state: disabled + register: result - - name: assert icmp block inversion is disabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert icmp block inversion is disabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed # Validate backwards compatible behavior until icmp block inversion is switched from string to boolean type - name: Icmp block inversion enabled when icmp block inversion is non-boolean string and state is enabled block: - - name: Testing enable icmp block inversion - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: 'some string' - permanent: yes - state: enabled - register: result + - name: Testing enable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: some string + permanent: true + state: enabled + register: result - - name: assert icmp block inversion is enabled - assert: - that: - - result is changed + - name: Assert icmp block inversion is enabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing enable icmp block inversion (verify not changed) - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: 'some string' - permanent: yes - state: enabled - register: result + - name: Testing enable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: some string + permanent: true + state: enabled + register: result - - name: assert icmp block inversion is enabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert icmp block inversion is enabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Icmp block inversion disabled when icmp block inversion is non-boolean string and state is disabled block: - - name: Testing disable icmp block inversion - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: 'some string' - permanent: yes - state: disabled - register: result + - name: Testing disable icmp block inversion + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: some string + permanent: true + state: disabled + register: result - - name: assert icmp block inversion is disabled - assert: - that: - - result is changed + - name: Assert icmp block inversion is disabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing disable icmp block inversion (verify not changed) - ansible.posix.firewalld: - zone: trusted - icmp_block_inversion: 'some string' - permanent: yes - state: disabled - register: result + - name: Testing disable icmp block inversion (verify not changed) + ansible.posix.firewalld: + zone: trusted + icmp_block_inversion: some string + permanent: true + state: disabled + register: result - - name: assert icmp block inversion is disabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert icmp block inversion is disabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/interface_test_cases.yml b/tests/integration/targets/firewalld/tasks/interface_test_cases.yml index e7130f7..64bbc65 100644 --- a/tests/integration/targets/firewalld/tasks/interface_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/interface_test_cases.yml @@ -1,87 +1,88 @@ +--- # Test playbook for the firewalld module - interface operations # (c) 2022, Gregory Furlong # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Validate adding interface block: - - name: Add lo interface to trusted zone - ansible.posix.firewalld: - interface: lo - zone: trusted - permanent: Yes - state: enabled - register: result + - name: Add lo interface to trusted zone + ansible.posix.firewalld: + interface: lo + zone: trusted + permanent: true + state: enabled + register: result - - name: assert lo was added to trusted zone - assert: - that: - - result is changed + - name: Assert lo was added to trusted zone + ansible.builtin.assert: + that: + - result is changed - - name: Add lo interface to trusted zone (verify not changed) - ansible.posix.firewalld: - interface: lo - zone: trusted - permanent: Yes - state: enabled - register: result + - name: Add lo interface to trusted zone (verify not changed) + ansible.posix.firewalld: + interface: lo + zone: trusted + permanent: true + state: enabled + register: result - - name: assert lo was added to trusted zone (verify not changed) - assert: - that: - - result is not changed + - name: Assert lo was added to trusted zone (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Validate moving interfaces block: - - name: Move lo interface from trusted zone to internal zone - ansible.posix.firewalld: - interface: lo - zone: internal - permanent: Yes - state: enabled - register: result + - name: Move lo interface from trusted zone to internal zone + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: true + state: enabled + register: result - - name: Assert lo was moved from trusted zone to internal zone - assert: - that: - - result is changed + - name: Assert lo was moved from trusted zone to internal zone + ansible.builtin.assert: + that: + - result is changed - - name: Move lo interface from trusted zone to internal zone (verify not changed) - ansible.posix.firewalld: - interface: lo - zone: internal - permanent: Yes - state: enabled - register: result + - name: Move lo interface from trusted zone to internal zone (verify not changed) + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: true + state: enabled + register: result - - name: assert lo was moved from trusted zone to internal zone (verify not changed) - assert: - that: - - result is not changed + - name: Assert lo was moved from trusted zone to internal zone (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Validate removing interface block: - - name: Remove lo interface from internal zone - ansible.posix.firewalld: - interface: lo - zone: internal - permanent: Yes - state: disabled - register: result + - name: Remove lo interface from internal zone + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: true + state: disabled + register: result - - name: Assert lo interface was removed from internal zone - assert: - that: - - result is changed + - name: Assert lo interface was removed from internal zone + ansible.builtin.assert: + that: + - result is changed - - name: Remove lo interface from internal zone (verify not changed) - ansible.posix.firewalld: - interface: lo - zone: internal - permanent: Yes - state: disabled - register: result + - name: Remove lo interface from internal zone (verify not changed) + ansible.posix.firewalld: + interface: lo + zone: internal + permanent: true + state: disabled + register: result - - name: Assert lo interface was removed from internal zone (verify not changed) - assert: - that: - - result is not changed + - name: Assert lo interface was removed from internal zone (verify not changed) + ansible.builtin.assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/main.yml b/tests/integration/targets/firewalld/tasks/main.yml index 5f81c62..b19c28f 100644 --- a/tests/integration/targets/firewalld/tasks/main.yml +++ b/tests/integration/targets/firewalld/tasks/main.yml @@ -1,17 +1,24 @@ +--- # Test playbook for the firewalld module # (c) 2017, Adam Miller # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Run firewalld tests + when: + - ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=') + - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '==')) + # Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros + - not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3) + - not (ansible_facts.distribution == "CentOS" and ansible_distribution_major_version is version('7', '==')) # FIXME block: - name: Ensure firewalld is installed - package: + ansible.builtin.package: name: firewalld state: present - # This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6 + # This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6 - name: Enable dbus-broker daemon - service: + ansible.builtin.service: name: dbus-broker enabled: true state: started @@ -19,25 +26,20 @@ - name: Test Online Operations block: - - name: start firewalld - service: + - name: Start firewalld + ansible.builtin.service: name: firewalld state: started - - import_tasks: run_all_tests.yml + - name: Import test tasks + ansible.builtin.import_tasks: run_all_tests.yml - name: Test Offline Operations block: - - name: stop firewalld - service: + - name: Stop firewalld + ansible.builtin.service: name: firewalld state: stopped - - import_tasks: run_all_tests.yml - - when: - - ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=') - - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '==')) - # Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros - - not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3) - - not (ansible_facts.distribution == "CentOS" and ansible_distribution_major_version is version('7', '==')) # FIXME + - name: Import test tasks + ansible.builtin.import_tasks: run_all_tests.yml diff --git a/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml b/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml index 860378f..82d321e 100644 --- a/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/masquerade_test_cases.yml @@ -1,172 +1,173 @@ +--- # Test playbook for the firewalld module - masquerade operations # (c) 2022, Gregory Furlong # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Masquerade enabled when masquerade is truthy and state is enabled block: - - name: Testing enable masquerade - ansible.posix.firewalld: - zone: trusted - masquerade: yes - permanent: yes - state: enabled - register: result + - name: Testing enable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: true + permanent: true + state: enabled + register: result - - name: assert masquerade is enabled - assert: - that: - - result is changed + - name: Assert masquerade is enabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing enable masquerade (verify not changed) - ansible.posix.firewalld: - zone: trusted - masquerade: yes - permanent: yes - state: enabled - register: result + - name: Testing enable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: true + permanent: true + state: enabled + register: result - - name: assert masquerade is enabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert masquerade is enabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Masquerade disabled when masquerade is falsy and state is enabled block: - - name: Testing disable masquerade - ansible.posix.firewalld: - zone: trusted - masquerade: no - permanent: yes - state: enabled - register: result + - name: Testing disable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: false + permanent: true + state: enabled + register: result - - name: assert masquerade is disabled - assert: - that: - - result is changed + - name: Assert masquerade is disabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing disable masquerade (verify not changed) - ansible.posix.firewalld: - zone: trusted - masquerade: no - permanent: yes - state: enabled - register: result + - name: Testing disable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: false + permanent: true + state: enabled + register: result - - name: assert masquerade is disabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert masquerade is disabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Masquerade enabled when masquerade is falsy and state is disabled block: - - name: Testing enable masquerade - ansible.posix.firewalld: - zone: trusted - masquerade: no - permanent: yes - state: disabled - register: result + - name: Testing enable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: false + permanent: true + state: disabled + register: result - - name: assert masquerade is enabled - assert: - that: - - result is changed + - name: Assert masquerade is enabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing enable masquerade (verify not changed) - ansible.posix.firewalld: - zone: trusted - masquerade: no - permanent: yes - state: disabled - register: result + - name: Testing enable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: false + permanent: true + state: disabled + register: result - - name: assert masquerade is enabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert masquerade is enabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Masquerade disabled when masquerade is truthy and state is disabled block: - - name: Testing disable masquerade - ansible.posix.firewalld: - zone: trusted - masquerade: yes - permanent: yes - state: disabled - register: result + - name: Testing disable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: true + permanent: true + state: disabled + register: result - - name: assert masquerade is disabled - assert: - that: - - result is changed + - name: Assert masquerade is disabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing disable masquerade (verify not changed) - ansible.posix.firewalld: - zone: trusted - masquerade: yes - permanent: yes - state: disabled - register: result + - name: Testing disable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: true + permanent: true + state: disabled + register: result - - name: assert masquerade is disabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert masquerade is disabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed # Validate backwards compatible behavior until masquerade is switched from string to boolean type - name: Masquerade enabled when masquerade is non-boolean string and state is enabled block: - - name: Testing enable masquerade - ansible.posix.firewalld: - zone: trusted - masquerade: 'some string' - permanent: yes - state: enabled - register: result + - name: Testing enable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: some string + permanent: true + state: enabled + register: result - - name: assert masquerade is enabled - assert: - that: - - result is changed + - name: Assert masquerade is enabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing enable masquerade (verify not changed) - ansible.posix.firewalld: - zone: trusted - masquerade: 'some string' - permanent: yes - state: enabled - register: result + - name: Testing enable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: some string + permanent: true + state: enabled + register: result - - name: assert masquerade is enabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert masquerade is enabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed - name: Masquerade disabled when masquerade is non-boolean string and state is disabled block: - - name: Testing disable masquerade - ansible.posix.firewalld: - zone: trusted - masquerade: 'some string' - permanent: yes - state: disabled - register: result + - name: Testing disable masquerade + ansible.posix.firewalld: + zone: trusted + masquerade: some string + permanent: true + state: disabled + register: result - - name: assert masquerade is disabled - assert: - that: - - result is changed + - name: Assert masquerade is disabled + ansible.builtin.assert: + that: + - result is changed - - name: Testing disable masquerade (verify not changed) - ansible.posix.firewalld: - zone: trusted - masquerade: 'some string' - permanent: yes - state: disabled - register: result + - name: Testing disable masquerade (verify not changed) + ansible.posix.firewalld: + zone: trusted + masquerade: some string + permanent: true + state: disabled + register: result - - name: assert masquerade is disabled (verify not changed) - assert: - that: - - result is not changed + - name: Assert masquerade is disabled (verify not changed) + ansible.builtin.assert: + that: + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml b/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml index 78a451d..0b71444 100644 --- a/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/port_forward_test_cases.yml @@ -1,9 +1,10 @@ +--- # Test playbook for the firewalld module - port operations # (c) 2017, Adam Miller # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -- name: firewalld port forward test permanent enabled - firewalld: +- name: Firewalld port forward test permanent enabled + ansible.posix.firewalld: port_forward: - port: 8080 proto: tcp @@ -12,13 +13,13 @@ state: enabled register: result -- name: assert firewalld port test permanent enabled worked - assert: +- name: Assert firewalld port test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld port test permanent enabled rerun (verify not changed) - firewalld: +- name: Firewalld port test permanent enabled rerun (verify not changed) + ansible.posix.firewalld: port_forward: - port: 8080 proto: tcp @@ -27,13 +28,13 @@ state: enabled register: result -- name: assert firewalld port test permanent enabled rerun worked (verify not changed) - assert: +- name: Assert firewalld port test permanent enabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld port test permanent disabled - firewalld: +- name: Firewalld port test permanent disabled + ansible.posix.firewalld: port_forward: - port: 8080 proto: tcp @@ -42,13 +43,13 @@ state: disabled register: result -- name: assert firewalld port test permanent disabled worked - assert: +- name: Assert firewalld port test permanent disabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld port test permanent disabled rerun (verify not changed) - firewalld: +- name: Firewalld port test permanent disabled rerun (verify not changed) + ansible.posix.firewalld: port_forward: - port: 8080 proto: tcp @@ -57,7 +58,7 @@ state: disabled register: result -- name: assert firewalld port test permanent disabled rerun worked (verify not changed) - assert: +- name: Assert firewalld port test permanent disabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/port_test_cases.yml b/tests/integration/targets/firewalld/tasks/port_test_cases.yml index c62c242..ff2440f 100644 --- a/tests/integration/targets/firewalld/tasks/port_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/port_test_cases.yml @@ -1,57 +1,58 @@ +--- # Test playbook for the firewalld module - port operations # (c) 2017, Adam Miller # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -- name: firewalld port range test permanent enabled - firewalld: +- name: Firewalld port range test permanent enabled + ansible.posix.firewalld: port: 5500-6850/tcp permanent: true state: enabled register: result -- name: assert firewalld port range test permanent enabled worked - assert: +- name: Assert firewalld port range test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld port range test permanent enabled rerun (verify not changed) - firewalld: +- name: Firewalld port range test permanent enabled rerun (verify not changed) + ansible.posix.firewalld: port: 5500-6850/tcp permanent: true state: enabled register: result -- name: assert firewalld port range test permanent enabled rerun worked (verify not changed) - assert: +- name: Assert firewalld port range test permanent enabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld port test permanent enabled - firewalld: +- name: Firewalld port test permanent enabled + ansible.posix.firewalld: port: 6900/tcp permanent: true state: enabled register: result -- name: assert firewalld port test permanent enabled worked - assert: +- name: Assert firewalld port test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld port test permanent enabled - firewalld: +- name: Firewalld port test permanent enabled + ansible.posix.firewalld: port: 6900/tcp permanent: true state: enabled register: result -- name: assert firewalld port test permanent enabled worked - assert: +- name: Assert firewalld port test permanent enabled worked + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld port test disabled - firewalld: +- name: Firewalld port test disabled + ansible.posix.firewalld: port: "{{ item }}" permanent: true state: disabled @@ -59,50 +60,50 @@ - 6900/tcp - 5500-6850/tcp -- name: firewalld port test permanent enabled - firewalld: +- name: Firewalld port test permanent enabled + ansible.posix.firewalld: port: 8081/tcp permanent: true state: enabled register: result -- name: assert firewalld port test permanent enabled worked - assert: +- name: Assert firewalld port test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld port test permanent enabled rerun (verify not changed) - firewalld: +- name: Firewalld port test permanent enabled rerun (verify not changed) + ansible.posix.firewalld: port: 8081/tcp permanent: true state: enabled register: result -- name: assert firewalld port test permanent enabled rerun worked (verify not changed) - assert: +- name: Assert firewalld port test permanent enabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld port test permanent disabled - firewalld: +- name: Firewalld port test permanent disabled + ansible.posix.firewalld: port: 8081/tcp permanent: true state: disabled register: result -- name: assert firewalld port test permanent disabled worked - assert: +- name: Assert firewalld port test permanent disabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld port test permanent disabled rerun (verify not changed) - firewalld: +- name: Firewalld port test permanent disabled rerun (verify not changed) + ansible.posix.firewalld: port: 8081/tcp permanent: true state: disabled register: result -- name: assert firewalld port test permanent disabled rerun worked (verify not changed) - assert: +- name: Assert firewalld port test permanent disabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml b/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml index 2af8921..996b3f1 100644 --- a/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/protocol_test_cases.yml @@ -1,3 +1,4 @@ +--- # Test playbook for the firewalld module - protocol operations # (c) 2022, Robért S. Guhr @@ -16,50 +17,50 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- name: firewalld protocol test permanent enabled - firewalld: +- name: Firewalld protocol test permanent enabled + ansible.posix.firewalld: protocol: ospf permanent: true state: enabled register: result -- name: assert firewalld protocol test permanent enabled worked - assert: +- name: Assert firewalld protocol test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld protocol test permanent enabled rerun (verify not changed) - firewalld: +- name: Firewalld protocol test permanent enabled rerun (verify not changed) + ansible.posix.firewalld: protocol: ospf permanent: true state: enabled register: result -- name: assert firewalld protocol test permanent enabled rerun worked (verify not changed) - assert: +- name: Assert firewalld protocol test permanent enabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld protocol test permanent disabled - firewalld: +- name: Firewalld protocol test permanent disabled + ansible.posix.firewalld: protocol: ospf permanent: true state: disabled register: result -- name: assert firewalld protocol test permanent disabled worked - assert: +- name: Assert firewalld protocol test permanent disabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld protocol test permanent disabled rerun (verify not changed) - firewalld: +- name: Firewalld protocol test permanent disabled rerun (verify not changed) + ansible.posix.firewalld: protocol: ospf permanent: true state: disabled register: result -- name: assert firewalld protocol test permanent disabled rerun worked (verify not changed) - assert: +- name: Assert firewalld protocol test permanent disabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/run_all_tests.yml b/tests/integration/targets/firewalld/tasks/run_all_tests.yml index e88b007..fa8c344 100644 --- a/tests/integration/targets/firewalld/tasks/run_all_tests.yml +++ b/tests/integration/targets/firewalld/tasks/run_all_tests.yml @@ -1,38 +1,50 @@ +--- # Test playbook for the firewalld module # (c) 2017, Adam Miller # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Ensure /run/firewalld exists - file: + ansible.builtin.file: path: /run/firewalld state: directory + mode: "0755" # firewalld service operation test cases -- include_tasks: service_test_cases.yml +- name: Include service test cases for firewalld module + ansible.builtin.include_tasks: service_test_cases.yml # firewalld protocol operation test cases -- include_tasks: protocol_test_cases.yml +- name: Include protocol test cases for firewalld module + ansible.builtin.include_tasks: protocol_test_cases.yml # firewalld port operation test cases -- include_tasks: port_test_cases.yml +- name: Include port test cases for firewalld module + ansible.builtin.include_tasks: port_test_cases.yml # firewalld source operation test cases -- include_tasks: source_test_cases.yml +- name: Include source test cases for firewalld module + ansible.builtin.include_tasks: source_test_cases.yml # firewalld zone operation test cases -- include_tasks: zone_test_cases.yml +- name: Include zone test cases for firewalld module + ansible.builtin.include_tasks: zone_test_cases.yml # firewalld zone target operation test cases -- include_tasks: zone_target_test_cases.yml +- name: Include zone target test cases for firewalld module + ansible.builtin.include_tasks: zone_target_test_cases.yml # firewalld port forwarding operation test cases -- include_tasks: port_forward_test_cases.yml +- name: Include port forward target test cases for firewalld module + ansible.builtin.include_tasks: port_forward_test_cases.yml # firewalld masquerade operation test cases -- include_tasks: masquerade_test_cases.yml +- name: Include masquerade target test cases for firewalld module + ansible.builtin.include_tasks: masquerade_test_cases.yml # firewalld icmp block inversion operation test cases -- include_tasks: icmp_block_inversion_test_cases.yml +- name: Include icmp block inversion target test cases for firewalld module + ansible.builtin.include_tasks: icmp_block_inversion_test_cases.yml # firewalld interface operation test cases -- include_tasks: interface_test_cases.yml +- name: Include interface target test cases for firewalld module + ansible.builtin.include_tasks: interface_test_cases.yml diff --git a/tests/integration/targets/firewalld/tasks/service_test_cases.yml b/tests/integration/targets/firewalld/tasks/service_test_cases.yml index 3c95d81..1286646 100644 --- a/tests/integration/targets/firewalld/tasks/service_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/service_test_cases.yml @@ -1,3 +1,4 @@ +--- # Test playbook for the firewalld module - service operations # (c) 2017, Adam Miller @@ -16,50 +17,50 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- name: firewalld service test permanent enabled - firewalld: +- name: Firewalld service test permanent enabled + ansible.posix.firewalld: service: https permanent: true state: enabled register: result -- name: assert firewalld service test permanent enabled worked - assert: +- name: Assert firewalld service test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld service test permanent enabled rerun (verify not changed) - firewalld: +- name: Firewalld service test permanent enabled rerun (verify not changed) + ansible.posix.firewalld: service: https permanent: true state: enabled register: result -- name: assert firewalld service test permanent enabled rerun worked (verify not changed) - assert: +- name: Assert firewalld service test permanent enabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld service test permanent disabled - firewalld: +- name: Firewalld service test permanent disabled + ansible.posix.firewalld: service: https permanent: true state: disabled register: result -- name: assert firewalld service test permanent disabled worked - assert: +- name: Assert firewalld service test permanent disabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld service test permanent disabled rerun (verify not changed) - firewalld: +- name: Firewalld service test permanent disabled rerun (verify not changed) + ansible.posix.firewalld: service: https permanent: true state: disabled register: result -- name: assert firewalld service test permanent disabled rerun worked (verify not changed) - assert: +- name: Assert firewalld service test permanent disabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/source_test_cases.yml b/tests/integration/targets/firewalld/tasks/source_test_cases.yml index 4bc8b65..a2552d5 100644 --- a/tests/integration/targets/firewalld/tasks/source_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/source_test_cases.yml @@ -1,3 +1,4 @@ +--- # Test playbook for the firewalld module - source operations # (c) 2019, Hideki Saito @@ -16,70 +17,71 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- name: firewalld source test permanent enabled - firewalld: +- name: Firewalld source test permanent enabled + ansible.posix.firewalld: source: 192.0.2.0/24 zone: internal - permanent: True + permanent: true state: enabled register: result -- name: assert firewalld source test permanent enabled worked - assert: +- name: Assert firewalld source test permanent enabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld source test permanent enabled rerun (verify not changed) - firewalld: +- name: Firewalld source test permanent enabled rerun (verify not changed) + ansible.posix.firewalld: source: 192.0.2.0/24 zone: internal - permanent: True + permanent: true state: enabled register: result -- name: assert firewalld source test permanent enabled rerun worked (verify not changed) - assert: +- name: Assert firewalld source test permanent enabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld source test permanent disabled - firewalld: +- name: Firewalld source test permanent disabled + ansible.posix.firewalld: source: 192.0.2.0/24 zone: internal - permanent: True + permanent: true state: disabled register: result -- name: assert firewalld source test permanent disabled worked - assert: +- name: Assert firewalld source test permanent disabled worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld source test permanent disabled rerun (verify not changed) - firewalld: +- name: Firewalld source test permanent disabled rerun (verify not changed) + ansible.posix.firewalld: source: 192.0.2.0/24 zone: internal - permanent: True + permanent: true state: disabled register: result -- name: assert firewalld source test permanent disabled rerun worked (verify not changed) - assert: +- name: Assert firewalld source test permanent disabled rerun worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld source test permanent enabled is exclusive (verify exclusive error) - firewalld: +- name: Firewalld source test permanent enabled is exclusive (verify exclusive error) + ansible.posix.firewalld: source: 192.0.2.0/24 port: 8081/tcp zone: internal - permanent: True + permanent: true state: enabled register: result ignore_errors: true -- name: assert firewalld source test permanent enabled is exclusive (verify exclusive error) - assert: +- name: Assert firewalld source test permanent enabled is exclusive (verify exclusive error) + ansible.builtin.assert: that: - - result is not changed - - "result.msg == 'parameters are mutually exclusive: icmp_block|icmp_block_inversion|service|protocol|port|port_forward|rich_rule|interface|masquerade|source|target'" + - result is not changed + - "result.msg == + 'parameters are mutually exclusive: icmp_block|icmp_block_inversion|service|protocol|port|port_forward|rich_rule|interface|masquerade|source|target'" diff --git a/tests/integration/targets/firewalld/tasks/zone_target_test_cases.yml b/tests/integration/targets/firewalld/tasks/zone_target_test_cases.yml index 085762a..324165d 100644 --- a/tests/integration/targets/firewalld/tasks/zone_target_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/zone_target_test_cases.yml @@ -1,3 +1,4 @@ +--- # Test playbook for the firewalld module - source operations # (c) 2020, Adam Miller @@ -16,106 +17,106 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- name: firewalld dmz zone target DROP - firewalld: +- name: Firewalld dmz zone target DROP + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: present target: DROP register: result -- name: assert firewalld dmz zone target DROP present worked - assert: +- name: Assert firewalld dmz zone target DROP present worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld dmz zone target DROP rerun (verify not changed) - firewalld: +- name: Firewalld dmz zone target DROP rerun (verify not changed) + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: present target: DROP register: result -- name: assert firewalld dmz zone target DROP present worked (verify not changed) - assert: +- name: Assert firewalld dmz zone target DROP present worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld dmz zone target DROP absent - firewalld: +- name: Firewalld dmz zone target DROP absent + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: absent target: DROP register: result -- name: assert firewalld dmz zone target DROP absent worked - assert: +- name: Assert firewalld dmz zone target DROP absent worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld dmz zone target DROP rerun (verify not changed) - firewalld: +- name: Firewalld dmz zone target DROP rerun (verify not changed) + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: absent target: DROP register: result -- name: assert firewalld dmz zone target DROP present worked (verify not changed) - assert: +- name: Assert firewalld dmz zone target DROP present worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld dmz zone target %%REJECT%% - firewalld: +- name: Firewalld dmz zone target %%REJECT%% + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: present - target: '%%REJECT%%' + target: "%%REJECT%%" register: result -- name: assert firewalld dmz zone target %%REJECT%% present worked - assert: +- name: Assert firewalld dmz zone target %%REJECT%% present worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld dmz zone target %%REJECT%% rerun (verify not changed) - firewalld: +- name: Firewalld dmz zone target %%REJECT%% rerun (verify not changed) + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: present - target: '%%REJECT%%' + target: "%%REJECT%%" register: result -- name: assert firewalld dmz zone target %%REJECT%% present worked (verify not changed) - assert: +- name: Assert firewalld dmz zone target %%REJECT%% present worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld dmz zone target %%REJECT%% absent - firewalld: +- name: Firewalld dmz zone target %%REJECT%% absent + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: absent - target: '%%REJECT%%' + target: "%%REJECT%%" register: result -- name: assert firewalld dmz zone target %%REJECT%% absent worked - assert: +- name: Assert firewalld dmz zone target %%REJECT%% absent worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld dmz zone target %%REJECT%% rerun (verify not changed) - firewalld: +- name: Firewalld dmz zone target %%REJECT%% rerun (verify not changed) + ansible.posix.firewalld: zone: dmz - permanent: True + permanent: true state: absent - target: '%%REJECT%%' + target: "%%REJECT%%" register: result -- name: assert firewalld dmz zone target %%REJECT%% present worked (verify not changed) - assert: +- name: Assert firewalld dmz zone target %%REJECT%% present worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed \ No newline at end of file + - result is not changed diff --git a/tests/integration/targets/firewalld/tasks/zone_test_cases.yml b/tests/integration/targets/firewalld/tasks/zone_test_cases.yml index c9d54c6..753dd18 100644 --- a/tests/integration/targets/firewalld/tasks/zone_test_cases.yml +++ b/tests/integration/targets/firewalld/tasks/zone_test_cases.yml @@ -1,47 +1,48 @@ -- name: firewalld create zone custom - firewalld: +--- +- name: Firewalld create zone custom + ansible.posix.firewalld: zone: custom - permanent: True + permanent: true state: present register: result -- name: assert firewalld custom zone created worked - assert: +- name: Assert firewalld custom zone created worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld create zone custom rerun (verify not changed) - firewalld: +- name: Firewalld create zone custom rerun (verify not changed) + ansible.posix.firewalld: zone: custom - permanent: True + permanent: true state: present register: result -- name: assert firewalld custom zone created worked (verify not changed) - assert: +- name: Assert firewalld custom zone created worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: firewalld remove zone custom - firewalld: +- name: Firewalld remove zone custom + ansible.posix.firewalld: zone: custom - permanent: True + permanent: true state: absent register: result -- name: assert firewalld custom zone removed worked - assert: +- name: Assert firewalld custom zone removed worked + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: firewalld remove custom zone rerun (verify not changed) - firewalld: +- name: Firewalld remove custom zone rerun (verify not changed) + ansible.posix.firewalld: zone: custom - permanent: True + permanent: true state: absent register: result -- name: assert firewalld custom zone removed worked (verify not changed) - assert: +- name: Assert firewalld custom zone removed worked (verify not changed) + ansible.builtin.assert: that: - - result is not changed + - result is not changed diff --git a/tests/integration/targets/firewalld_info/tasks/main.yml b/tests/integration/targets/firewalld_info/tasks/main.yml index bce6b54..58c7fc8 100644 --- a/tests/integration/targets/firewalld_info/tasks/main.yml +++ b/tests/integration/targets/firewalld_info/tasks/main.yml @@ -1,52 +1,53 @@ +--- # Test playbook for the firewalld_info module # (c) 2021, Hideki Saito # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # This test is based on the integration test playbook for firewalld module. - name: Run firewalld tests + when: + - ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=') + - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '==')) + # Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros + - not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3) block: - name: Ensure firewalld is installed - package: + ansible.builtin.package: name: firewalld state: present - # This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6 + # This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6 - name: Check to make sure the firewalld python module is available. - shell: "{{ansible_python.executable}} -c 'import firewall'" + ansible.builtin.command: "{{ ansible_python.executable }} -c 'import firewall'" + changed_when: false register: check_output_firewall ignore_errors: true - name: Check to make sure the dbus python module is available. - shell: "{{ansible_python.executable}} -c 'import dbus'" + ansible.builtin.command: "{{ ansible_python.executable }} -c 'import dbus'" + changed_when: false register: check_output_dbus ignore_errors: true - name: Test Online Operations block: - - name: start firewalld - service: + - name: Start firewalld + ansible.builtin.service: name: firewalld state: started - - import_tasks: run_tests_in_started.yml + - name: Import test tasks from run_tests_in_started.yml + ansible.builtin.import_tasks: run_tests_in_started.yml + + - name: Test Offline Operations when: - check_output_firewall.rc == 0 - check_output_dbus.rc == 0 - - - name: Test Offline Operations block: - - name: stop firewalld - service: + - name: Stop firewalld + ansible.builtin.service: name: firewalld state: stopped - - import_tasks: run_tests_in_stopped.yml - when: - - check_output_firewall.rc == 0 - - check_output_dbus.rc == 0 - - when: - - ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=') - - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '==')) - # Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros - - not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3) + - name: Import test tasks from run_tests_in_stopped.yml + ansible.builtin.import_tasks: run_tests_in_stopped.yml diff --git a/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml b/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml index 5024884..3b73845 100644 --- a/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml +++ b/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml @@ -1,32 +1,33 @@ +--- # Test playbook for the firewalld_info module # (c) 2021, Hideki Saito # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Ensure firewalld_info without options - firewalld_info: + ansible.posix.firewalld_info: register: result - name: Assert collected_zones and undefined_zones - assert: + ansible.builtin.assert: that: - - 'result.collected_zones and not result.undefined_zones' + - result.collected_zones and not result.undefined_zones - name: Ensure firewalld_info with active_zones - firewalld_info: - active_zones: yes + ansible.posix.firewalld_info: + active_zones: true register: result - name: Assert turn active_zones true - assert: + ansible.builtin.assert: that: - name: Ensure firewalld_zones with zone list - firewalld_info: + ansible.posix.firewalld_info: zones: - public - invalid_zone register: result - name: Assert specified zones - assert: + ansible.builtin.assert: that: diff --git a/tests/integration/targets/firewalld_info/tasks/run_tests_in_stopped.yml b/tests/integration/targets/firewalld_info/tasks/run_tests_in_stopped.yml index 2ad4c0c..175041c 100644 --- a/tests/integration/targets/firewalld_info/tasks/run_tests_in_stopped.yml +++ b/tests/integration/targets/firewalld_info/tasks/run_tests_in_stopped.yml @@ -1,40 +1,41 @@ +--- # Test playbook for the firewalld_info module # (c) 2021, Hideki Saito # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - name: Ensure firewalld_info without options - firewalld_info: + ansible.posix.firewalld_info: register: result - ignore_errors: yes + ignore_errors: true - name: Assert firewalld_info fails if firewalld is not running. - assert: + ansible.builtin.assert: that: - result.failed - "'firewalld probably not be running,' in result.msg" - name: Ensure firewalld_info with active_zones - firewalld_info: - active_zones: yes + ansible.posix.firewalld_info: + active_zones: true register: result - ignore_errors: yes + ignore_errors: true - name: Assert firewalld_info with active_zones fails if firewalld is not running. - assert: + ansible.builtin.assert: that: - result.failed - "'firewalld probably not be running,' in result.msg" - name: Ensure firewalld_zones with zone list - firewalld_info: + ansible.posix.firewalld_info: zones: - public - invalid_zone register: result - ignore_errors: yes + ignore_errors: true - name: Assert firewalld_info with zones list fails if firewalld is not running. - assert: + ansible.builtin.assert: that: - result.failed - "'firewalld probably not be running,' in result.msg" diff --git a/tests/integration/targets/mount/tasks/main.yml b/tests/integration/targets/mount/tasks/main.yml index 7b0d141..58eace8 100644 --- a/tests/integration/targets/mount/tasks/main.yml +++ b/tests/integration/targets/mount/tasks/main.yml @@ -1,29 +1,117 @@ -- name: Install dependencies +- name: Install dependencies (Linux) ansible.builtin.package: name: e2fsprogs state: present when: ansible_system == 'Linux' +- name: Install dependencies (FreeBSD) + ansible.builtin.package: + name: bash + state: present + +- name: Register facts on Linux + ansible.builtin.set_fact: + shell_executable: /bin/bash + ephemeral_device_a: /tmp/myfs_A.img + ephemeral_device_b: /tmp/myfs_B.img + ephemeral_fstype: ext3 + ephemeral_fstab: /etc/fstab + when: ansible_system == 'Linux' + +- name: Register facts on Solaris/SunOS + ansible.builtin.set_fact: + shell_executable: /usr/bin/bash + ephemeral_device_a: /dev/lofi/1 + ephemeral_device_b: /dev/lofi/2 + ephemeral_create_loop_dev_cmd: >- + lofiadm -a /tmp/myfs_A.img /dev/lofi/1 && + lofiadm -a /tmp/myfs_B.img /dev/lofi/2 + ephemeral_remove_loop_dev_cmd: >- + lofiadm -d /dev/lofi/1 && + lofiadm -d /dev/lofi/2 || true + ephemeral_fstype: ufs + ephemeral_fstab: /etc/vfstab + when: ansible_system == 'SunOS' + +- name: Register facts on FreeBSD + ansible.builtin.set_fact: + shell_executable: /usr/local/bin/bash + ephemeral_device_a: /dev/md1 + ephemeral_device_b: /dev/md2 + ephemeral_create_loop_dev_cmd: >- + mdconfig -a -t vnode -f /tmp/myfs_A.img -u /dev/md1 && + mdconfig -a -t vnode -f /tmp/myfs_B.img -u /dev/md2 + ephemeral_remove_loop_dev_cmd: >- + mdconfig -d -u /dev/md1 && + mdconfig -d -u /dev/md2 + ephemeral_fstype: ufs + ephemeral_fstab: /etc/fstab + when: ansible_system == 'FreeBSD' + +- name: Register facts on NetBSD + ansible.builtin.set_fact: + shell_executable: /usr/local/bin/bash + ephemeral_device_a: /dev/vnd1 + ephemeral_device_b: /dev/vnd2 + ephemeral_create_loop_dev_cmd: >- + vnconfig /dev/vnd1 /tmp/myfs_A.img && + vnconfig /dev/vnd2 /tmp/myfs_B.img + ephemeral_remove_loop_dev_cmd: >- + vnconfig -u /dev/vnd1 && + vnconfig -u /dev/vnd2 + ephemeral_fstype: ufs + ephemeral_fstab: /etc/fstab + when: ansible_system == 'NetBSD' + +- name: Register format fs command on Non-Linux and Non-OpenBSD + ansible.builtin.set_fact: + ephemeral_format_fs_cmd: >- + newfs {{ ephemeral_device_a }} && + newfs {{ ephemeral_device_b }} + when: ansible_system in ('SunOS', 'FreeBSD', 'NetBSD') + +- name: Register facts on OpenBSD + ansible.builtin.set_fact: + shell_executable: /usr/local/bin/bash + ephemeral_device_a: /dev/vnd1c + ephemeral_device_b: /dev/vnd2c + ephemeral_create_loop_dev_cmd: >- + vnconfig vnd1 /tmp/myfs_A.img && + vnconfig vnd2 /tmp/myfs_B.img + ephemeral_remove_loop_dev_cmd: >- + vnconfig -u vnd1 && + vnconfig -u vnd2 + ephemeral_format_fs_cmd: >- + newfs /dev/rvnd1c && + newfs /dev/rvnd2c + ephemeral_fstype: ffs + ephemeral_fstab: /etc/fstab + when: ansible_system == 'OpenBSD' + + - name: Create the mount point - file: + ansible.builtin.file: state: directory path: '{{ output_dir }}/mount_dest' + mode: '0755' - name: Create a directory to bind mount - file: + ansible.builtin.file: state: directory path: '{{ output_dir }}/mount_source' + mode: '0755' - name: Put something in the directory so we see that it worked - copy: + ansible.builtin.copy: content: 'Testing ' dest: '{{ output_dir }}/mount_source/test_file' + mode: '0644' register: orig_info - name: Bind mount a filesystem (Linux) - mount: + ansible.posix.mount: src: '{{ output_dir }}/mount_source' name: '{{ output_dir }}/mount_dest' state: mounted @@ -33,7 +121,7 @@ register: bind_result_linux - name: Bind mount a filesystem (FreeBSD) - mount: + ansible.posix.mount: src: '{{ output_dir }}/mount_source' name: '{{ output_dir }}/mount_dest' state: mounted @@ -41,22 +129,22 @@ when: ansible_system == 'FreeBSD' register: bind_result_freebsd -- name: get checksum for bind mounted file - stat: +- name: Get checksum for bind mounted file + ansible.builtin.stat: path: '{{ output_dir }}/mount_dest/test_file' when: ansible_system in ('FreeBSD', 'Linux') register: dest_stat -- name: assert the bind mount was successful - assert: +- name: Assert the bind mount was successful + ansible.builtin.assert: that: - - (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed']) - - dest_stat['stat']['exists'] - - orig_info['checksum'] == dest_stat['stat']['checksum'] + - (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed']) + - dest_stat['stat']['exists'] + - orig_info['checksum'] == dest_stat['stat']['checksum'] when: ansible_system in ('FreeBSD', 'Linux') - name: Bind mount a filesystem (Linux) - mount: + ansible.posix.mount: src: '{{ output_dir }}/mount_source' name: '{{ output_dir }}/mount_dest' state: mounted @@ -66,7 +154,7 @@ register: bind_result_linux - name: Bind mount a filesystem (FreeBSD) - mount: + ansible.posix.mount: src: '{{ output_dir }}/mount_source' name: '{{ output_dir }}/mount_dest' state: mounted @@ -75,13 +163,13 @@ register: bind_result_freebsd - name: Make sure we didn't mount a second time - assert: + ansible.builtin.assert: that: - - (ansible_system == 'Linux' and not bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and not bind_result_freebsd['changed']) + - (ansible_system == 'Linux' and not bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and not bind_result_freebsd['changed']) when: ansible_system in ('FreeBSD', 'Linux') - name: Remount filesystem with different opts (Linux) - mount: + ansible.posix.mount: src: '{{ output_dir }}/mount_source' name: '{{ output_dir }}/mount_dest' state: mounted @@ -91,7 +179,7 @@ register: bind_result_linux - name: Remount filesystem with different opts (FreeBSD) - mount: + ansible.posix.mount: src: '{{ output_dir }}/mount_source' name: '{{ output_dir }}/mount_dest' state: mounted @@ -101,581 +189,553 @@ register: bind_result_freebsd - name: Get mount options - shell: mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l + ansible.builtin.shell: + cmd: set -o pipefail && mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l + executable: "{{ shell_executable }}" + changed_when: false register: remount_options - name: Make sure the filesystem now has the new opts - assert: + ansible.builtin.assert: that: - - (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed']) - - '''1'' in remount_options.stdout' - - 1 == remount_options.stdout_lines | length + - (ansible_system == 'Linux' and bind_result_linux['changed']) or (ansible_system == 'FreeBSD' and bind_result_freebsd['changed']) + - '''1'' in remount_options.stdout' + - 1 == remount_options.stdout_lines | length when: ansible_system in ('FreeBSD', 'Linux') - name: Unmount the bind mount - mount: + ansible.posix.mount: name: '{{ output_dir }}/mount_dest' state: absent when: ansible_system in ('Linux', 'FreeBSD') register: unmount_result - name: Make sure the file no longer exists in dest - stat: + ansible.builtin.stat: path: '{{ output_dir }}/mount_dest/test_file' when: ansible_system in ('FreeBSD', 'Linux') register: dest_stat - name: Check that we unmounted - assert: + ansible.builtin.assert: that: - - unmount_result['changed'] - - not dest_stat['stat']['exists'] + - unmount_result['changed'] + - not dest_stat['stat']['exists'] when: ansible_system in ('FreeBSD', 'Linux') - name: Block to test remounted option + when: ansible_system in ('Linux') block: - - name: Create fstab record for the first swap file - mount: - name: none - src: /tmp/swap1 - opts: sw - fstype: swap - state: present - register: swap1_created + - name: Create fstab record for the first swap file + ansible.posix.mount: + name: none + src: /tmp/swap1 + opts: sw + fstype: swap + state: present + register: swap1_created - - name: Try to create fstab record for the first swap file again - mount: - name: none - src: /tmp/swap1 - opts: sw - fstype: swap - state: present - register: swap1_created_again + - name: Try to create fstab record for the first swap file again + ansible.posix.mount: + name: none + src: /tmp/swap1 + opts: sw + fstype: swap + state: present + register: swap1_created_again - - name: Check that we created the swap1 record - assert: - that: - - swap1_created['changed'] - - not swap1_created_again['changed'] + - name: Check that we created the swap1 record + ansible.builtin.assert: + that: + - swap1_created['changed'] + - not swap1_created_again['changed'] - - name: Create fstab record for the second swap file - mount: - name: none - src: /tmp/swap2 - opts: sw - fstype: swap - state: present - register: swap2_created + - name: Create fstab record for the second swap file + ansible.posix.mount: + name: none + src: /tmp/swap2 + opts: sw + fstype: swap + state: present + register: swap2_created - - name: Try to create fstab record for the second swap file again - mount: - name: none - src: /tmp/swap1 - opts: sw - fstype: swap - state: present - register: swap2_created_again + - name: Try to create fstab record for the second swap file again + ansible.posix.mount: + name: none + src: /tmp/swap2 + opts: sw + fstype: swap + state: present + register: swap2_created_again - - name: Check that we created the swap2 record - assert: - that: - - swap2_created['changed'] - - not swap2_created_again['changed'] + - name: Check that we created the swap2 record + ansible.builtin.assert: + that: + - swap2_created['changed'] + - not swap2_created_again['changed'] - - name: Remove the fstab record for the first swap file - mount: - name: none - src: /tmp/swap1 - state: absent - register: swap1_removed + - name: Remove the fstab record for the first swap file + ansible.posix.mount: + name: none + src: /tmp/swap1 + state: absent + register: swap1_removed - - name: Try to remove the fstab record for the first swap file again - mount: - name: none - src: /tmp/swap1 - state: absent - register: swap1_removed_again + - name: Try to remove the fstab record for the first swap file again + ansible.posix.mount: + name: none + src: /tmp/swap1 + state: absent + register: swap1_removed_again - - name: Check that we removed the swap1 record - assert: - that: - - swap1_removed['changed'] - - not swap1_removed_again['changed'] + - name: Check that we removed the swap1 record + ansible.builtin.assert: + that: + - swap1_removed['changed'] + - not swap1_removed_again['changed'] - - name: Remove the fstab record for the second swap file - mount: - name: none - src: /tmp/swap2 - state: absent - register: swap2_removed + - name: Remove the fstab record for the second swap file + ansible.posix.mount: + name: none + src: /tmp/swap2 + state: absent + register: swap2_removed - - name: Try to remove the fstab record for the second swap file again - mount: - name: none - src: /tmp/swap2 - state: absent - register: swap2_removed_again + - name: Try to remove the fstab record for the second swap file again + ansible.posix.mount: + name: none + src: /tmp/swap2 + state: absent + register: swap2_removed_again - - name: Check that we removed the swap2 record - assert: - that: - - swap2_removed['changed'] - - not swap2_removed_again['changed'] + - name: Check that we removed the swap2 record + ansible.builtin.assert: + that: + - swap2_removed['changed'] + - not swap2_removed_again['changed'] - - name: Create fstab record with missing last two fields - copy: - dest: /etc/fstab - content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev + - name: Create fstab record with missing last two fields + ansible.builtin.copy: + dest: /etc/fstab + content: '//nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev - ' + ' + mode: "0644" - - name: Try to change the fstab record with the missing last two fields - mount: - src: //nas/photo - path: /home/jik/pictures - fstype: cifs - opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 - state: present - register: optional_fields_update + - name: Try to change the fstab record with the missing last two fields + ansible.posix.mount: + src: //nas/photo + path: /home/jik/pictures + fstype: cifs + opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0 + state: present + register: optional_fields_update - - name: Get the content of the fstab file - shell: cat /etc/fstab - register: optional_fields_content + - name: Get the content of the fstab file + ansible.builtin.command: cat /etc/fstab + changed_when: false + register: optional_fields_content - - name: Check if the line containing the missing last two fields was changed - assert: - that: - - optional_fields_update['changed'] - - ''' 0 0'' in optional_fields_content.stdout' - - 1 == optional_fields_content.stdout_lines | length + - name: Check if the line containing the missing last two fields was changed + ansible.builtin.assert: + that: + - optional_fields_update['changed'] + - ''' 0 0'' in optional_fields_content.stdout' + - 1 == optional_fields_content.stdout_lines | length - - name: Create empty file - community.general.filesize: - path: /tmp/myfs.img - size: 20M + - name: Create empty file + community.general.filesize: + path: /tmp/myfs.img + size: 20M - - name: Format FS - community.general.filesystem: - fstype: ext3 - dev: /tmp/myfs.img + - name: Format FS + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs.img - - name: Mount the FS for the first time - mount: - path: /tmp/myfs - src: /tmp/myfs.img - fstype: ext2 - state: mounted + - name: Mount the FS for the first time + ansible.posix.mount: + path: /tmp/myfs + src: /tmp/myfs.img + fstype: ext2 + state: mounted - - name: Get the last write time - shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' - register: last_write_time + - name: Get the last write time + ansible.builtin.shell: + cmd: >- + set -o pipefail && dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i "last write time:" | cut -d: -f2- + executable: "{{ shell_executable }}" + changed_when: false + register: last_write_time - - name: Wait 2 second - pause: - seconds: 2 + - name: Wait 2 second + ansible.builtin.pause: + seconds: 2 - - name: Test if the FS is remounted - mount: - path: /tmp/myfs - state: remounted + - name: Test if the FS is remounted + ansible.posix.mount: + path: /tmp/myfs + state: remounted - - name: Get again the last write time - shell: 'dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last write time: |cut -d: -f2-' - register: last_write_time2 + - name: Get again the last write time + ansible.builtin.shell: + cmd: >- + set -o pipefail && dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i "last write time:" |cut -d: -f2- + executable: "{{ shell_executable }}" + changed_when: false + register: last_write_time2 - - name: Fail if they are the same - fail: - msg: Filesytem was not remounted, testing of the module failed! - when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout + - name: Fail if they are the same + ansible.builtin.fail: + msg: Filesytem was not remounted, testing of the module failed! + when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout - - name: Remount filesystem with different opts using remounted option (Linux only) - mount: - path: /tmp/myfs - state: remounted - opts: rw,noexec + - name: Remount filesystem with different opts using remounted option (Linux only) + ansible.posix.mount: + path: /tmp/myfs + state: remounted + opts: rw,noexec - - name: Get remounted options (Linux only) - shell: mount | grep myfs | grep -E -w 'noexec' | wc -l - register: remounted_options + - name: Get remounted options (Linux only) + ansible.builtin.shell: + cmd: set -o pipefail && mount | grep myfs | grep -E -w 'noexec' | wc -l + executable: "{{ shell_executable }}" + changed_when: false + register: remounted_options - - name: Make sure the filesystem now has the new opts after using remounted (Linux only) - assert: - that: - - "'1' in remounted_options.stdout" - - "1 == remounted_options.stdout_lines | length" + - name: Make sure the filesystem now has the new opts after using remounted (Linux only) + ansible.builtin.assert: + that: + - "'1' in remounted_options.stdout" + - "1 == remounted_options.stdout_lines | length" - - name: Mount the FS again to test backup - mount: - path: /tmp/myfs - src: /tmp/myfs.img - fstype: ext2 - state: mounted - backup: yes - register: mount_backup_out + - name: Mount the FS again to test backup + ansible.posix.mount: + path: /tmp/myfs + src: /tmp/myfs.img + fstype: ext2 + state: mounted + backup: true + register: mount_backup_out - - name: ensure backup_file in returned output - assert: - that: - - "'backup_file' in mount_backup_out" + - name: Ensure backup_file in returned output + ansible.builtin.assert: + that: + - "'backup_file' in mount_backup_out" always: - - name: Umount the test FS - mount: - path: /tmp/myfs - src: /tmp/myfs.img - opts: loop - state: absent + - name: Umount the test FS + ansible.posix.mount: + path: /tmp/myfs + src: /tmp/myfs.img + opts: loop + state: absent - - name: Remove the test FS - file: - path: '{{ item }}' - state: absent - loop: - - /tmp/myfs.img - - /tmp/myfs - when: ansible_system in ('Linux') + - name: Remove the test FS + ansible.builtin.file: + path: '{{ item }}' + state: absent + loop: + - /tmp/myfs.img + - /tmp/myfs - name: Block to test boot option for Linux - block: - - name: Create empty file - community.general.filesize: - path: /tmp/myfs.img - size: 20M - - - name: Format FS - community.general.filesystem: - fstype: ext3 - dev: /tmp/myfs.img - - - name: Mount the FS with noauto option - mount: - path: /tmp/myfs - src: /tmp/myfs.img - fstype: ext3 - state: mounted - boot: no - opts: rw,user,async - register: mount_info - - - name: assert the mount without noauto was successful - assert: - that: - - mount_info['opts'] == 'rw,user,async,noauto' - - - name: Unmount FS - mount: - path: /tmp/myfs - state: absent - - - name: Remove the test FS - file: - path: '{{ item }}' - state: absent - loop: - - /tmp/myfs.img - - /tmp/myfs when: ansible_system in ('Linux') + block: + - name: Create empty file + community.general.filesize: + path: /tmp/myfs.img + size: 20M + + - name: Format FS + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs.img + + - name: Mount the FS with noauto option + ansible.posix.mount: + path: /tmp/myfs + src: /tmp/myfs.img + fstype: ext3 + state: mounted + boot: false + opts: rw,user,async + register: mount_info + + - name: Assert the mount without noauto was successful + ansible.builtin.assert: + that: + - mount_info['opts'] == 'rw,user,async,noauto' + + - name: Unmount FS + ansible.posix.mount: + path: /tmp/myfs + state: absent + + - name: Remove the test FS + ansible.builtin.file: + path: '{{ item }}' + state: absent + loop: + - /tmp/myfs.img + - /tmp/myfs - name: Block to test missing newline at the EOF of fstab - block: - - name: Create empty file - community.general.filesize: - path: /tmp/myfs1.img - size: 20M - - name: Format FS - community.general.filesystem: - fstype: ext3 - dev: /tmp/myfs1.img - - name: Create custom fstab file without newline - copy: - content: '#TEST COMMENT WITHOUT NEWLINE' - dest: /tmp/test_fstab - - name: Mount the FS using the custom fstab - mount: - path: /tmp/myfs1 - src: /tmp/myfs1.img - fstype: ext3 - state: mounted - opts: defaults - fstab: /tmp/test_fstab - - name: Unmount the mount point in the custom fstab - mount: - path: /tmp/myfs1 - state: absent - fstab: /tmp/test_fstab - - name: Remove the test FS and the custom fstab - file: - path: '{{ item }}' - state: absent - loop: - - /tmp/myfs1.img - - /tmp/myfs1 - - /tmp/test_fstab when: ansible_system in ('Linux') + block: + - name: Create empty file + community.general.filesize: + path: /tmp/myfs1.img + size: 20M + - name: Format FS + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs1.img + - name: Create custom fstab file without newline + ansible.builtin.copy: + content: '#TEST COMMENT WITHOUT NEWLINE' + dest: /tmp/test_fstab + mode: "0644" + - name: Mount the FS using the custom fstab + ansible.posix.mount: + path: /tmp/myfs1 + src: /tmp/myfs1.img + fstype: ext3 + state: mounted + opts: defaults + fstab: /tmp/test_fstab + - name: Unmount the mount point in the custom fstab + ansible.posix.mount: + path: /tmp/myfs1 + state: absent + fstab: /tmp/test_fstab + - name: Remove the test FS and the custom fstab + ansible.builtin.file: + path: '{{ item }}' + state: absent + loop: + - /tmp/myfs1.img + - /tmp/myfs1 + - /tmp/test_fstab - name: Block to test ephemeral option environment: PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + when: ansible_system in ('Linux', 'SunOS', 'FreeBSD', 'NetBSD', 'OpenBSD') block: - - name: Create empty file A - community.general.filesize: - path: /tmp/myfs_A.img - size: 20M + - name: Create empty file A + community.general.filesize: + path: /tmp/myfs_A.img + size: 20M - - name: Create empty file B - community.general.filesize: - path: /tmp/myfs_B.img - size: 20M + - name: Create empty file B + community.general.filesize: + path: /tmp/myfs_B.img + size: 20M - - name: Register facts on Linux - ansible.builtin.set_fact: - ephemeral_device_A: /tmp/myfs_A.img - ephemeral_device_B: /tmp/myfs_B.img - ephemeral_fstype: ext3 - ephemeral_fstab: /etc/fstab - when: ansible_system == 'Linux' + ##### FORMAT FS ON LINUX - - name: Register facts on Solaris/SunOS - ansible.builtin.set_fact: - ephemeral_device_A: /dev/lofi/1 - ephemeral_device_B: /dev/lofi/2 - ephemeral_create_loop_dev_cmd: > - lofiadm -a /tmp/myfs_A.img /dev/lofi/1 && - lofiadm -a /tmp/myfs_B.img /dev/lofi/2 - ephemeral_remove_loop_dev_cmd: > - lofiadm -d /dev/lofi/1 && - lofiadm -d /dev/lofi/2 || true - ephemeral_fstype: ufs - ephemeral_fstab: /etc/vfstab - when: ansible_system == 'SunOS' + - name: Block to format FS on Linux + when: ansible_system == 'Linux' + block: + - name: Format FS A on Linux + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs_A.img - - name: Register facts on FreeBSD - ansible.builtin.set_fact: - ephemeral_device_A: /dev/md1 - ephemeral_device_B: /dev/md2 - ephemeral_create_loop_dev_cmd: > - mdconfig -a -t vnode -f /tmp/myfs_A.img -u /dev/md1 && - mdconfig -a -t vnode -f /tmp/myfs_B.img -u /dev/md2 - ephemeral_remove_loop_dev_cmd: > - mdconfig -d -u /dev/md1 && - mdconfig -d -u /dev/md2 - ephemeral_fstype: ufs - ephemeral_fstab: /etc/fstab - when: ansible_system == 'FreeBSD' + - name: Format FS B on Linux + community.general.filesystem: + fstype: ext3 + dev: /tmp/myfs_B.img - - name: Register facts on NetBSD - ansible.builtin.set_fact: - ephemeral_device_A: /dev/vnd1 - ephemeral_device_B: /dev/vnd2 - ephemeral_create_loop_dev_cmd: > - vnconfig /dev/vnd1 /tmp/myfs_A.img && - vnconfig /dev/vnd2 /tmp/myfs_B.img - ephemeral_remove_loop_dev_cmd: > - vnconfig -u /dev/vnd1 && - vnconfig -u /dev/vnd2 - ephemeral_fstype: ufs - ephemeral_fstab: /etc/fstab - when: ansible_system == 'NetBSD' + ##### FORMAT FS ON SOLARIS AND BSD - - name: Register format fs command on Non-Linux and Non-OpenBSD - ansible.builtin.set_fact: - ephemeral_format_fs_cmd: > - yes | newfs {{ ephemeral_device_A }} && - yes | newfs {{ ephemeral_device_B }} - when: ansible_system in ('SunOS', 'FreeBSD', 'NetBSD') + - name: Create loop devices on Solaris and BSD + ansible.builtin.shell: + cmd: "set -o pipefail && {{ ephemeral_create_loop_dev_cmd }}" + executable: "{{ shell_executable }}" + changed_when: true + when: ephemeral_create_loop_dev_cmd is defined - - name: Register facts on OpenBSD - ansible.builtin.set_fact: - ephemeral_device_A: /dev/vnd1c - ephemeral_device_B: /dev/vnd2c - ephemeral_create_loop_dev_cmd: > - vnconfig vnd1 /tmp/myfs_A.img && - vnconfig vnd2 /tmp/myfs_B.img - ephemeral_remove_loop_dev_cmd: > - vnconfig -u vnd1 && - vnconfig -u vnd2 - ephemeral_format_fs_cmd: > - yes | newfs /dev/rvnd1c && - yes | newfs /dev/rvnd2c - ephemeral_fstype: ffs - ephemeral_fstab: /etc/fstab - when: ansible_system == 'OpenBSD' + - name: Format FS A and B on Solaris and BSD + ansible.builtin.shell: + cmd: "set -o pipefail && {{ ephemeral_format_fs_cmd }}" + executable: "{{ shell_executable }}" + changed_when: true + when: ephemeral_format_fs_cmd is defined -##### FORMAT FS ON LINUX + ##### TESTS - - name: Block to format FS on Linux - block: - - name: Format FS A on Linux - community.general.filesystem: - fstype: ext3 - dev: /tmp/myfs_A.img + - name: Create fstab if it does not exist + ansible.builtin.file: + path: "{{ ephemeral_fstab }}" + state: touch + mode: '0644' - - name: Format FS B on Linux - community.general.filesystem: - fstype: ext3 - dev: /tmp/myfs_B.img - when: ansible_system == 'Linux' + - name: Get checksum of /etc/fstab before mounting anything + ansible.builtin.stat: + path: '{{ ephemeral_fstab }}' + register: fstab_stat_before_mount -##### FORMAT FS ON SOLARIS AND BSD + - name: Mount the FS A with ephemeral state + ansible.posix.mount: + path: /tmp/myfs + src: '{{ ephemeral_device_a }}' + fstype: '{{ ephemeral_fstype }}' + opts: rw + state: ephemeral + register: ephemeral_mount_info - - name: Create loop devices on Solaris and BSD - ansible.builtin.shell: "{{ ephemeral_create_loop_dev_cmd }}" - when: ephemeral_create_loop_dev_cmd is defined + - name: Put something in the directory so we can do additional checks later on + ansible.builtin.copy: + content: 'Testing' + dest: /tmp/myfs/test_file + mode: '0644' - - name: Format FS A and B on Solaris and BSD - ansible.builtin.shell: "{{ ephemeral_format_fs_cmd }}" - when: ephemeral_format_fs_cmd is defined + - name: Get checksum of /etc/fstab after an ephemeral mount + ansible.builtin.stat: + path: '{{ ephemeral_fstab }}' + register: fstab_stat_after_mount -##### TESTS + - name: Get mountinfo + ansible.builtin.shell: + cmd: grep -c '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + register: check_mountinfo + failed_when: false + changed_when: false - - name: Create fstab if it does not exist - ansible.builtin.file: - path: "{{ ephemeral_fstab }}" - state: touch + - name: Assert the mount occured and the fstab is unchanged + ansible.builtin.assert: + that: + - check_mountinfo.stdout|int == 1 + - ephemeral_mount_info['changed'] + - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_mount['stat']['checksum'] - - name: Get checksum of /etc/fstab before mounting anything - stat: - path: '{{ ephemeral_fstab }}' - register: fstab_stat_before_mount + - name: Get first mount record + ansible.builtin.shell: + cmd: grep '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + register: ephemeral_mount_record_1 + changed_when: false - - name: Mount the FS A with ephemeral state - mount: - path: /tmp/myfs - src: '{{ ephemeral_device_A }}' - fstype: '{{ ephemeral_fstype }}' - opts: rw - state: ephemeral - register: ephemeral_mount_info + - name: Try to mount FS A where FS A is already mounted (should trigger remount and changed) + ansible.posix.mount: + path: /tmp/myfs + src: '{{ ephemeral_device_a }}' + fstype: '{{ ephemeral_fstype }}' + opts: ro + state: ephemeral + register: ephemeral_mount_info - - name: Put something in the directory so we can do additional checks later on - copy: - content: 'Testing' - dest: /tmp/myfs/test_file + - name: Get second mount record (should be different than the first) + ansible.builtin.shell: + cmd: grep '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + register: ephemeral_mount_record_2 + changed_when: false - - name: Get checksum of /etc/fstab after an ephemeral mount - stat: - path: '{{ ephemeral_fstab }}' - register: fstab_stat_after_mount + - name: Get mountinfo + ansible.builtin.shell: + cmd: grep -c '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + failed_when: false + register: check_mountinfo + changed_when: false - - name: Get mountinfo - shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l - register: check_mountinfo - changed_when: no + - name: Assert the FS A is still mounted, the options changed and the fstab unchanged + ansible.builtin.assert: + that: + - check_mountinfo.stdout|int == 1 + - ephemeral_mount_record_1.stdout != ephemeral_mount_record_2.stdout + - ephemeral_mount_info['changed'] + - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_mount['stat']['checksum'] - - name: Assert the mount occured and the fstab is unchanged - assert: - that: - - check_mountinfo.stdout|int == 1 - - ephemeral_mount_info['changed'] - - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_mount['stat']['checksum'] + - name: Try to mount file B on file A mountpoint (should fail) + ansible.posix.mount: + path: /tmp/myfs + src: '{{ ephemeral_device_b }}' + fstype: '{{ ephemeral_fstype }}' + state: ephemeral + register: ephemeral_mount_b_info + ignore_errors: true - - name: Get first mount record - shell: mount -v | grep '/tmp/myfs' - register: ephemeral_mount_record_1 - changed_when: no + - name: Get third mount record (should be the same than the second) + ansible.builtin.shell: + cmd: grep '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + register: ephemeral_mount_record_3 + changed_when: false - - name: Try to mount FS A where FS A is already mounted (should trigger remount and changed) - mount: - path: /tmp/myfs - src: '{{ ephemeral_device_A }}' - fstype: '{{ ephemeral_fstype }}' - opts: ro - state: ephemeral - register: ephemeral_mount_info + - name: Get mountinfo + ansible.builtin.shell: + cmd: grep -c '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + failed_when: false + register: check_mountinfo + changed_when: false - - name: Get second mount record (should be different than the first) - shell: mount -v | grep '/tmp/myfs' - register: ephemeral_mount_record_2 - changed_when: no + - name: Try to stat our test file + ansible.builtin.stat: + path: /tmp/myfs/test_file + register: test_file_stat - - name: Get mountinfo - shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l - register: check_mountinfo - changed_when: no + - name: Assert that mounting FS B over FS A failed + ansible.builtin.assert: + that: + - check_mountinfo.stdout|int == 1 + - ephemeral_mount_record_2.stdout == ephemeral_mount_record_3.stdout + - test_file_stat['stat']['exists'] + - ephemeral_mount_b_info is failed - - name: Assert the FS A is still mounted, the options changed and the fstab unchanged - assert: - that: - - check_mountinfo.stdout|int == 1 - - ephemeral_mount_record_1.stdout != ephemeral_mount_record_2.stdout - - ephemeral_mount_info['changed'] - - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_mount['stat']['checksum'] + - name: Unmount FS with state = unmounted + ansible.posix.mount: + path: /tmp/myfs + state: unmounted - - name: Try to mount file B on file A mountpoint (should fail) - mount: - path: /tmp/myfs - src: '{{ ephemeral_device_B }}' - fstype: '{{ ephemeral_fstype }}' - state: ephemeral - register: ephemeral_mount_b_info - ignore_errors: true + - name: Get fstab checksum after unmounting an ephemeral mount with state = unmounted + ansible.builtin.stat: + path: '{{ ephemeral_fstab }}' + register: fstab_stat_after_unmount - - name: Get third mount record (should be the same than the second) - shell: mount -v | grep '/tmp/myfs' - register: ephemeral_mount_record_3 - changed_when: no + - name: Get mountinfo + ansible.builtin.shell: + cmd: grep -c '/tmp/myfs' <(mount -v) + executable: "{{ shell_executable }}" + register: check_mountinfo + failed_when: false + changed_when: false - - name: Get mountinfo - shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l - register: check_mountinfo - changed_when: no + - name: Try to stat our test file + ansible.builtin.stat: + path: /tmp/myfs/test_file + register: test_file_stat - - name: Try to stat our test file - stat: - path: /tmp/myfs/test_file - register: test_file_stat - - - name: Assert that mounting FS B over FS A failed - assert: - that: - - check_mountinfo.stdout|int == 1 - - ephemeral_mount_record_2.stdout == ephemeral_mount_record_3.stdout - - test_file_stat['stat']['exists'] - - ephemeral_mount_b_info is failed - - - name: Unmount FS with state = unmounted - mount: - path: /tmp/myfs - state: unmounted - - - name: Get fstab checksum after unmounting an ephemeral mount with state = unmounted - stat: - path: '{{ ephemeral_fstab }}' - register: fstab_stat_after_unmount - - - name: Get mountinfo - shell: mount -v | awk '{print $3}' | grep '^/tmp/myfs$' | wc -l - register: check_mountinfo - changed_when: no - - - name: Try to stat our test file - stat: - path: /tmp/myfs/test_file - register: test_file_stat - - - name: Assert that fstab is unchanged after unmounting an ephemeral mount with state = unmounted - assert: - that: - - check_mountinfo.stdout|int == 0 - - not test_file_stat['stat']['exists'] - - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_unmount['stat']['checksum'] + - name: Assert that fstab is unchanged after unmounting an ephemeral mount with state = unmounted + ansible.builtin.assert: + that: + - check_mountinfo.stdout|int == 0 + - not test_file_stat['stat']['exists'] + - fstab_stat_before_mount['stat']['checksum'] == fstab_stat_after_unmount['stat']['checksum'] always: - name: Unmount potential failure relicas - mount: + ansible.posix.mount: path: /tmp/myfs state: unmounted - name: Remove loop devices on Solaris and BSD - ansible.builtin.shell: "{{ ephemeral_remove_loop_dev_cmd }}" + ansible.builtin.shell: + cmd: "set -o pipefail && {{ ephemeral_remove_loop_dev_cmd }}" + executable: "{{ shell_executable }}" + changed_when: true when: ephemeral_remove_loop_dev_cmd is defined - name: Remove the test FS - file: + ansible.builtin.file: path: '{{ item }}' state: absent loop: - /tmp/myfs_A.img - /tmp/myfs_B.img - /tmp/myfs - when: ansible_system in ('Linux', 'SunOS', 'FreeBSD', 'NetBSD', 'OpenBSD') diff --git a/tests/integration/targets/patch/tasks/main.yml b/tests/integration/targets/patch/tasks/main.yml index 0b5f3ee..d29c30c 100644 --- a/tests/integration/targets/patch/tasks/main.yml +++ b/tests/integration/targets/patch/tasks/main.yml @@ -1,124 +1,147 @@ -- name: ensure idempotency installed - package: +--- +- name: Ensure idempotency installed + ansible.builtin.package: name: patch when: ansible_distribution != "MacOSX" -- name: create a directory for the result - file: - dest: '{{ output_dir }}/patch' + +- name: Create a directory for the result + ansible.builtin.file: + dest: "{{ output_dir }}/patch" state: directory + mode: "0755" register: result -- name: assert the directory was created - assert: + +- name: Assert the directory was created + ansible.builtin.assert: that: - - result.state == 'directory' -- name: copy the origin file - copy: + - result.state == 'directory' + +- name: Copy the origin file + ansible.builtin.copy: src: ./origin.txt - dest: '{{ output_dir }}/patch/workfile.txt' + dest: "{{ output_dir }}/patch/workfile.txt" + mode: "0644" register: result -- name: patch the origin file in check mode + +- name: Patch the origin file in check mode check_mode: true register: result - patch: + ansible.posix.patch: src: result.patch - dest: '{{ output_dir }}/patch/workfile.txt' -- name: verify patch the origin file in check mode - assert: + dest: "{{ output_dir }}/patch/workfile.txt" + +- name: Verify patch the origin file in check mode + ansible.builtin.assert: that: - - result is changed -- name: patch the origin file + - result is changed + +- name: Patch the origin file register: result - patch: + ansible.posix.patch: src: result.patch - dest: '{{ output_dir }}/patch/workfile.txt' -- name: verify patch the origin file - assert: + dest: "{{ output_dir }}/patch/workfile.txt" + +- name: Verify patch the origin file + ansible.builtin.assert: that: - - result is changed -- name: test patch the origin file idempotency + - result is changed + +- name: Test patch the origin file idempotency register: result - patch: + ansible.posix.patch: src: result.patch - dest: '{{ output_dir }}/patch/workfile.txt' -- name: verify test patch the origin file idempotency - assert: + dest: "{{ output_dir }}/patch/workfile.txt" +- name: Verify test patch the origin file idempotency + ansible.builtin.assert: that: - - result is not changed -- name: verify the resulted file matches expectations - copy: + - result is not changed + +- name: Verify the resulted file matches expectations + ansible.builtin.copy: src: ./result.txt - dest: '{{ output_dir }}/patch/workfile.txt' + dest: "{{ output_dir }}/patch/workfile.txt" + mode: "0644" register: result failed_when: result is changed -- name: patch the workfile file in check mode state absent + +- name: Patch the workfile file in check mode state absent check_mode: true register: result - patch: + ansible.posix.patch: src: result.patch - dest: '{{ output_dir }}/patch/workfile.txt' + dest: "{{ output_dir }}/patch/workfile.txt" state: absent -- name: verify patch the workfile file in check mode state absent - assert: + +- name: Verify patch the workfile file in check mode state absent + ansible.builtin.assert: that: - - result is changed -- name: patch the workfile file state absent + - result is changed + +- name: Patch the workfile file state absent register: result - patch: + ansible.posix.patch: src: result.patch - dest: '{{ output_dir }}/patch/workfile.txt' + dest: "{{ output_dir }}/patch/workfile.txt" state: absent -- name: verify patch the workfile file state absent - assert: + +- name: Verify patch the workfile file state absent + ansible.builtin.assert: that: - - result is changed -- name: patch the workfile file state absent idempotency + - result is changed + +- name: Patch the workfile file state absent idempotency register: result - patch: + ansible.posix.patch: src: result.patch - dest: '{{ output_dir }}/patch/workfile.txt' + dest: "{{ output_dir }}/patch/workfile.txt" state: absent -- name: verify patch the workfile file state absent idempotency - assert: + +- name: Verify patch the workfile file state absent idempotency + ansible.builtin.assert: that: - - result is not changed -- name: verify the resulted file matches expectations - copy: + - result is not changed + +- name: Verify the resulted file matches expectations + ansible.builtin.copy: src: ./origin.txt - dest: '{{ output_dir }}/patch/workfile.txt' + dest: "{{ output_dir }}/patch/workfile.txt" + mode: "0644" register: result failed_when: result is changed -- name: copy the origin file whitespace - copy: +- name: Copy the origin file whitespace + ansible.builtin.copy: src: ./origin.txt - dest: '{{ output_dir }}/patch/workfile_whitespace.txt' + dest: "{{ output_dir }}/patch/workfile_whitespace.txt" + mode: "0644" register: result -- name: patch the origin file +- name: Patch the origin file register: result - patch: + ansible.posix.patch: src: result_whitespace.patch - dest: '{{ output_dir }}/patch/workfile_whitespace.txt' - ignore_whitespace: yes -- name: verify patch the origin file - assert: + dest: "{{ output_dir }}/patch/workfile_whitespace.txt" + ignore_whitespace: true +- name: Verify patch the origin file + ansible.builtin.assert: that: - - result is changed + - result is changed -- name: test patch the origin file idempotency +- name: Test patch the origin file idempotency register: result - patch: + ansible.posix.patch: src: result_whitespace.patch - dest: '{{ output_dir }}/patch/workfile_whitespace.txt' - ignore_whitespace: yes -- name: verify test patch the origin file idempotency - assert: + dest: "{{ output_dir }}/patch/workfile_whitespace.txt" + ignore_whitespace: true +- name: Verify test patch the origin file idempotency + ansible.builtin.assert: that: - - result is not changed + - result is not changed -- name: verify the resulted file matches expectations - copy: +- name: Verify the resulted file matches expectations + ansible.builtin.copy: src: ./result_whitespace.txt - dest: '{{ output_dir }}/patch/workfile_whitespace.txt' + dest: "{{ output_dir }}/patch/workfile_whitespace.txt" + mode: "0644" register: result failed_when: result is changed diff --git a/tests/integration/targets/seboolean/tasks/main.yml b/tests/integration/targets/seboolean/tasks/main.yml index c8a5ffe..4aad585 100644 --- a/tests/integration/targets/seboolean/tasks/main.yml +++ b/tests/integration/targets/seboolean/tasks/main.yml @@ -1,3 +1,4 @@ +--- # (c) 2017, Martin Krizek # This file is part of Ansible @@ -15,8 +16,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- include_tasks: seboolean.yml +- name: Include_tasks for when SELinux is enabled + ansible.builtin.include_tasks: seboolean.yml when: - ansible_selinux is defined - - ansible_selinux != False + - ansible_selinux - ansible_selinux.status == 'enabled' diff --git a/tests/integration/targets/seboolean/tasks/seboolean.yml b/tests/integration/targets/seboolean/tasks/seboolean.yml index 252ee3d..dbd747b 100644 --- a/tests/integration/targets/seboolean/tasks/seboolean.yml +++ b/tests/integration/targets/seboolean/tasks/seboolean.yml @@ -1,3 +1,4 @@ +--- # (c) 2017, Martin Krizek # This file is part of Ansible @@ -15,69 +16,89 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- name: install requirements for RHEL 7 and earlier - package: +- name: Install requirements for RHEL 7 and earlier + ansible.builtin.package: name: policycoreutils-python when: - ansible_distribution == 'RedHat' and ansible_distribution_major_version is version('7', '<=') -- name: install requirements for RHEL 8 and later - package: +- name: Install requirements for RHEL 8 and later + ansible.builtin.package: name: policycoreutils-python-utils when: - ansible_distribution == 'RedHat' and ansible_distribution_major_version is version('8', '>=') +- name: Get getsebool output preflight + ansible.builtin.shell: + cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W' + executable: /bin/bash + changed_when: false + register: getsebool_output_preflight + - name: Cleanup - shell: setsebool -P httpd_can_network_connect 0 -########################################################################################## -- name: set flag and don't keep it persistent - seboolean: + ansible.builtin.shell: + cmd: set -o pipefail && setsebool -P httpd_can_network_connect 0 + executable: /bin/bash + changed_when: getsebool_output_preflight.stdout.startswith('httpd_can_network_connect --> on') + +- name: Set flag and don't keep it persistent + ansible.posix.seboolean: name: httpd_can_network_connect - state: yes + state: true register: output -- name: get getsebool output - shell: semanage boolean -l | grep 'httpd_can_network_connect\W' +- name: Get getsebool output + ansible.builtin.shell: + cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W' + executable: /bin/bash + changed_when: false register: getsebool_output -- name: check output - assert: +- name: Check output + ansible.builtin.assert: that: - output is changed - output is not failed - output.name == 'httpd_can_network_connect' - getsebool_output.stdout.startswith('httpd_can_network_connect (on , off)') ########################################################################################## -- name: unset flag - seboolean: +- name: Unset flag + ansible.posix.seboolean: name: httpd_can_network_connect - state: no + state: false -- name: get getsebool output - shell: semanage boolean -l | grep 'httpd_can_network_connect\W' +- name: Get getsebool output + ansible.builtin.shell: + cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W' + executable: /bin/bash + changed_when: false register: getsebool_output -- name: check output - assert: +- name: Check output + ansible.builtin.assert: that: - output is changed - output is not failed - output.name == 'httpd_can_network_connect' - getsebool_output.stdout.startswith('httpd_can_network_connect (off , off)') + ########################################################################################## -- name: set flag and keep it persistent - seboolean: +- name: Set flag and keep it persistent + ansible.posix.seboolean: name: httpd_can_network_connect - state: yes - persistent: yes + state: true + persistent: true register: output -- name: get getsebool output - shell: semanage boolean -l | grep 'httpd_can_network_connect\W' +- name: Get getsebool output + ansible.builtin.shell: + cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W' + executable: /bin/bash + changed_when: false register: getsebool_output -- name: check output - assert: +- name: Check output + ansible.builtin.assert: that: - output is changed - output is not failed diff --git a/tests/integration/targets/selinux/tasks/main.yml b/tests/integration/targets/selinux/tasks/main.yml index a5fed6b..8d8db05 100644 --- a/tests/integration/targets/selinux/tasks/main.yml +++ b/tests/integration/targets/selinux/tasks/main.yml @@ -1,3 +1,4 @@ +--- # (c) 2017, Sam Doran # This file is part of Ansible @@ -15,22 +16,26 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- debug: +- name: Debug message for when SELinux is disabled + ansible.builtin.debug: msg: SELinux is disabled - when: ansible_selinux is defined and ansible_selinux == False + when: ansible_selinux is defined and not ansible_selinux -- debug: +- name: Debug message for when SELinux is enabled and not disabled + ansible.builtin.debug: msg: SELinux is {{ ansible_selinux.status }} - when: ansible_selinux is defined and ansible_selinux != False + when: ansible_selinux is defined and ansible_selinux -- include_tasks: selinux.yml +- name: Include_tasks for when SELinux is enabled + ansible.builtin.include_tasks: selinux.yml when: - ansible_selinux is defined - - ansible_selinux != False + - ansible_selinux - ansible_selinux.status == 'enabled' -- include_tasks: selogin.yml +- name: Include tasks for selogin when SELinux is enabled + ansible.builtin.include_tasks: selogin.yml when: - ansible_selinux is defined - - ansible_selinux != False + - ansible_selinux - ansible_selinux.status == 'enabled' diff --git a/tests/integration/targets/selinux/tasks/selinux.yml b/tests/integration/targets/selinux/tasks/selinux.yml index d936ec6..b9cfb20 100644 --- a/tests/integration/targets/selinux/tasks/selinux.yml +++ b/tests/integration/targets/selinux/tasks/selinux.yml @@ -1,3 +1,4 @@ +--- # (c) 2017, Sam Doran # This file is part of Ansible @@ -14,67 +15,67 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . - - # First Test # ############################################################################## # Test changing the state, which requires a reboot - name: TEST 1 | Make sure grubby is present - package: + ansible.builtin.package: name: grubby state: present - name: TEST 1 | Get current SELinux config file contents - slurp: + ansible.builtin.slurp: src: /etc/sysconfig/selinux register: selinux_config_original_base64 - name: TEST 1 | Register SELinux config and SELinux status - set_fact: + ansible.builtin.set_fact: selinux_config_original_raw: "{{ selinux_config_original_base64.content | b64decode }}" before_test_sestatus: "{{ ansible_selinux }}" - name: TEST 1 | Split by line and register original config - set_fact: + ansible.builtin.set_fact: selinux_config_original: "{{ selinux_config_original_raw.split('\n') }}" -- debug: +- name: TEST 1 | Debug selinux_config_original, before_test_sestatus, and ansible_selinux + ansible.builtin.debug: var: "{{ item }}" verbosity: 1 - with_items: + loop: - selinux_config_original - before_test_sestatus - ansible_selinux - name: TEST 1 | Setup SELinux configuration for tests - selinux: + ansible.posix.selinux: state: enforcing policy: targeted - name: TEST 1 | Disable SELinux - selinux: + ansible.posix.selinux: state: disabled policy: targeted register: _disable_test1 -- debug: +- name: TEST 1 | Debug _disable_test1 + ansible.builtin.debug: var: _disable_test1 verbosity: 1 - name: Before gathering the fact - debug: + ansible.builtin.debug: msg: "{{ ansible_selinux }}" - name: TEST 1 | Re-gather facts - setup: + ansible.builtin.setup: - name: After gathering the fact - debug: + ansible.builtin.debug: msg: "{{ ansible_selinux }}" - name: TEST 1 | Assert that status was changed, reboot_required is True, a warning was displayed, and SELinux is configured properly - assert: + ansible.builtin.assert: that: - _disable_test1 is changed - _disable_test1.reboot_required @@ -82,53 +83,56 @@ - ansible_selinux.config_mode == 'disabled' - ansible_selinux.type == 'targeted' -- debug: +- name: TEST 1 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 - name: TEST 1 | Disable SELinux again - selinux: + ansible.posix.selinux: state: disabled policy: targeted register: _disable_test2 -- debug: +- name: Test 1 | Debug _disable_test2 + ansible.builtin.debug: var: _disable_test2 verbosity: 1 - name: TEST 1 | Assert that no change is reported, a warning was displayed, and reboot_required is True - assert: + ansible.builtin.assert: that: - _disable_test2 is not changed - (_disable_test1.warnings | length ) >= 1 - _disable_test2.reboot_required - name: TEST 1 | Get modified config file - slurp: + ansible.builtin.slurp: src: /etc/sysconfig/selinux register: selinux_config_after_base64 - name: TEST 1 | Register modified config - set_fact: + ansible.builtin.set_fact: selinux_config_after_raw: "{{ selinux_config_after_base64.content | b64decode }}" - name: TEST 1 | Split by line and register modified config - set_fact: + ansible.builtin.set_fact: selinux_config_after: "{{ selinux_config_after_raw.split('\n') }}" -- debug: +- name: TEST 1 | Debug selinux_config_after + ansible.builtin.debug: var: selinux_config_after verbosity: 1 - name: TEST 1 | Ensure SELinux config file is properly formatted - assert: + ansible.builtin.assert: that: - selinux_config_original | length == selinux_config_after | length - selinux_config_after[selinux_config_after.index('SELINUX=disabled')] is search("^SELINUX=\w+$") - selinux_config_after[selinux_config_after.index('SELINUXTYPE=targeted')] is search("^SELINUXTYPE=\w+$") - name: TEST 1 | Disable SELinux again, with kernel arguments update - selinux: + ansible.posix.selinux: state: disabled policy: targeted update_kernel_param: true @@ -136,72 +140,76 @@ - name: Check kernel command-line arguments ansible.builtin.command: grubby --info=DEFAULT + changed_when: false register: _grubby_test1 - name: TEST 1 | Assert that kernel cmdline contains selinux=0 - assert: + ansible.builtin.assert: that: - "' selinux=0' in _grubby_test1.stdout" - name: TEST 1 | Enable SELinux, without kernel arguments update - selinux: + ansible.posix.selinux: state: disabled policy: targeted register: _disable_test2 - name: Check kernel command-line arguments ansible.builtin.command: grubby --info=DEFAULT + changed_when: false register: _grubby_test1 - name: TEST 1 | Assert that kernel cmdline still contains selinux=0 - assert: + ansible.builtin.assert: that: - "' selinux=0' in _grubby_test1.stdout" - name: TEST 1 | Reset SELinux configuration for next test (also kernel args) - selinux: + ansible.posix.selinux: state: enforcing update_kernel_param: true policy: targeted - name: Check kernel command-line arguments ansible.builtin.command: grubby --info=DEFAULT + changed_when: false register: _grubby_test2 - name: TEST 1 | Assert that kernel cmdline doesn't contain selinux=0 - assert: + ansible.builtin.assert: that: - "' selinux=0' not in _grubby_test2.stdout" - # Second Test # ############################################################################## # Test changing only the policy, which does not require a reboot - name: TEST 2 | Make sure the policy is present - package: + ansible.builtin.package: name: selinux-policy-mls state: present - name: TEST 2 | Set SELinux policy - selinux: + ansible.posix.selinux: state: enforcing policy: mls register: _state_test1 -- debug: +- name: TEST 2 | Debug _state_test1 + ansible.builtin.debug: var: _state_test1 verbosity: 1 - name: TEST 2 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 2 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux tags: debug - name: TEST 2 | Assert that status was changed, reboot_required is False, no warnings were displayed, and SELinux is configured properly - assert: + ansible.builtin.assert: that: - _state_test1 is changed - not _state_test1.reboot_required @@ -210,76 +218,79 @@ - ansible_selinux.type == 'mls' - name: TEST 2 | Set SELinux policy again - selinux: + ansible.posix.selinux: state: enforcing policy: mls register: _state_test2 -- debug: +- name: TEST 2 | Debug _state_test2 + ansible.builtin.debug: var: _state_test2 verbosity: 1 - name: TEST 2 | Assert that no change was reported, no warnings were displayed, and reboot_required is False - assert: + ansible.builtin.assert: that: - _state_test2 is not changed - _state_test2.warnings is not defined - not _state_test2.reboot_required - name: TEST 2 | Get modified config file - slurp: + ansible.builtin.slurp: src: /etc/sysconfig/selinux register: selinux_config_after_base64 - name: TEST 2 | Register modified config - set_fact: + ansible.builtin.set_fact: selinux_config_after_raw: "{{ selinux_config_after_base64.content | b64decode }}" - name: TEST 2 | Split by line and register modified config - set_fact: + ansible.builtin.set_fact: selinux_config_after: "{{ selinux_config_after_raw.split('\n') }}" -- debug: +- name: TEST 2 | Debug selinux_config_after + ansible.builtin.debug: var: selinux_config_after verbosity: 1 - name: TEST 2 | Ensure SELinux config file is properly formatted - assert: + ansible.builtin.assert: that: - selinux_config_original | length == selinux_config_after | length - selinux_config_after[selinux_config_after.index('SELINUX=enforcing')] is search("^SELINUX=\w+$") - selinux_config_after[selinux_config_after.index('SELINUXTYPE=mls')] is search("^SELINUXTYPE=\w+$") - name: TEST 2 | Reset SELinux configuration for next test - selinux: + ansible.posix.selinux: state: enforcing policy: targeted - # Third Test # ############################################################################## # Test changing non-existing policy - name: TEST 3 | Set SELinux policy - selinux: + ansible.posix.selinux: state: enforcing policy: non-existing-selinux-policy register: _state_test1 - ignore_errors: yes + ignore_errors: true -- debug: +- name: TEST 3 | Debug _state_test1 + ansible.builtin.debug: var: _state_test1 verbosity: 1 - name: TEST 3 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST3 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux tags: debug - name: TEST 3 | Assert that status was not changed, the task failed, the msg contains proper information and SELinux was not changed - assert: + ansible.builtin.assert: that: - _state_test1 is not changed - _state_test1 is failed @@ -287,40 +298,40 @@ - ansible_selinux.config_mode == 'enforcing' - ansible_selinux.type == 'targeted' - # Fourth Test # ############################################################################## # Test if check mode returns correct changed values and # doesn't make any changes - - name: TEST 4 | Set SELinux to enforcing - selinux: + ansible.posix.selinux: state: enforcing policy: targeted register: _check_mode_test1 -- debug: +- name: TEST 4 | Debug _check_mode_test1 + ansible.builtin.debug: var: _check_mode_test1 verbosity: 1 - name: TEST 4 | Set SELinux to enforcing in check mode - selinux: + ansible.posix.selinux: state: enforcing policy: targeted register: _check_mode_test1 - check_mode: yes + check_mode: true - name: TEST 4 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 4| Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 tags: debug - name: TEST 4 | Assert that check mode is idempotent - assert: + ansible.builtin.assert: that: - _check_mode_test1 is success - not _check_mode_test1.reboot_required @@ -328,22 +339,23 @@ - ansible_selinux.type == 'targeted' - name: TEST 4 | Set SELinux to permissive in check mode - selinux: + ansible.posix.selinux: state: permissive policy: targeted register: _check_mode_test2 - check_mode: yes + check_mode: true - name: TEST 4 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 4 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 tags: debug - name: TEST 4 | Assert that check mode doesn't set state permissive and returns changed - assert: + ansible.builtin.assert: that: - _check_mode_test2 is changed - not _check_mode_test2.reboot_required @@ -351,21 +363,22 @@ - ansible_selinux.type == 'targeted' - name: TEST 4 | Disable SELinux in check mode - selinux: + ansible.posix.selinux: state: disabled register: _check_mode_test3 - check_mode: yes + check_mode: true - name: TEST 4 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 4 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 tags: debug - name: TEST 4 | Assert that check mode didn't change anything, status is changed, reboot_required is True, a warning was displayed - assert: + ansible.builtin.assert: that: - _check_mode_test3 is changed - _check_mode_test3.reboot_required @@ -374,31 +387,33 @@ - ansible_selinux.type == 'targeted' - name: TEST 4 | Set SELinux to permissive - selinux: + ansible.posix.selinux: state: permissive policy: targeted register: _check_mode_test4 -- debug: +- name: TEST 4 | Debug _check_mode_test4 + ansible.builtin.debug: var: _check_mode_test4 verbosity: 1 - name: TEST 4 | Disable SELinux in check mode - selinux: + ansible.posix.selinux: state: disabled register: _check_mode_test4 - check_mode: yes + check_mode: true - name: TEST 4 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 4 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 tags: debug - name: TEST 4 | Assert that check mode didn't change anything, status is changed, reboot_required is True, a warning was displayed - assert: + ansible.builtin.assert: that: - _check_mode_test4 is changed - _check_mode_test4.reboot_required @@ -407,36 +422,38 @@ - ansible_selinux.type == 'targeted' - name: TEST 4 | Set SELinux to enforcing - selinux: + ansible.posix.selinux: state: enforcing policy: targeted register: _check_mode_test5 -- debug: +- name: TEST 4 | Debug _check_mode_test5 + ansible.builtin.debug: var: _check_mode_test5 verbosity: 1 - name: TEST 4 | Disable SELinux - selinux: + ansible.posix.selinux: state: disabled register: _check_mode_test5 - name: TEST 4 | Disable SELinux in check mode - selinux: + ansible.posix.selinux: state: disabled register: _check_mode_test5 - check_mode: yes + check_mode: true - name: TEST 4 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 4 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 tags: debug - name: TEST 4 | Assert that in check mode status was not changed, reboot_required is True, a warning was displayed, and SELinux is configured properly - assert: + ansible.builtin.assert: that: - _check_mode_test5 is success - _check_mode_test5.reboot_required @@ -450,32 +467,34 @@ # sure the module re-adds the expected lines - name: TEST 5 | Remove SELINUX key from /etc/selinux/config - lineinfile: + ansible.builtin.lineinfile: path: /etc/selinux/config - regexp: '^SELINUX=' + regexp: ^SELINUX= state: absent - backup: yes + backup: true register: _lineinfile_out1 -- debug: +- name: TEST 5 | Debug _lineinfile_out1 + ansible.builtin.debug: var: _lineinfile_out1 verbosity: 1 - name: TEST 5 | Set SELinux to enforcing - selinux: + ansible.posix.selinux: state: enforcing policy: targeted register: _set_enforcing1 - name: TEST 5 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 5 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 - name: TEST 5 | Assert that SELINUX key is populated - assert: + ansible.builtin.assert: that: - _set_enforcing1 is success - _set_enforcing1 is changed @@ -483,31 +502,33 @@ - ansible_selinux.config_mode == 'enforcing' - name: TEST 5 | Remove SELINUXTYPE key from /etc/selinux/config - lineinfile: + ansible.builtin.lineinfile: path: /etc/selinux/config - regexp: '^SELINUXTYPE=' + regexp: ^SELINUXTYPE= state: absent register: _lineinfile_out2 -- debug: +- name: TEST 5 | Debug _lineinfile_out2 + ansible.builtin.debug: var: _lineinfile_out2 verbosity: 1 - name: TEST 5 | Set SELinux Policy to targeted - selinux: + ansible.posix.selinux: state: enforcing policy: targeted register: _set_policy2 - name: TEST 5 | Re-gather facts - setup: + ansible.builtin.setup: -- debug: +- name: TEST 5 | Debug ansible_selinux + ansible.builtin.debug: var: ansible_selinux verbosity: 1 - name: TEST 5 | Assert that SELINUXTYPE key is populated - assert: + ansible.builtin.assert: that: - _set_policy2 is success - _set_policy2 is changed @@ -515,7 +536,8 @@ - ansible_selinux.type == 'targeted' - name: TEST 5 | Restore original SELinux config file /etc/selinux/config - copy: + ansible.builtin.copy: dest: /etc/selinux/config src: "{{ _lineinfile_out1['backup'] }}" - remote_src: yes + remote_src: true + mode: "0644" diff --git a/tests/integration/targets/selinux/tasks/selogin.yml b/tests/integration/targets/selinux/tasks/selogin.yml index 6e7b726..c8899da 100644 --- a/tests/integration/targets/selinux/tasks/selogin.yml +++ b/tests/integration/targets/selinux/tasks/selogin.yml @@ -1,70 +1,71 @@ -- name: create user for testing - user: +--- +- name: Create user for testing + ansible.builtin.user: name: seuser -- name: attempt to add mapping without 'seuser' +- name: Attempt to add mapping without 'seuser' register: selogin_error ignore_errors: true community.general.system.selogin: login: seuser -- name: verify failure - assert: +- name: Verify failure + ansible.builtin.assert: that: - - selogin_error is failed -- name: map login to SELinux user + - selogin_error is failed +- name: Map login to SELinux user register: selogin_new_mapping - check_mode: '{{ item }}' + check_mode: "{{ item }}" with_items: - - true - - false - - true - - false + - true + - false + - true + - false community.general.system.selogin: login: seuser seuser: staff_u -- name: new mapping- verify functionality and check_mode - assert: +- name: New mapping- verify functionality and check_mode + ansible.builtin.assert: that: - - selogin_new_mapping.results[0] is changed - - selogin_new_mapping.results[1] is changed - - selogin_new_mapping.results[2] is not changed - - selogin_new_mapping.results[3] is not changed -- name: change SELinux user login mapping + - selogin_new_mapping.results[0] is changed + - selogin_new_mapping.results[1] is changed + - selogin_new_mapping.results[2] is not changed + - selogin_new_mapping.results[3] is not changed +- name: Change SELinux user login mapping register: selogin_mod_mapping - check_mode: '{{ item }}' + check_mode: "{{ item }}" with_items: - - true - - false - - true - - false + - true + - false + - true + - false community.general.system.selogin: login: seuser seuser: user_u -- name: changed mapping- verify functionality and check_mode - assert: +- name: Changed mapping- verify functionality and check_mode + ansible.builtin.assert: that: - - selogin_mod_mapping.results[0] is changed - - selogin_mod_mapping.results[1] is changed - - selogin_mod_mapping.results[2] is not changed - - selogin_mod_mapping.results[3] is not changed -- name: remove SELinux user mapping + - selogin_mod_mapping.results[0] is changed + - selogin_mod_mapping.results[1] is changed + - selogin_mod_mapping.results[2] is not changed + - selogin_mod_mapping.results[3] is not changed +- name: Remove SELinux user mapping register: selogin_del_mapping - check_mode: '{{ item }}' + check_mode: "{{ item }}" with_items: - - true - - false - - true - - false + - true + - false + - true + - false community.general.system.selogin: login: seuser state: absent -- name: delete mapping- verify functionality and check_mode - assert: +- name: Delete mapping- verify functionality and check_mode + ansible.builtin.assert: that: - - selogin_del_mapping.results[0] is changed - - selogin_del_mapping.results[1] is changed - - selogin_del_mapping.results[2] is not changed - - selogin_del_mapping.results[3] is not changed -- name: remove test user - user: + - selogin_del_mapping.results[0] is changed + - selogin_del_mapping.results[1] is changed + - selogin_del_mapping.results[2] is not changed + - selogin_del_mapping.results[3] is not changed +- name: Remove test user + ansible.builtin.user: name: seuser state: absent diff --git a/tests/integration/targets/setup_pkg_mgr/tasks/main.yml b/tests/integration/targets/setup_pkg_mgr/tasks/main.yml index 24d0222..3ec66bb 100644 --- a/tests/integration/targets/setup_pkg_mgr/tasks/main.yml +++ b/tests/integration/targets/setup_pkg_mgr/tasks/main.yml @@ -4,14 +4,16 @@ # and should not be used as examples of how to write Ansible roles # #################################################################### -- set_fact: +- name: Set pkg_mgr and ansible_pkg_mgr on FreeBSD + ansible.builtin.set_fact: pkg_mgr: community.general.pkgng ansible_pkg_mgr: community.general.pkgng - cacheable: yes + cacheable: true when: ansible_os_family == "FreeBSD" -- set_fact: +- name: Set pkg_mgr and ansible_pkg_mgr on Suse + ansible.builtin.set_fact: pkg_mgr: community.general.zypper ansible_pkg_mgr: community.general.zypper - cacheable: yes + cacheable: true when: ansible_os_family == "Suse" diff --git a/tests/integration/targets/synchronize/meta/main.yml b/tests/integration/targets/synchronize/meta/main.yml index 07faa21..8828391 100644 --- a/tests/integration/targets/synchronize/meta/main.yml +++ b/tests/integration/targets/synchronize/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - prepare_tests diff --git a/tests/integration/targets/synchronize/tasks/main.yml b/tests/integration/targets/synchronize/tasks/main.yml index 125a406..d6dcdad 100644 --- a/tests/integration/targets/synchronize/tasks/main.yml +++ b/tests/integration/targets/synchronize/tasks/main.yml @@ -1,310 +1,350 @@ -- name: install rsync - package: +--- +- name: Install rsync + ansible.builtin.package: name: rsync when: ansible_distribution != "MacOSX" -- name: Clean up the working directory and files - file: - path: '{{ output_dir }}' + +- name: Clean up the working disrectory and files + ansible.builtin.file: + path: "{{ output_dir }}" state: absent + - name: Create the working directory - file: - path: '{{ output_dir }}' + ansible.builtin.file: + path: "{{ output_dir }}" state: directory -- name: create test new files - copy: - dest: '{{output_dir}}/{{item}}' - mode: '0644' - content: 'hello world' - with_items: - - foo.txt - - bar.txt + mode: "0755" -- name: synchronize file to new filename - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.result' +- name: Create test new files + ansible.builtin.copy: + dest: "{{ output_dir }}/{{ item }}" + mode: "0644" + content: hello world + loop: + - foo.txt + - bar.txt + +- name: Synchronize file to new filename + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.result" register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: - that: - - '''changed'' in sync_result' - - sync_result.changed == true - - '''cmd'' in sync_result' - - '''rsync'' in sync_result.cmd' - - '''msg'' in sync_result' - - sync_result.msg.startswith('>f+') - - 'sync_result.msg.endswith(''+ foo.txt + delegate_to: "{{ inventory_hostname }}" - '')' -- name: test that the file was really copied over - stat: - path: '{{ output_dir }}/foo.result' +- name: Check that the file was copied over correctly + ansible.builtin.assert: + that: + - "'changed' in sync_result" + - sync_result.changed == true + - "'cmd' in sync_result" + - "'rsync' in sync_result.cmd" + - "'msg' in sync_result" + - sync_result.msg.startswith('>f+') + - "sync_result.msg.endswith('+ foo.txt\n')" + +- name: Test that the file was really copied over + ansible.builtin.stat: + path: "{{ output_dir }}/foo.result" register: stat_result -- assert: - that: - - stat_result.stat.exists == True - - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' -- name: test that the file is not copied a second time - synchronize: - src='{{output_dir}}/foo.txt' - dest='{{output_dir}}/foo.result' - register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: +- name: Test that the file was really copied over + ansible.builtin.assert: that: - - sync_result.changed == False + - stat_result.stat.exists == True + - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' + +- name: Test that the file is not copied a second time + ansible.posix.synchronize: + src: "'{{ output_dir }}/foo.txt'" + dest: "'{{ output_dir }}/foo.result'" + register: sync_result + delegate_to: "{{ inventory_hostname }}" + +- name: Test that no change occurred + ansible.builtin.assert: + that: + - not sync_result.changed + - name: Cleanup - file: + ansible.builtin.file: state: absent - path: '{{output_dir}}/{{item}}' - with_items: - - foo.result - - bar.result + path: "{{ output_dir }}/{{ item }}" + loop: + - foo.result + - bar.result - name: Synchronize using the mode=push param - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.result' + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.result" mode: push register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: - that: - - '''changed'' in sync_result' - - sync_result.changed == true - - '''cmd'' in sync_result' - - '''rsync'' in sync_result.cmd' - - '''msg'' in sync_result' - - sync_result.msg.startswith('>f+') - - 'sync_result.msg.endswith(''+ foo.txt + delegate_to: "{{ inventory_hostname }}" - '')' -- name: test that the file was really copied over - stat: - path: '{{ output_dir }}/foo.result' +- name: Check that the file was copied over correctly mode=push + ansible.builtin.assert: + that: + - "'changed' in sync_result" + - sync_result.changed == true + - "'cmd' in sync_result" + - "'rsync' in sync_result.cmd" + - "'msg' in sync_result" + - sync_result.msg.startswith('>f+') + - "sync_result.msg.endswith('+ foo.txt\n')" + +- name: Test that the file was really copied over + ansible.builtin.stat: + path: "{{ output_dir }}/foo.result" register: stat_result -- assert: - that: - - stat_result.stat.exists == True - - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' -- name: test that the file is not copied a second time - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.result' +- name: Ensure file exists and checksum matches + ansible.builtin.assert: + that: + - stat_result.stat.exists == True + - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' + +- name: Test that the file is not copied a second time + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.result" mode: push register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: + delegate_to: "{{ inventory_hostname }}" + +- name: Ensure no change occorred + ansible.builtin.assert: that: - - sync_result.changed == False + - sync_result.changed == False + - name: Cleanup - file: + ansible.builtin.file: state: absent - path: '{{output_dir}}/{{item}}' - with_items: - - foo.result - - bar.result + path: "{{ output_dir }}/{{ item }}" + loop: + - foo.result + - bar.result - name: Synchronize using the mode=pull param - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.result' + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.result" mode: pull register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: - that: - - '''changed'' in sync_result' - - sync_result.changed == true - - '''cmd'' in sync_result' - - '''rsync'' in sync_result.cmd' - - '''msg'' in sync_result' - - sync_result.msg.startswith('>f+') - - 'sync_result.msg.endswith(''+ foo.txt + delegate_to: "{{ inventory_hostname }}" - '')' -- name: test that the file was really copied over - stat: - path: '{{ output_dir }}/foo.result' +- name: Check that the file was copied over correctly mode=pull + ansible.builtin.assert: + that: + - "'changed' in sync_result" + - sync_result.changed == true + - "'cmd' in sync_result" + - "'rsync' in sync_result.cmd" + - "'msg' in sync_result" + - sync_result.msg.startswith('>f+') + - "sync_result.msg.endswith('+ foo.txt\n')" + +- name: Test that the file was really copied over + ansible.builtin.stat: + path: "{{ output_dir }}/foo.result" register: stat_result -- assert: - that: - - stat_result.stat.exists == True - - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' -- name: test that the file is not copied a second time - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.result' +- name: Ensure file exists and checksum matches + ansible.builtin.assert: + that: + - stat_result.stat.exists == True + - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' + +- name: Test that the file is not copied a second time + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.result" mode: pull register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: + delegate_to: "{{ inventory_hostname }}" + +- name: Ensure no change occorred + ansible.builtin.assert: that: - - sync_result.changed == False + - sync_result.changed == False + - name: Cleanup - file: + ansible.builtin.file: state: absent - path: '{{output_dir}}/{{item}}' - with_items: - - foo.result - - bar.result + path: "{{ output_dir }}/{{ item }}" + loop: + - foo.result + - bar.result -- name: synchronize files using with_items (issue#5965) - synchronize: - src: '{{output_dir}}/{{item}}' - dest: '{{output_dir}}/{{item}}.result' - with_items: - - foo.txt - - bar.txt - register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: - that: - - sync_result.changed - - sync_result.msg == 'All items completed' - - '''results'' in sync_result' - - sync_result.results|length == 2 - - 'sync_result.results[0].msg.endswith(''+ foo.txt - - '')' - - 'sync_result.results[1].msg.endswith(''+ bar.txt - - '')' -- name: Cleanup - file: - state: absent - path: '{{output_dir}}/{{item}}.result' - with_items: - - foo.txt - - bar.txt - -- name: synchronize files using rsync_path (issue#7182) - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.rsync_path' - rsync_path: 'sudo rsync' - register: sync_result - delegate_to: '{{ inventory_hostname }}' -- assert: - that: - - '''changed'' in sync_result' - - sync_result.changed == true - - '''cmd'' in sync_result' - - '''rsync'' in sync_result.cmd' - - '''rsync_path'' in sync_result.cmd' - - '''msg'' in sync_result' - - sync_result.msg.startswith('>f+') - - 'sync_result.msg.endswith(''+ foo.txt - - '')' -- name: Cleanup - file: - state: absent - path: '{{output_dir}}/{{item}}' - with_items: - - foo.rsync_path -- name: add subdirectories for link-dest test - file: - path: '{{output_dir}}/{{item}}/' - state: directory - mode: '0755' - with_items: - - directory_a - - directory_b -- name: copy foo.txt into the first directory - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/{{item}}/foo.txt' - with_items: - - directory_a - delegate_to: '{{ inventory_hostname }}' -- name: synchronize files using link_dest - synchronize: - src: '{{output_dir}}/directory_a/foo.txt' - dest: '{{output_dir}}/directory_b/foo.txt' - link_dest: - - '{{output_dir}}/directory_a' - register: sync_result - delegate_to: '{{ inventory_hostname }}' -- name: get stat information for directory_a - stat: - path: '{{ output_dir }}/directory_a/foo.txt' - register: stat_result_a -- name: get stat information for directory_b - stat: - path: '{{ output_dir }}/directory_b/foo.txt' - register: stat_result_b -- assert: - that: - - '''changed'' in sync_result' - - sync_result.changed == true - - stat_result_a.stat.inode == stat_result_b.stat.inode -- name: synchronize files using link_dest that would be recursive - synchronize: - src: '{{output_dir}}/foo.txt' - dest: '{{output_dir}}/foo.result' - link_dest: - - '{{output_dir}}' - register: sync_result - ignore_errors: true - delegate_to: '{{ inventory_hostname }}' - -- assert: - that: - - sync_result is not changed - - sync_result is failed -- name: Cleanup - file: - state: absent - path: '{{output_dir}}/{{item}}' - with_items: - - directory_b/foo.txt - - directory_a/foo.txt - - directory_a - - directory_b - -- name: setup - test for source with working dir with spaces in path - file: - state: directory - path: '{{output_dir}}/{{item}}' - delegate_to: '{{ inventory_hostname }}' - with_items: - - 'directory a' - - 'directory b' -- name: setup - create test new files - copy: - dest: '{{output_dir}}/directory a/{{item}}' - mode: '0644' - content: 'hello world' +- name: Synchronize files using with_items (issue#5965) + ansible.posix.synchronize: + src: "{{ output_dir }}/{{ item }}" + dest: "{{ output_dir }}/{{ item }}.result" with_items: - foo.txt - delegate_to: '{{ inventory_hostname }}' -- name: copy source with spaces in dir path - synchronize: - src: '{{output_dir}}/directory a/foo.txt' - dest: '{{output_dir}}/directory b/' - delegate_to: '{{ inventory_hostname }}' + - bar.txt + register: sync_result + delegate_to: "{{ inventory_hostname }}" + +- name: Validate syncrhonize with_items + ansible.builtin.assert: + that: + - sync_result.changed + - sync_result.msg == 'All items completed' + - "'results' in sync_result" + - sync_result.results|length == 2 + - "sync_result.results[0].msg.endswith('+ foo.txt\n')" + - "sync_result.results[1].msg.endswith('+ bar.txt\n')" + +- name: Cleanup + ansible.builtin.file: + state: absent + path: "{{ output_dir }}/{{ item }}.result" + loop: + - foo.txt + - bar.txt + +- name: Synchronize files using rsync_path (issue#7182) + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.rsync_path" + rsync_path: sudo rsync + register: sync_result + delegate_to: "{{ inventory_hostname }}" + +- name: Validate syncrhonize using rsync_path (issue#7182) + ansible.builtin.assert: + that: + - "'changed' in sync_result" + - sync_result.changed == true + - "'cmd' in sync_result" + - "'rsync' in sync_result.cmd" + - "'rsync_path' in sync_result.cmd" + - "'msg' in sync_result" + - sync_result.msg.startswith('>f+') + - "sync_result.msg.endswith('+ foo.txt\n')" + +- name: Cleanup + ansible.builtin.file: + state: absent + path: "{{ output_dir }}/{{ item }}" + loop: + - foo.rsync_path + +- name: Add subdirectories for link-dest test + ansible.builtin.file: + path: "{{ output_dir }}/{{ item }}/" + state: directory + mode: "0755" + loop: + - directory_a + - directory_b + +- name: Copy foo.txt into the first directory + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/{{ item }}/foo.txt" + loop: + - directory_a + delegate_to: "{{ inventory_hostname }}" + +- name: Synchronize files using link_dest + ansible.posix.synchronize: + src: "{{ output_dir }}/directory_a/foo.txt" + dest: "{{ output_dir }}/directory_b/foo.txt" + link_dest: + - "{{ output_dir }}/directory_a" + register: sync_result + delegate_to: "{{ inventory_hostname }}" + +- name: Get stat information for directory_a + ansible.builtin.stat: + path: "{{ output_dir }}/directory_a/foo.txt" + register: stat_result_a + +- name: Get stat information for directory_b + ansible.builtin.stat: + path: "{{ output_dir }}/directory_b/foo.txt" + register: stat_result_b + +- name: Ensure file exists and inode matches + ansible.builtin.assert: + that: + - "'changed' in sync_result" + - sync_result.changed == true + - stat_result_a.stat.inode == stat_result_b.stat.inode + +- name: Synchronize files using link_dest that would be recursive + ansible.posix.synchronize: + src: "{{ output_dir }}/foo.txt" + dest: "{{ output_dir }}/foo.result" + link_dest: + - "{{ output_dir }}" register: sync_result ignore_errors: true -- name: get stat information for directory_b - stat: - path: '{{ output_dir }}/directory b/foo.txt' - register: stat_result_b -- assert: + delegate_to: "{{ inventory_hostname }}" + +- name: Ensure no change occorred and failed + ansible.builtin.assert: that: - - '''changed'' in sync_result' + - sync_result is not changed + - sync_result is failed + +- name: Cleanup + ansible.builtin.file: + state: absent + path: "{{ output_dir }}/{{ item }}" + loop: + - directory_b/foo.txt + - directory_a/foo.txt + - directory_a + - directory_b + +- name: Setup - test for source with working dir with spaces in path + ansible.builtin.file: + state: directory + path: "{{ output_dir }}/{{ item }}" + mode: "0755" + delegate_to: "{{ inventory_hostname }}" + loop: + - directory a + - directory b + +- name: Setup - create test new files + ansible.builtin.copy: + dest: "{{ output_dir }}/directory a/{{ item }}" + mode: "0644" + content: hello world + loop: + - foo.txt + delegate_to: "{{ inventory_hostname }}" + +- name: Copy source with spaces in dir path + ansible.posix.synchronize: + src: "{{ output_dir }}/directory a/foo.txt" + dest: "{{ output_dir }}/directory b/" + delegate_to: "{{ inventory_hostname }}" + register: sync_result + ignore_errors: true + +- name: Get stat information for directory_b + ansible.builtin.stat: + path: "{{ output_dir }}/directory b/foo.txt" + register: stat_result_b + +- name: Ensure file exists and checksum matches + ansible.builtin.assert: + that: + - "'changed' in sync_result" - sync_result.changed == true - stat_result_b.stat.exists == True - stat_result_b.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' + - name: Cleanup - file: + ansible.builtin.file: state: absent - path: '{{output_dir}}/{{item}}' - with_items: - - 'directory b/foo.txt' - - 'directory a/foo.txt' - - 'directory a' - - 'directory b' + path: "{{ output_dir }}/{{ item }}" + loop: + - directory b/foo.txt + - directory a/foo.txt + - directory a + - directory b diff --git a/tests/integration/targets/sysctl/meta/main.yml b/tests/integration/targets/sysctl/meta/main.yml index 07faa21..8828391 100644 --- a/tests/integration/targets/sysctl/meta/main.yml +++ b/tests/integration/targets/sysctl/meta/main.yml @@ -1,2 +1,3 @@ +--- dependencies: - prepare_tests diff --git a/tests/integration/targets/sysctl/tasks/main.yml b/tests/integration/targets/sysctl/tasks/main.yml index 0c40fc3..249bde1 100644 --- a/tests/integration/targets/sysctl/tasks/main.yml +++ b/tests/integration/targets/sysctl/tasks/main.yml @@ -1,3 +1,4 @@ +--- # Test code for the sysctl module. # (c) 2017, James Tanner @@ -24,79 +25,91 @@ when: - ansible_facts.virtualization_type == 'docker' or ansible_facts.virtualization_type == 'container' block: - - set_fact: + - name: Set output_dir_test fact + ansible.builtin.set_fact: output_dir_test: "{{ output_dir }}/test_sysctl" - - name: make sure our testing sub-directory does not exist - file: + - name: Make sure our testing sub-directory does not exist + ansible.builtin.file: path: "{{ output_dir_test }}" state: absent - - name: create our testing sub-directory - file: + - name: Create our testing sub-directory + ansible.builtin.file: path: "{{ output_dir_test }}" state: directory + mode: "0755" ## ## sysctl - file manipulation ## - - name: copy the example conf to the test dir - copy: + - name: Copy the example conf to the test dir + ansible.builtin.copy: src: sysctl.conf dest: "{{ output_dir_test }}" + mode: "0644" - name: Set vm.swappiness to 5 - sysctl: + ansible.posix.sysctl: name: vm.swappiness value: 5 state: present - reload: no + reload: false sysctl_file: "{{ output_dir_test }}/sysctl.conf" register: sysctl_test0 - - debug: + - name: Debug sysctl_test0 + ansible.builtin.debug: var: sysctl_test0 verbosity: 1 - - name: get file content - shell: "cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\\#" + - name: Get file content + ansible.builtin.shell: + cmd: set -o pipefail && cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\# + executable: /bin/bash + changed_when: false register: sysctl_content0 - - debug: + - name: Debug sysctl_content0 + ansible.builtin.debug: var: sysctl_content0 verbosity: 1 - name: Set vm.swappiness to 5 again - sysctl: - name: vm.swappiness - value: 5 - state: present - reload: no - sysctl_file: "{{ output_dir_test }}/sysctl.conf" + ansible.posix.sysctl: + name: vm.swappiness + value: 5 + state: present + reload: false + sysctl_file: "{{ output_dir_test }}/sysctl.conf" register: sysctl_test1 - - name: validate results - assert: - that: - - sysctl_test0 is changed - - sysctl_test1 is not changed - - 'sysctl_content0.stdout_lines[sysctl_content0.stdout_lines.index("vm.swappiness=5")] == "vm.swappiness=5"' + - name: Validate results + ansible.builtin.assert: + that: + - sysctl_test0 is changed + - sysctl_test1 is not changed + - sysctl_content0.stdout_lines[sysctl_content0.stdout_lines.index("vm.swappiness=5")] == "vm.swappiness=5" - name: Remove kernel.panic - sysctl: + ansible.posix.sysctl: name: kernel.panic value: 2 - reload: no + reload: false state: absent sysctl_file: "{{ output_dir_test }}/sysctl.conf" register: sysctl_test2 - - name: get file content - shell: "cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\\#" + - name: Get file content + ansible.builtin.shell: + cmd: set -o pipefail && cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\# + executable: /bin/bash + changed_when: false register: sysctl_content2 - - debug: + - name: Debug sysctl_test2 sysctl_content2 + ansible.builtin.debug: var: item verbosity: 1 with_items: @@ -104,38 +117,39 @@ - "{{ sysctl_content2 }}" - name: Validate results for key removal - assert: + ansible.builtin.assert: that: - sysctl_test2 is changed - "'kernel.panic' not in sysctl_content2.stdout_lines" - name: Test remove kernel.panic again - sysctl: + ansible.posix.sysctl: name: kernel.panic value: 2 state: absent - reload: no + reload: false sysctl_file: "{{ output_dir_test }}/sysctl.conf" register: sysctl_test2_change_test - name: Assert that no change was made - assert: + ansible.builtin.assert: that: - sysctl_test2_change_test is not changed - name: Try sysctl with an invalid name - sysctl: + ansible.posix.sysctl: name: test.invalid value: 1 register: sysctl_test3 - ignore_errors: yes + ignore_errors: true - - debug: + - name: Debug sysctl_test3 + ansible.builtin.debug: var: sysctl_test3 verbosity: 1 - - name: validate results for test 3 - assert: + - name: Validate results for test 3 + ansible.builtin.assert: that: - sysctl_test3 is failed @@ -143,77 +157,79 @@ ## sysctl - sysctl_set ## - - name: set net.ipv4.ip_forward - sysctl: + - name: Set net.ipv4.ip_forward + ansible.posix.sysctl: name: net.ipv4.ip_forward value: 1 - sysctl_set: yes - reload: no + sysctl_set: true + reload: false register: sysctl_test3 - - name: check with sysctl command - shell: sysctl net.ipv4.ip_forward + - name: Check with sysctl command + ansible.builtin.command: sysctl net.ipv4.ip_forward + changed_when: false register: sysctl_check3 - - debug: + - name: Debug sysctl_test3 sysctl_check3 + ansible.builtin.debug: var: item verbosity: 1 with_items: - "{{ sysctl_test3 }}" - "{{ sysctl_check3 }}" - - name: validate results for test 3 - assert: + - name: Validate results for test 3 + ansible.builtin.assert: that: - sysctl_test3 is changed - - 'sysctl_check3.stdout_lines == ["net.ipv4.ip_forward = 1"]' + - sysctl_check3.stdout_lines == ["net.ipv4.ip_forward = 1"] - name: Try sysctl with no name - sysctl: + ansible.posix.sysctl: name: "" value: 1 - sysctl_set: yes - ignore_errors: True + sysctl_set: true + ignore_errors: true register: sysctl_no_name - - name: validate nameless results - assert: + - name: Validate nameless results + ansible.builtin.assert: that: - sysctl_no_name is failed - - "sysctl_no_name.msg == 'name cannot be blank'" + - sysctl_no_name.msg == 'name cannot be blank' - name: Try sysctl with no value - sysctl: + ansible.posix.sysctl: name: Foo value: - sysctl_set: yes - ignore_errors: True + sysctl_set: true + ignore_errors: true register: sysctl_no_value - - name: validate nameless results - assert: + - name: Validate nameless results + ansible.builtin.assert: that: - sysctl_no_value is failed - - "sysctl_no_value.msg == 'value cannot be None'" + - sysctl_no_value.msg == 'value cannot be None' - name: Try sysctl with an invalid name - sysctl: + ansible.posix.sysctl: name: test.invalid value: 1 - sysctl_set: yes + sysctl_set: true register: sysctl_test4 - ignore_errors: yes + ignore_errors: true - - debug: + - name: Debug sysctl_test4 + ansible.builtin.debug: var: sysctl_test4 verbosity: 1 - - name: validate results for test 4 - assert: + - name: Validate results for test 4 + ansible.builtin.assert: that: - sysctl_test4 is failed - - name: Test on RHEL VMs when: - ansible_facts.virtualization_type != 'docker' @@ -221,34 +237,37 @@ block: # Test reload: yes - name: Set sysctl property using module - sysctl: + ansible.posix.sysctl: name: vm.swappiness - value: '22' + value: "22" state: present - reload: yes + reload: true register: sysctl_set1 - name: Change sysctl property using command - command: sysctl vm.swappiness=33 + ansible.builtin.command: sysctl vm.swappiness=33 + changed_when: true - name: Set sysctl property using module - sysctl: + ansible.posix.sysctl: name: vm.swappiness - value: '22' + value: "22" state: present - reload: yes + reload: true register: sysctl_set2 - name: Read /etc/sysctl.conf - command: 'egrep -v ^# /etc/sysctl.conf' + ansible.builtin.command: egrep -v ^# /etc/sysctl.conf + changed_when: false register: sysctl_conf_content - name: Get current value of vm.swappiness - command: sysctl -n vm.swappiness + ansible.builtin.command: sysctl -n vm.swappiness + changed_when: false register: sysctl_current_vm_swappiness - name: Ensure changes were made appropriately - assert: + ansible.builtin.assert: that: - sysctl_set1 is changed - sysctl_set2 is changed @@ -257,33 +276,35 @@ # Test reload: yes in check mode - name: Set the same value using module in check mode - sysctl: + ansible.posix.sysctl: name: vm.swappiness - value: '22' + value: "22" state: present - reload: yes - check_mode: yes + reload: true + check_mode: true register: sysctl_check_mode1 - name: Set a different value using module in check mode - sysctl: + ansible.posix.sysctl: name: vm.swappiness - value: '44' + value: "44" state: present - reload: yes - check_mode: yes + reload: true + check_mode: true register: sysctl_check_mode2 - name: Read /etc/sysctl.conf - command: 'egrep -v ^# /etc/sysctl.conf' + ansible.builtin.command: egrep -v ^# /etc/sysctl.conf + changed_when: false register: sysctl_check_mode_conf_content - name: Get current value of vm.swappiness - command: sysctl -n vm.swappiness + ansible.builtin.command: sysctl -n vm.swappiness + changed_when: false register: sysctl_check_mode_current_vm_swappiness - name: Ensure no changes were made in check mode - assert: + ansible.builtin.assert: that: - sysctl_check_mode1 is success - sysctl_check_mode2 is changed @@ -292,21 +313,22 @@ # Test sysctl: invalid value - name: Set invalid sysctl property using module - sysctl: + ansible.posix.sysctl: name: vm.mmap_rnd_bits - value: '1024' + value: "1024" state: present - reload: yes - sysctl_set: True - ignore_errors: True + reload: true + sysctl_set: true + ignore_errors: true register: sysctl_invalid_set1 - name: Read /etc/sysctl.conf - command: 'cat /etc/sysctl.conf' + ansible.builtin.command: cat /etc/sysctl.conf + changed_when: false register: sysctl_invalid_conf_content - name: Ensure changes were not made - assert: + ansible.builtin.assert: that: - sysctl_invalid_set1 is failed - "'vm.mmap_rnd_bits' not in sysctl_invalid_conf_content.stdout" diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 0b6905e..caf2217 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -1,8 +1,2 @@ -plugins/modules/synchronize.py pylint:disallowed-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index 0b6905e..caf2217 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -1,8 +1,2 @@ -plugins/modules/synchronize.py pylint:disallowed-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index d196952..3cf68c0 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -1,7 +1 @@ -plugins/modules/synchronize.py pylint:disallowed-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt index d196952..3cf68c0 100644 --- a/tests/sanity/ignore-2.17.txt +++ b/tests/sanity/ignore-2.17.txt @@ -1,7 +1 @@ -plugins/modules/synchronize.py pylint:disallowed-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt deleted file mode 100644 index 013403f..0000000 --- a/tests/sanity/ignore-2.9.txt +++ /dev/null @@ -1,8 +0,0 @@ -plugins/modules/synchronize.py pylint:blacklisted-name -plugins/modules/synchronize.py use-argspec-type-path -plugins/modules/synchronize.py validate-modules:doc-default-does-not-match-spec -plugins/modules/synchronize.py validate-modules:nonexistent-parameter-documented -plugins/modules/synchronize.py validate-modules:parameter-type-not-in-doc -plugins/modules/synchronize.py validate-modules:undocumented-parameter -tests/utils/shippable/check_matrix.py replace-urlopen -tests/utils/shippable/timing.py shebang diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic/meta.yaml index 7608ebf..28b7045 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic/meta.yaml @@ -1,17 +1,18 @@ +--- fixtures: - taskvars_in: taskvars_in.json - taskvars_out: taskvars_out.json + taskvars_in: taskvars_in.json + taskvars_out: taskvars_out.json connection: - transport: 'ssh' + transport: ssh hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self._play_context.shell == 'sh'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self._play_context.shell == 'sh' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic_become/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic_become/meta.yaml index 8435735..1eb0b92 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic_become/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic_become/meta.yaml @@ -1,39 +1,40 @@ +--- task_args: - src: /tmp/deleteme - dest: /tmp/deleteme - #rsync_path: rsync + src: /tmp/deleteme + dest: /tmp/deleteme +# rsync_path: rsync _task: - become: True - become_method: None + become: true + become_method: None fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json connection: - transport: 'ssh' + transport: ssh _play_context: - become: True - become_method: sudo - remote_addr: el6host - remote_user: root + become: true + become_method: sudo + remote_addr: el6host + remote_user: root hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - # this is a crucial aspect of this scenario ... - # note: become_user None -> root - - "self.final_module_args['rsync_path'] == 'sudo -u root rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" - - "self.task.become == True" - - "self.task.become_user == None" - - "self._play_context.shell == 'sh'" - - "self._play_context.remote_addr == 'el6host'" - - "self._play_context.remote_user == 'root'" - - "self._play_context.become == False" - - "self._play_context.become_user == 'root'" - - "self._play_context.password == None" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + # this is a crucial aspect of this scenario ... + # note: become_user None -> root + - self.final_module_args['rsync_path'] == 'sudo -u root rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' + - self.task.become == True + - self.task.become_user == None + - self._play_context.shell == 'sh' + - self._play_context.remote_addr == 'el6host' + - self._play_context.remote_user == 'root' + - self._play_context.become == False + - self._play_context.become_user == 'root' + - self._play_context.password == None diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic_become_cli/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic_become_cli/meta.yaml index 294bfde..1bec3b4 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic_become_cli/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic_become_cli/meta.yaml @@ -1,39 +1,40 @@ +--- task_args: - src: /tmp/deleteme - dest: /tmp/deleteme - #rsync_path: rsync + src: /tmp/deleteme + dest: /tmp/deleteme +# rsync_path: rsync _task: - become: None - become_method: None + become: None + become_method: None fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json connection: - transport: 'ssh' + transport: ssh _play_context: - become: True - become_method: sudo - remote_addr: el6host - remote_user: root + become: true + become_method: sudo + remote_addr: el6host + remote_user: root hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - # this is a crucial aspect of this scenario ... - # note: become_user None -> root - - "self.final_module_args['rsync_path'] == 'sudo -u root rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" - - "self.task.become == None" - - "self.task.become_user == None" - - "self._play_context.shell == 'sh'" - - "self._play_context.remote_addr == 'el6host'" - - "self._play_context.remote_user == 'root'" - - "self._play_context.become == False" - - "self._play_context.become_user == 'root'" - - "self._play_context.password == None" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + # this is a crucial aspect of this scenario ... + # note: become_user None -> root + - self.final_module_args['rsync_path'] == 'sudo -u root rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' + - self.task.become == None + - self.task.become_user == None + - self._play_context.shell == 'sh' + - self._play_context.remote_addr == 'el6host' + - self._play_context.remote_user == 'root' + - self._play_context.become == False + - self._play_context.become_user == 'root' + - self._play_context.password == None diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant/meta.yaml index 7654cc6..574ee6a 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant/meta.yaml @@ -1,29 +1,30 @@ +--- task_args: - src: /tmp/deleteme - dest: /tmp/deleteme + src: /tmp/deleteme + dest: /tmp/deleteme fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json connection: - transport: 'ssh' + transport: ssh _play_context: - remote_addr: '127.0.0.1' - remote_user: vagrant + remote_addr: 127.0.0.1 + remote_user: vagrant hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['dest_port'] == 2202" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'" - - "self._play_context.shell == 'sh'" - - "self._play_context.remote_addr == '127.0.0.1'" - - "self._play_context.remote_user == 'vagrant'" - - "self._play_context.become == False" - - "self._play_context.become_user == 'root'" - - "self._play_context.password == None" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['dest_port'] == 2202 + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme' + - self._play_context.shell == 'sh' + - self._play_context.remote_addr == '127.0.0.1' + - self._play_context.remote_user == 'vagrant' + - self._play_context.become == False + - self._play_context.become_user == 'root' + - self._play_context.password == None diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_become_cli/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_become_cli/meta.yaml index 242de92..eb0d5b1 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_become_cli/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_become_cli/meta.yaml @@ -1,32 +1,33 @@ +--- task: - #become: None +# become: None task_args: - src: /tmp/deleteme - dest: /tmp/deleteme + src: /tmp/deleteme + dest: /tmp/deleteme fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json connection: - transport: 'ssh' + transport: ssh _play_context: - become: True - remote_addr: '127.0.0.1' - remote_user: vagrant + become: true + remote_addr: 127.0.0.1 + remote_user: vagrant hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['dest_port'] == 2202" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'" - - "self._play_context.shell == 'sh'" - - "self._play_context.remote_addr == '127.0.0.1'" - - "self._play_context.remote_user == 'vagrant'" - - "self._play_context.become == False" - - "self._play_context.become_user == 'root'" - - "self._play_context.password == None" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['dest_port'] == 2202 + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme' + - self._play_context.shell == 'sh' + - self._play_context.remote_addr == '127.0.0.1' + - self._play_context.remote_user == 'vagrant' + - self._play_context.become == False + - self._play_context.become_user == 'root' + - self._play_context.password == None diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_sudo/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_sudo/meta.yaml index 7654cc6..574ee6a 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_sudo/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic_vagrant_sudo/meta.yaml @@ -1,29 +1,30 @@ +--- task_args: - src: /tmp/deleteme - dest: /tmp/deleteme + src: /tmp/deleteme + dest: /tmp/deleteme fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json connection: - transport: 'ssh' + transport: ssh _play_context: - remote_addr: '127.0.0.1' - remote_user: vagrant + remote_addr: 127.0.0.1 + remote_user: vagrant hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['dest_port'] == 2202" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'" - - "self._play_context.shell == 'sh'" - - "self._play_context.remote_addr == '127.0.0.1'" - - "self._play_context.remote_user == 'vagrant'" - - "self._play_context.become == False" - - "self._play_context.become_user == 'root'" - - "self._play_context.password == None" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['dest_port'] == 2202 + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme' + - self._play_context.shell == 'sh' + - self._play_context.remote_addr == '127.0.0.1' + - self._play_context.remote_user == 'vagrant' + - self._play_context.become == False + - self._play_context.become_user == 'root' + - self._play_context.password == None diff --git a/tests/unit/plugins/action/fixtures/synchronize/basic_with_private_key/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/basic_with_private_key/meta.yaml index 9b227e0..7405cb6 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/basic_with_private_key/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/basic_with_private_key/meta.yaml @@ -1,25 +1,26 @@ +--- fixtures: - taskvars_in: taskvars_in.json - taskvars_out: taskvars_out.json + taskvars_in: taskvars_in.json + taskvars_out: taskvars_out.json connection: - transport: 'ssh' + transport: ssh hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} _play_context: - private_key_file: ~/test.pem + private_key_file: ~/test.pem task_args: - private_key: ~/.ssh/id_rsa - dest: /tmp/deleteme - src: /tmp/deleteme + private_key: ~/.ssh/id_rsa + dest: /tmp/deleteme + src: /tmp/deleteme asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'local'" - - "self._play_context.shell == 'sh'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" - - "self.final_module_args['private_key'] == '~/.ssh/id_rsa'" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'local' + - self._play_context.shell == 'sh' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' + - self.final_module_args['private_key'] == '~/.ssh/id_rsa' diff --git a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml index 1c55b28..e943b79 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote/meta.yaml @@ -1,26 +1,27 @@ +--- fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json task_args: - src: /tmp/deleteme - dest: /tmp/deleteme + src: /tmp/deleteme + dest: /tmp/deleteme _task: - delegate_to: u1404 + delegate_to: u1404 _play_context: - shell: None - remote_addr: u1404 - remote_user: root + shell: None + remote_addr: u1404 + remote_user: root connection: - transport: 'ssh' + transport: ssh hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'ssh'" - - "self._play_context.shell == None" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'ssh' + - self._play_context.shell == None + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' diff --git a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_play_context_private_key/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_play_context_private_key/meta.yaml index 31939ca..2d88e63 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_play_context_private_key/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_play_context_private_key/meta.yaml @@ -1,28 +1,29 @@ +--- fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json task_args: - src: /tmp/deleteme - dest: /tmp/deleteme + src: /tmp/deleteme + dest: /tmp/deleteme _task: - delegate_to: u1404 + delegate_to: u1404 _play_context: - shell: None - remote_addr: u1404 - remote_user: root - private_key_file: ~/test.pem + shell: None + remote_addr: u1404 + remote_user: root + private_key_file: ~/test.pem connection: - transport: 'ssh' + transport: ssh hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'ssh'" - - "self._play_context.shell == None" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" - - "self.final_module_args['private_key'] == '~/test.pem'" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'ssh' + - self._play_context.shell == None + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' + - self.final_module_args['private_key'] == '~/test.pem' diff --git a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml index 28e35c9..34df19d 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_su/meta.yaml @@ -1,33 +1,34 @@ +--- fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json task_args: - src: /tmp/deleteme - dest: /tmp/deleteme + src: /tmp/deleteme + dest: /tmp/deleteme _task: - delegate_to: u1404 + delegate_to: u1404 _play_context: - become: True - become_user: None #if ! None|root, different testcase - become_method: su - shell: None - remote_addr: u1404 - remote_user: root + become: true + become_user: None # if ! None|root, different testcase + become_method: su + shell: None + remote_addr: u1404 + remote_user: root connection: - transport: 'ssh' + transport: ssh hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'ssh'" - - "self._play_context.shell == None" - - "self._play_context.remote_addr == 'u1404'" - - "self._play_context.remote_user == 'root'" - - "not self._play_context.become" - - "self._play_context.become_method == 'su'" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'ssh' + - self._play_context.shell == None + - self._play_context.remote_addr == 'u1404' + - self._play_context.remote_user == 'root' + - not self._play_context.become + - self._play_context.become_method == 'su' + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' diff --git a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_with_private_key/meta.yaml b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_with_private_key/meta.yaml index 1242b1d..603a4cb 100644 --- a/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_with_private_key/meta.yaml +++ b/tests/unit/plugins/action/fixtures/synchronize/delegate_remote_with_private_key/meta.yaml @@ -1,29 +1,30 @@ +--- fixtures: - taskvars_in: task_vars_in.json - taskvars_out: task_vars_out.json + taskvars_in: task_vars_in.json + taskvars_out: task_vars_out.json task_args: - src: /tmp/deleteme - dest: /tmp/deleteme - private_key: ~/.ssh/id_rsa + src: /tmp/deleteme + dest: /tmp/deleteme + private_key: ~/.ssh/id_rsa _task: - delegate_to: u1404 + delegate_to: u1404 _play_context: - shell: None - remote_addr: u1404 - remote_user: root - private_key_file: ~/test.pem + shell: None + remote_addr: u1404 + remote_user: root + private_key_file: ~/test.pem connection: - transport: 'ssh' + transport: ssh hostvars: - '127.0.0.1': {} - '::1': {} - 'localhost': {} + 127.0.0.1: {} + ::1: {} + localhost: {} asserts: - - "hasattr(SAM._connection, 'ismock')" - - "SAM._connection.transport == 'ssh'" - - "self._play_context.shell == None" - - "self.execute_called" - - "self.final_module_args['_local_rsync_path'] == 'rsync'" - - "self.final_module_args['src'] == '/tmp/deleteme'" - - "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'" - - "self.final_module_args['private_key'] == '~/.ssh/id_rsa'" + - hasattr(SAM._connection, 'ismock') + - SAM._connection.transport == 'ssh' + - self._play_context.shell == None + - self.execute_called + - self.final_module_args['_local_rsync_path'] == 'rsync' + - self.final_module_args['src'] == '/tmp/deleteme' + - self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme' + - self.final_module_args['private_key'] == '~/.ssh/id_rsa' diff --git a/tests/unit/requirements.yml b/tests/unit/requirements.yml index 08e2610..8dd5161 100644 --- a/tests/unit/requirements.yml +++ b/tests/unit/requirements.yml @@ -1,3 +1,3 @@ --- collections: -- community.general + - community.general From 046f6d1483c195fda72bc984d21a644411ea6554 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 11 Dec 2023 10:18:12 -0500 Subject: [PATCH 102/109] update ci target for freebsd 13, r1 is eol --- .azure-pipelines/azure-pipelines.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index d02f9de..0d81188 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -209,8 +209,8 @@ stages: test: rhel/8.7 - name: RHEL 9.1 test: rhel/9.1 - - name: FreeBSD 13.1 - test: freebsd/13.1 + - name: FreeBSD 13.2 + test: freebsd/13.2 - name: FreeBSD 12.4 test: freebsd/12.4 - stage: Remote_2_14 @@ -225,8 +225,8 @@ stages: test: rhel/7.9 - name: RHEL 8.6 test: rhel/8.6 - - name: FreeBSD 13.1 - test: freebsd/13.1 + - name: FreeBSD 13.2 + test: freebsd/13.2 - name: FreeBSD 12.4 test: freebsd/12.4 From 45d8819b7c5eaee656688e8330e692ec6a3d22c4 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 9 Jan 2024 07:25:45 +0100 Subject: [PATCH 103/109] Remove Shippable leftovers. --- tests/utils/shippable/shippable.sh | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index 1cff6d8..6269f57 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -62,16 +62,7 @@ else retry pip install "https://github.com/ansible/ansible/archive/stable-${ansible_version}.tar.gz" --disable-pip-version-check fi -if [ "${SHIPPABLE_BUILD_ID:-}" ]; then - export ANSIBLE_COLLECTIONS_PATHS="${HOME}/.ansible" - SHIPPABLE_RESULT_DIR="$(pwd)/shippable" - TEST_DIR="${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/ansible/posix" - mkdir -p "${TEST_DIR}" - cp -aT "${SHIPPABLE_BUILD_DIR}" "${TEST_DIR}" - cd "${TEST_DIR}" -else - export ANSIBLE_COLLECTIONS_PATHS="${PWD}/../../../" -fi +export ANSIBLE_COLLECTIONS_PATHS="${PWD}/../../../" # START: HACK install dependencies if [ "${ansible_version}" == "2.9" ] || [ "${ansible_version}" == "2.10" ]; then From 8e900e5218ddece901624dc223b8a2b4c0081fb1 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 9 Jan 2024 07:30:04 +0100 Subject: [PATCH 104/109] Support for FreeBSD 12.4 was removed. --- .azure-pipelines/azure-pipelines.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index 0d81188..498e5f8 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -211,8 +211,6 @@ stages: test: rhel/9.1 - name: FreeBSD 13.2 test: freebsd/13.2 - - name: FreeBSD 12.4 - test: freebsd/12.4 - stage: Remote_2_14 displayName: Remote 2.14 dependsOn: [] @@ -227,8 +225,6 @@ stages: test: rhel/8.6 - name: FreeBSD 13.2 test: freebsd/13.2 - - name: FreeBSD 12.4 - test: freebsd/12.4 ## Finally From 2a1fb334ee7c10335b8b309ad38294a05fe3e7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Wed, 10 Jan 2024 00:06:26 +0200 Subject: [PATCH 105/109] mount: edit boot parameters warning condition (#523) the CI failures are unrelated and shouldn't even be showing up ... I'm going to sort that out separately but that doesn't need to prevent this merge, all relevant CI tests passed --- plugins/modules/mount.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/mount.py b/plugins/modules/mount.py index d28ae38..1fdf276 100644 --- a/plugins/modules/mount.py +++ b/plugins/modules/mount.py @@ -831,7 +831,7 @@ def main(): # handle mount on boot. To avoid mount option conflicts, if 'noauto' # specified in 'opts', mount module will ignore 'boot'. opts = args['opts'].split(',') - if 'noauto' in opts: + if module.params['boot'] and 'noauto' in opts: args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'noauto'.") elif not module.params['boot']: args['boot'] = 'no' From 0847977d1216cbe2b09a22900210343812591d6c Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Tue, 9 Jan 2024 23:07:58 +0100 Subject: [PATCH 106/109] Warn only when zones were ignored in firewalld_info (#504) * warn only when zones were ignored * add changelog 504-firewalld_info-warning --- changelogs/fragments/504-firewalld_info-warning.yaml | 2 ++ plugins/modules/firewalld_info.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/504-firewalld_info-warning.yaml diff --git a/changelogs/fragments/504-firewalld_info-warning.yaml b/changelogs/fragments/504-firewalld_info-warning.yaml new file mode 100644 index 0000000..73e00aa --- /dev/null +++ b/changelogs/fragments/504-firewalld_info-warning.yaml @@ -0,0 +1,2 @@ +minor_changes: + - firewalld_info - Only warn about ignored zones, when there are zones ignored. diff --git a/plugins/modules/firewalld_info.py b/plugins/modules/firewalld_info.py index 8b5c80c..c83437d 100644 --- a/plugins/modules/firewalld_info.py +++ b/plugins/modules/firewalld_info.py @@ -356,8 +356,9 @@ def main(): specified_zones = module.params['zones'] collect_zones = list(set(specified_zones) & set(all_zones)) ignore_zones = list(set(specified_zones) - set(collect_zones)) - warn.append( - 'Please note: zone:(%s) have been ignored in the gathering process.' % ','.join(ignore_zones)) + if ignore_zones: + warn.append( + 'Please note: zone:(%s) have been ignored in the gathering process.' % ','.join(ignore_zones)) else: collect_zones = get_all_zones(client) From e929aad539c46b8fa01bfcb393504ff306b3bce5 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:24:45 -0500 Subject: [PATCH 107/109] remove deprecated internal argument from synchronize (#421) * remove deprecated internal argument from synchronize the new_stdin argument is no longer used to instantiate a connection plugin * add a changelog --- changelogs/fragments/421-remove-deprecation-warning.yml | 2 ++ plugins/action/synchronize.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/421-remove-deprecation-warning.yml diff --git a/changelogs/fragments/421-remove-deprecation-warning.yml b/changelogs/fragments/421-remove-deprecation-warning.yml new file mode 100644 index 0000000..5224f1e --- /dev/null +++ b/changelogs/fragments/421-remove-deprecation-warning.yml @@ -0,0 +1,2 @@ +trivial: + - synchronize - instantiate the connection plugin without the ``new_stdin`` argument, which is deprecated in ansible-core 2.15 (https://github.com/ansible-collections/ansible.posix/pull/421). diff --git a/plugins/action/synchronize.py b/plugins/action/synchronize.py index dd780b9..34c9015 100644 --- a/plugins/action/synchronize.py +++ b/plugins/action/synchronize.py @@ -284,9 +284,6 @@ class ActionModule(ActionBase): # told (via delegate_to) that a different host is the source of the # rsync if not use_delegate and remote_transport: - # Create a connection to localhost to run rsync on - new_stdin = self._connection._new_stdin - # Unlike port, there can be only one shell localhost_shell = None for host in C.LOCALHOST: @@ -315,7 +312,11 @@ class ActionModule(ActionBase): localhost_executable = C.DEFAULT_EXECUTABLE self._play_context.executable = localhost_executable - new_connection = connection_loader.get('local', self._play_context, new_stdin) + try: + new_connection = connection_loader.get('local', self._play_context) + except TypeError: + # Needed for ansible-core < 2.15 + new_connection = connection_loader.get('local', self._play_context, self._connection._new_stdin) self._connection = new_connection # Override _remote_is_local as an instance attribute specifically for the synchronize use case # ensuring we set local tmpdir correctly From 0a07bdb358de41b4ca2ba288567988e3828e4752 Mon Sep 17 00:00:00 2001 From: Petr Lautrbach Date: Tue, 6 Feb 2024 16:21:27 +0100 Subject: [PATCH 108/109] seboolean: make it work with disabled SELinux (#496) Sometimes it's necessary to configure SELinux before it's enabled on the system. There's `ignore_selinux_state` which should allow it. Before this change `seboolean` module failed on SELinux disabled system even with `ignore_selinux_state: true` and SELinux policy installed while `semanage boolean` worked as expected: $ ansible -i 192.168.121.153, -m seboolean -a "name=ssh_sysadm_login state=on ignore_selinux_state=true" all 192.168.121.153 | FAILED! => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "msg": "Failed to get list of boolean names" } $ ssh root@192.168.121.153 semanage boolean -l | grep ssh_sysadm_login ssh_sysadm_login (off , off) Allow ssh to sysadm login It's caused by `selinux.security_get_boolean_names()` and `selinux.security_get_boolean_active(name)` which required SELinux enabled system. This change adds a fallback to semanage API which works in SELinux disabled system when SELinux targeted policy is installed: ANSIBLE_LIBRARY=plugins/modules ansible -i 192.168.121.153, -m seboolean -a "name=ssh_sysadm_login state=on persistent=true ignore_selinux_state=true" all 192.168.121.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": true, "name": "ssh_sysadm_login", "persistent": true, "state": true } $ ssh root@192.168.121.153 semanage boolean -l | grep ssh_sysadm_login ssh_sysadm_login (on , on) Allow ssh to sysadm login Note that without `persistent=true` this module is effectively NO-OP now. Signed-off-by: Petr Lautrbach --- ...ean-make-it-wrk-with-SELinux-disabled.yaml | 3 ++ plugins/modules/seboolean.py | 30 ++++--------------- 2 files changed, 9 insertions(+), 24 deletions(-) create mode 100644 changelogs/fragments/496_seboolean-make-it-wrk-with-SELinux-disabled.yaml diff --git a/changelogs/fragments/496_seboolean-make-it-wrk-with-SELinux-disabled.yaml b/changelogs/fragments/496_seboolean-make-it-wrk-with-SELinux-disabled.yaml new file mode 100644 index 0000000..e14cfa6 --- /dev/null +++ b/changelogs/fragments/496_seboolean-make-it-wrk-with-SELinux-disabled.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - seboolean - make it work with disabled SELinux diff --git a/plugins/modules/seboolean.py b/plugins/modules/seboolean.py index 0d23073..1e73aef 100644 --- a/plugins/modules/seboolean.py +++ b/plugins/modules/seboolean.py @@ -73,8 +73,7 @@ except ImportError: HAVE_SEMANAGE = False from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.six import binary_type -from ansible.module_utils._text import to_bytes, to_text +from ansible.module_utils._text import to_text from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL @@ -82,23 +81,6 @@ def get_runtime_status(ignore_selinux_state=False): return True if ignore_selinux_state is True else selinux.is_selinux_enabled() -def has_boolean_value(module, name): - bools = [] - try: - rc, bools = selinux.security_get_boolean_names() - except OSError: - module.fail_json(msg="Failed to get list of boolean names") - # work around for selinux who changed its API, see - # https://github.com/ansible/ansible/issues/25651 - if len(bools) > 0: - if isinstance(bools[0], binary_type): - name = to_bytes(name) - if name in bools: - return True - else: - return False - - def get_boolean_value(module, name): state = 0 try: @@ -174,7 +156,10 @@ def semanage_set_boolean_value(module, handle, name, value): semanage.semanage_handle_destroy(handle) module.fail_json(msg="Failed to modify boolean key with semanage") - if semanage.semanage_bool_set_active(handle, boolkey, sebool) < 0: + if ( + selinux.is_selinux_enabled() + and semanage.semanage_bool_set_active(handle, boolkey, sebool) < 0 + ): semanage.semanage_handle_destroy(handle) module.fail_json(msg="Failed to set boolean key active with semanage") @@ -315,12 +300,9 @@ def main(): # Feature only available in selinux library since 2012. name = selinux.selinux_boolean_sub(name) - if not has_boolean_value(module, name): - module.fail_json(msg="SELinux boolean %s does not exist." % name) - if persistent: changed = semanage_boolean_value(module, name, state) - else: + elif selinux.is_selinux_enabled(): cur_value = get_boolean_value(module, name) if cur_value != state: changed = True From 51b94f536c0e809fea14e8a1d7355f1c258f7cc6 Mon Sep 17 00:00:00 2001 From: Marty Winkler Date: Tue, 6 Feb 2024 16:21:42 +0100 Subject: [PATCH 109/109] Feat/add summary only option to profile callbacks (#511) * profile_tasks callback: add parameter to show only summary --- ...e-callbacks-add-summary-only-parameter.yml | 3 ++ plugins/callback/profile_roles.py | 32 +++++++++++++++++-- plugins/callback/profile_tasks.py | 25 +++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/511_profile-callbacks-add-summary-only-parameter.yml diff --git a/changelogs/fragments/511_profile-callbacks-add-summary-only-parameter.yml b/changelogs/fragments/511_profile-callbacks-add-summary-only-parameter.yml new file mode 100644 index 0000000..2347dd3 --- /dev/null +++ b/changelogs/fragments/511_profile-callbacks-add-summary-only-parameter.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "Add summary_only parameter to profile_roles and profile_tasks callbacks." diff --git a/plugins/callback/profile_roles.py b/plugins/callback/profile_roles.py index 13dae0c..59a437f 100644 --- a/plugins/callback/profile_roles.py +++ b/plugins/callback/profile_roles.py @@ -14,6 +14,19 @@ DOCUMENTATION = ''' - This callback module provides profiling for ansible roles. requirements: - whitelisting in configuration + options: + summary_only: + description: + - Only show summary, not individual task profiles. + Especially usefull in combination with C(DISPLAY_SKIPPED_HOSTS=false) and/or C(ANSIBLE_DISPLAY_OK_HOSTS=false). + type: bool + default: False + env: + - name: PROFILE_ROLES_SUMMARY_ONLY + ini: + - section: callback_profile_roles + key: summary_only + version_added: 1.5.0 ''' import collections @@ -76,13 +89,26 @@ class CallbackModule(CallbackBase): self.stats = collections.Counter() self.totals = collections.Counter() self.current = None + + self.summary_only = None + super(CallbackModule, self).__init__() + def set_options(self, task_keys=None, var_options=None, direct=None): + + super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct) + + self.summary_only = self.get_option('summary_only') + + def _display_tasktime(self): + if not self.summary_only: + self._display.display(tasktime()) + def _record_task(self, task): """ Logs the start of each task """ - self._display.display(tasktime()) + self._display_tasktime() timestamp(self) if task._role: @@ -99,10 +125,10 @@ class CallbackModule(CallbackBase): self._record_task(task) def playbook_on_setup(self): - self._display.display(tasktime()) + self._display_tasktime() def playbook_on_stats(self, stats): - 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 944b222..5fb7972 100644 --- a/plugins/callback/profile_tasks.py +++ b/plugins/callback/profile_tasks.py @@ -40,6 +40,18 @@ DOCUMENTATION = ''' ini: - section: callback_profile_tasks key: sort_order + summary_only: + description: + - Only show summary, not individual task profiles. + Especially usefull in combination with C(DISPLAY_SKIPPED_HOSTS=false) and/or C(ANSIBLE_DISPLAY_OK_HOSTS=false). + type: bool + default: False + env: + - name: PROFILE_TASKS_SUMMARY_ONLY + ini: + - section: callback_profile_tasks + key: summary_only + version_added: 1.5.0 ''' EXAMPLES = ''' @@ -120,6 +132,7 @@ class CallbackModule(CallbackBase): self.current = None self.sort_order = None + self.summary_only = None self.task_output_limit = None super(CallbackModule, self).__init__() @@ -137,6 +150,8 @@ class CallbackModule(CallbackBase): elif self.sort_order == 'none': self.sort_order = None + self.summary_only = self.get_option('summary_only') + self.task_output_limit = self.get_option('output_limit') if self.task_output_limit is not None: if self.task_output_limit == 'all': @@ -144,11 +159,15 @@ class CallbackModule(CallbackBase): else: self.task_output_limit = int(self.task_output_limit) + def _display_tasktime(self): + if not self.summary_only: + self._display.display(tasktime()) + def _record_task(self, task): """ Logs the start of each task """ - self._display.display(tasktime()) + self._display_tasktime() timestamp(self) # Record the start time of the current task @@ -171,10 +190,10 @@ class CallbackModule(CallbackBase): self._record_task(task) def playbook_on_setup(self): - self._display.display(tasktime()) + self._display_tasktime() def playbook_on_stats(self, stats): - self._display.display(tasktime()) + self._display_tasktime() self._display.display(filled("", fchar="=")) timestamp(self)