summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/general/tests/integration
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 06:22:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 06:22:20 +0000
commit18bd2207b6c1977e99a93673a7be099e23f0f547 (patch)
tree40fd9e5913462a88be6ba24be6953383c5b39874 /ansible_collections/community/general/tests/integration
parentReleasing progress-linux version 10.0.1+dfsg-1~progress7.99u1. (diff)
downloadansible-18bd2207b6c1977e99a93673a7be099e23f0f547.tar.xz
ansible-18bd2207b6c1977e99a93673a7be099e23f0f547.zip
Merging upstream version 10.1.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/general/tests/integration')
-rw-r--r--ansible_collections/community/general/tests/integration/targets/ansible_galaxy_install/tasks/main.yml55
-rw-r--r--ansible_collections/community/general/tests/integration/targets/cargo/tasks/main.yml1
-rw-r--r--ansible_collections/community/general/tests/integration/targets/cargo/tasks/test_directory.yml122
-rw-r--r--ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_check.yml114
-rw-r--r--ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_service.yml89
-rw-r--r--ansible_collections/community/general/tests/integration/targets/consul/tasks/main.yml2
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_keep_keys/aliases5
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/keep_keys.yml79
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/main.yml7
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_keep_keys/vars/main.yml33
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_remove_keys/aliases5
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/main.yml7
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/remove_keys.yml79
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_remove_keys/vars/main.yml33
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_replace_keys/aliases5
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/fn-test-replace_keys.yml21
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/main.yml7
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/replace_keys.yml56
-rw-r--r--ansible_collections/community/general/tests/integration/targets/filter_replace_keys/vars/main.yml58
-rw-r--r--ansible_collections/community/general/tests/integration/targets/git_config/tasks/unset_value.yml24
-rw-r--r--ansible_collections/community/general/tests/integration/targets/keycloak_client/tasks/main.yml128
21 files changed, 930 insertions, 0 deletions
diff --git a/ansible_collections/community/general/tests/integration/targets/ansible_galaxy_install/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/ansible_galaxy_install/tasks/main.yml
index 1ecd9980d..5c4af6d16 100644
--- a/ansible_collections/community/general/tests/integration/targets/ansible_galaxy_install/tasks/main.yml
+++ b/ansible_collections/community/general/tests/integration/targets/ansible_galaxy_install/tasks/main.yml
@@ -4,10 +4,16 @@
# SPDX-License-Identifier: GPL-3.0-or-later
###################################################
+- name: Make directory install_c
+ ansible.builtin.file:
+ path: "{{ remote_tmp_dir }}/install_c"
+ state: directory
+
- name: Install collection netbox.netbox
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox
+ dest: "{{ remote_tmp_dir }}/install_c"
register: install_c0
- name: Assert collection netbox.netbox was installed
@@ -20,6 +26,7 @@
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox
+ dest: "{{ remote_tmp_dir }}/install_c"
register: install_c1
- name: Assert collection was not installed
@@ -28,10 +35,16 @@
- install_c1 is not changed
###################################################
+- name: Make directory install_r
+ ansible.builtin.file:
+ path: "{{ remote_tmp_dir }}/install_r"
+ state: directory
+
- name: Install role ansistrano.deploy
community.general.ansible_galaxy_install:
type: role
name: ansistrano.deploy
+ dest: "{{ remote_tmp_dir }}/install_r"
register: install_r0
- name: Assert collection ansistrano.deploy was installed
@@ -44,6 +57,7 @@
community.general.ansible_galaxy_install:
type: role
name: ansistrano.deploy
+ dest: "{{ remote_tmp_dir }}/install_r"
register: install_r1
- name: Assert role was not installed
@@ -86,3 +100,44 @@
assert:
that:
- install_rq1 is not changed
+
+###################################################
+- name: Make directory upgrade_c
+ ansible.builtin.file:
+ path: "{{ remote_tmp_dir }}/upgrade_c"
+ state: directory
+
+- name: Install collection netbox.netbox 3.17.0
+ community.general.ansible_galaxy_install:
+ type: collection
+ name: netbox.netbox:3.17.0
+ dest: "{{ remote_tmp_dir }}/upgrade_c"
+ register: upgrade_c0
+
+- name: Assert collection netbox.netbox was installed
+ assert:
+ that:
+ - upgrade_c0 is changed
+ - '"netbox.netbox" in upgrade_c0.new_collections'
+
+- name: Upgrade collection netbox.netbox
+ community.general.ansible_galaxy_install:
+ state: latest
+ type: collection
+ name: netbox.netbox
+ dest: "{{ remote_tmp_dir }}/upgrade_c"
+ register: upgrade_c1
+
+- name: Upgrade collection netbox.netbox (again)
+ community.general.ansible_galaxy_install:
+ state: latest
+ type: collection
+ name: netbox.netbox
+ dest: "{{ remote_tmp_dir }}/upgrade_c"
+ register: upgrade_c2
+
+- name: Assert collection was not installed
+ assert:
+ that:
+ - upgrade_c1 is changed
+ - upgrade_c2 is not changed
diff --git a/ansible_collections/community/general/tests/integration/targets/cargo/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/cargo/tasks/main.yml
index 29f27c3fd..89f13960a 100644
--- a/ansible_collections/community/general/tests/integration/targets/cargo/tasks/main.yml
+++ b/ansible_collections/community/general/tests/integration/targets/cargo/tasks/main.yml
@@ -16,6 +16,7 @@
- block:
- import_tasks: test_general.yml
- import_tasks: test_version.yml
+ - import_tasks: test_directory.yml
environment: "{{ cargo_environment }}"
when: has_cargo | default(false)
- import_tasks: test_rustup_cargo.yml
diff --git a/ansible_collections/community/general/tests/integration/targets/cargo/tasks/test_directory.yml b/ansible_collections/community/general/tests/integration/targets/cargo/tasks/test_directory.yml
new file mode 100644
index 000000000..f4275ede6
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/cargo/tasks/test_directory.yml
@@ -0,0 +1,122 @@
+---
+# Copyright (c) 2024 Colin Nolan <cn580@alumni.york.ac.uk>
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Create temp directory
+ tempfile:
+ state: directory
+ register: temp_directory
+
+- name: Test block
+ vars:
+ manifest_path: "{{ temp_directory.path }}/Cargo.toml"
+ package_name: hello-world-directory-test
+ block:
+ - name: Initialize package
+ ansible.builtin.command:
+ cmd: "cargo init --name {{ package_name }}"
+ args:
+ chdir: "{{ temp_directory.path }}"
+
+ - name: Set package version (1.0.0)
+ ansible.builtin.lineinfile:
+ path: "{{ manifest_path }}"
+ regexp: '^version = ".*"$'
+ line: 'version = "1.0.0"'
+
+ - name: Ensure package is uninstalled
+ community.general.cargo:
+ name: "{{ package_name }}"
+ state: absent
+ directory: "{{ temp_directory.path }}"
+ register: uninstall_absent
+
+ - name: Install package
+ community.general.cargo:
+ name: "{{ package_name }}"
+ directory: "{{ temp_directory.path }}"
+ register: install_absent
+
+ - name: Change package version (1.0.1)
+ ansible.builtin.lineinfile:
+ path: "{{ manifest_path }}"
+ regexp: '^version = ".*"$'
+ line: 'version = "1.0.1"'
+
+ - name: Install package again (present)
+ community.general.cargo:
+ name: "{{ package_name }}"
+ state: present
+ directory: "{{ temp_directory.path }}"
+ register: install_present_state
+
+ - name: Install package again (latest)
+ community.general.cargo:
+ name: "{{ package_name }}"
+ state: latest
+ directory: "{{ temp_directory.path }}"
+ register: install_latest_state
+
+ - name: Change package version (2.0.0)
+ ansible.builtin.lineinfile:
+ path: "{{ manifest_path }}"
+ regexp: '^version = ".*"$'
+ line: 'version = "2.0.0"'
+
+ - name: Install package with given version (matched)
+ community.general.cargo:
+ name: "{{ package_name }}"
+ version: "2.0.0"
+ directory: "{{ temp_directory.path }}"
+ register: install_given_version_matched
+
+ - name: Install package with given version (unmatched)
+ community.general.cargo:
+ name: "{{ package_name }}"
+ version: "2.0.1"
+ directory: "{{ temp_directory.path }}"
+ register: install_given_version_unmatched
+ ignore_errors: true
+
+ - name: Uninstall package
+ community.general.cargo:
+ name: "{{ package_name }}"
+ state: absent
+ directory: "{{ temp_directory.path }}"
+ register: uninstall_present
+
+ - name: Install non-existant package
+ community.general.cargo:
+ name: "{{ package_name }}-non-existant"
+ state: present
+ directory: "{{ temp_directory.path }}"
+ register: install_non_existant
+ ignore_errors: true
+
+ - name: Install non-existant source directory
+ community.general.cargo:
+ name: "{{ package_name }}"
+ state: present
+ directory: "{{ temp_directory.path }}/non-existant"
+ register: install_non_existant_source
+ ignore_errors: true
+
+ always:
+ - name: Remove temp directory
+ file:
+ path: "{{ temp_directory.path }}"
+ state: absent
+
+- name: Check assertions
+ assert:
+ that:
+ - uninstall_absent is not changed
+ - install_absent is changed
+ - install_present_state is not changed
+ - install_latest_state is changed
+ - install_given_version_matched is changed
+ - install_given_version_unmatched is failed
+ - uninstall_present is changed
+ - install_non_existant is failed
+ - install_non_existant_source is failed
diff --git a/ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_check.yml b/ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_check.yml
new file mode 100644
index 000000000..e1229c794
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_check.yml
@@ -0,0 +1,114 @@
+---
+# Copyright (c) 2024, Michael Ilg (@Ilgmi)
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Create a service
+ community.general.consul_agent_service:
+ name: nginx
+ service_port: 80
+ address: localhost
+ tags:
+ - http
+ meta:
+ nginx_version: 1.25.3
+ register: result
+
+- set_fact:
+ nginx_service: "{{result.service}}"
+
+- assert:
+ that:
+ - result is changed
+ - result.service.ID is defined
+
+- name: Add a check for service
+ community.general.consul_agent_check:
+ name: nginx_check
+ id: nginx_check
+ interval: 30s
+ http: http://localhost:80/morestatus
+ notes: "Nginx Check"
+ service_id: "{{ nginx_service.ID }}"
+ register: result
+
+- assert:
+ that:
+ - result is changed
+ - result.check is defined
+ - result.check.CheckID == 'nginx_check'
+ - result.check.ServiceID == 'nginx'
+ - result.check.Interval == '30s'
+ - result.check.Type == 'http'
+ - result.check.Notes == 'Nginx Check'
+
+- set_fact:
+ nginx_service_check: "{{ result.check }}"
+
+- name: Update check for service
+ community.general.consul_agent_check:
+ name: "{{ nginx_service_check.Name }}"
+ id: "{{ nginx_service_check.CheckID }}"
+ interval: 60s
+ http: http://localhost:80/morestatus
+ notes: "New Nginx Check"
+ service_id: "{{ nginx_service.ID }}"
+ register: result
+
+- assert:
+ that:
+ - result is changed
+ - result.check is defined
+ - result.check.CheckID == 'nginx_check'
+ - result.check.ServiceID == 'nginx'
+ - result.check.Interval == '1m0s'
+ - result.check.Type == 'http'
+ - result.check.Notes == 'New Nginx Check'
+
+- name: Remove check
+ community.general.consul_agent_check:
+ id: "{{ nginx_service_check.Name }}"
+ state: absent
+ service_id: "{{ nginx_service.ID }}"
+ register: result
+
+- assert:
+ that:
+ - result is changed
+ - result is not failed
+ - result.operation == 'remove'
+
+- name: Add a check
+ community.general.consul_agent_check:
+ name: check
+ id: check
+ interval: 30s
+ tcp: localhost:80
+ notes: "check"
+ register: result
+
+- assert:
+ that:
+ - result is changed
+ - result.check is defined
+
+- name: Update a check
+ community.general.consul_agent_check:
+ name: check
+ id: check
+ interval: 60s
+ tcp: localhost:80
+ notes: "check"
+ register: result
+
+- assert:
+ that:
+ - result is changed
+ - result.check is defined
+ - result.check.Interval == '1m0s'
+
+- name: Remove check
+ community.general.consul_agent_check:
+ id: check
+ state: absent
+ register: result \ No newline at end of file
diff --git a/ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_service.yml b/ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_service.yml
new file mode 100644
index 000000000..95270f74b
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_agent_service.yml
@@ -0,0 +1,89 @@
+---
+# Copyright (c) 2024, Michael Ilg (@Ilgmi)
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Create a service
+ community.general.consul_agent_service:
+ name: nginx
+ service_port: 80
+ address: localhost
+ tags:
+ - http
+ meta:
+ nginx_version: 1.25.3
+ register: result
+
+- set_fact:
+ nginx_service: "{{result.service}}"
+
+- assert:
+ that:
+ - result is changed
+ - result.service.ID is defined
+ - result.service.Service == 'nginx'
+ - result.service.Address == 'localhost'
+ - result.service.Port == 80
+ - result.service.Tags[0] == 'http'
+ - result.service.Meta.nginx_version is defined
+ - result.service.Meta.nginx_version == '1.25.3'
+ - result.service.ContentHash is defined
+
+- name: Update service
+ community.general.consul_agent_service:
+ id: "{{ nginx_service.ID }}"
+ name: "{{ nginx_service.Service }}"
+ service_port: 8080
+ address: 127.0.0.1
+ tags:
+ - http
+ - new_tag
+ meta:
+ nginx_version: 1.0.0
+ nginx: 1.25.3
+ register: result
+- assert:
+ that:
+ - result is changed
+ - result.service.ID is defined
+ - result.service.Service == 'nginx'
+ - result.service.Address == '127.0.0.1'
+ - result.service.Port == 8080
+ - result.service.Tags[0] == 'http'
+ - result.service.Tags[1] == 'new_tag'
+ - result.service.Meta.nginx_version is defined
+ - result.service.Meta.nginx_version == '1.0.0'
+ - result.service.Meta.nginx is defined
+ - result.service.Meta.nginx == '1.25.3'
+ - result.service.ContentHash is defined
+
+- name: Update service not changed when updating again without changes
+ community.general.consul_agent_service:
+ id: "{{ nginx_service.ID }}"
+ name: "{{ nginx_service.Service }}"
+ service_port: 8080
+ address: 127.0.0.1
+ tags:
+ - http
+ - new_tag
+ meta:
+ nginx_version: 1.0.0
+ nginx: 1.25.3
+ register: result
+
+- assert:
+ that:
+ - result is not changed
+ - result.operation is not defined
+
+- name: Remove service
+ community.general.consul_agent_service:
+ id: "{{ nginx_service.ID }}"
+ state: absent
+ register: result
+
+- assert:
+ that:
+ - result is changed
+ - result is not failed
+ - result.operation == 'remove' \ No newline at end of file
diff --git a/ansible_collections/community/general/tests/integration/targets/consul/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/consul/tasks/main.yml
index 6fef2b998..0ac58fc40 100644
--- a/ansible_collections/community/general/tests/integration/targets/consul/tasks/main.yml
+++ b/ansible_collections/community/general/tests/integration/targets/consul/tasks/main.yml
@@ -97,6 +97,8 @@
- import_tasks: consul_token.yml
- import_tasks: consul_auth_method.yml
- import_tasks: consul_binding_rule.yml
+ - import_tasks: consul_agent_service.yml
+ - import_tasks: consul_agent_check.yml
module_defaults:
group/community.general.consul:
token: "{{ consul_management_token }}"
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/aliases b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/aliases
new file mode 100644
index 000000000..12d1d6617
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/aliases
@@ -0,0 +1,5 @@
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+azp/posix/2
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/keep_keys.yml b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/keep_keys.yml
new file mode 100644
index 000000000..94825c9d6
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/keep_keys.yml
@@ -0,0 +1,79 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Debug ansible_version
+ ansible.builtin.debug:
+ var: ansible_version
+ when: not quite_test | d(true) | bool
+ tags: ansible_version
+
+- name: Test keep keys equal (default)
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ vars:
+ rr: "{{ list1 | community.general.keep_keys(target=tt) }}"
+ tt: [k0_x0, k1_x1]
+ tags: equal_default
+
+- name: Test keep keys regex string
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ vars:
+ rr: "{{ list1 | community.general.keep_keys(target=tt, matching_parameter=mp) }}"
+ mp: regex
+ tt: '^.*[01]_x.*$'
+ tags: regex_string
+
+- name: Test keep keys targets1
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ loop: "{{ targets1 }}"
+ loop_control:
+ label: "{{ item.mp }}: {{ item.tt }}"
+ vars:
+ rr: "{{ list1 | community.general.keep_keys(target=item.tt, matching_parameter=item.mp) }}"
+ tags: targets1
+
+- name: Test keep keys targets2
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result2) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ loop: "{{ targets2 }}"
+ loop_control:
+ label: "{{ item.mp }}: {{ item.tt }}"
+ vars:
+ rr: "{{ list2 | community.general.keep_keys(target=item.tt, matching_parameter=item.mp) }}"
+ tags: targets2
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/main.yml
new file mode 100644
index 000000000..23457d1e1
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Test keep_keys
+ import_tasks: keep_keys.yml
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/vars/main.yml b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/vars/main.yml
new file mode 100644
index 000000000..b25325253
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_keep_keys/vars/main.yml
@@ -0,0 +1,33 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+targets1:
+ - {mp: equal, tt: [k0_x0, k1_x1]}
+ - {mp: starts_with, tt: [k0, k1]}
+ - {mp: ends_with, tt: [x0, x1]}
+ - {mp: regex, tt: ['^.*[01]_x.*$']}
+ - {mp: regex, tt: '^.*[01]_x.*$'}
+
+list1:
+ - {k0_x0: A0, k1_x1: B0, k2_x2: [C0], k3_x3: foo}
+ - {k0_x0: A1, k1_x1: B1, k2_x2: [C1], k3_x3: bar}
+
+result1:
+ - {k0_x0: A0, k1_x1: B0}
+ - {k0_x0: A1, k1_x1: B1}
+
+targets2:
+ - {mp: equal, tt: k0_x0}
+ - {mp: starts_with, tt: k0}
+ - {mp: ends_with, tt: x0}
+ - {mp: regex, tt: '^.*0_x.*$'}
+
+list2:
+ - {k0_x0: A0, k1_x1: B0, k2_x2: [C0], k3_x3: foo}
+ - {k0_x0: A1, k1_x1: B1, k2_x2: [C1], k3_x3: bar}
+
+result2:
+ - {k0_x0: A0}
+ - {k0_x0: A1}
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/aliases b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/aliases
new file mode 100644
index 000000000..12d1d6617
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/aliases
@@ -0,0 +1,5 @@
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+azp/posix/2
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/main.yml
new file mode 100644
index 000000000..d4215d8c5
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Test remove_keys
+ import_tasks: remove_keys.yml
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/remove_keys.yml b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/remove_keys.yml
new file mode 100644
index 000000000..121cd88cf
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/tasks/remove_keys.yml
@@ -0,0 +1,79 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Debug ansible_version
+ ansible.builtin.debug:
+ var: ansible_version
+ when: not quite_test | d(true) | bool
+ tags: ansible_version
+
+- name: Test remove keys equal (default)
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ vars:
+ rr: "{{ list1 | community.general.remove_keys(target=tt) }}"
+ tt: [k0_x0, k1_x1]
+ tags: equal_default
+
+- name: Test remove keys regex string
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ vars:
+ rr: "{{ list1 | community.general.remove_keys(target=tt, matching_parameter=mp) }}"
+ mp: regex
+ tt: '^.*[01]_x.*$'
+ tags: regex_string
+
+- name: Test remove keys targets1
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ loop: "{{ targets1 }}"
+ loop_control:
+ label: "{{ item.mp }}: {{ item.tt }}"
+ vars:
+ rr: "{{ list1 | community.general.remove_keys(target=item.tt, matching_parameter=item.mp) }}"
+ tags: targets1
+
+- name: Test remove keys targets2
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result2) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ loop: "{{ targets2 }}"
+ loop_control:
+ label: "{{ item.mp }}: {{ item.tt }}"
+ vars:
+ rr: "{{ list2 | community.general.remove_keys(target=item.tt, matching_parameter=item.mp) }}"
+ tags: targets1
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/vars/main.yml b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/vars/main.yml
new file mode 100644
index 000000000..a52d09a34
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_remove_keys/vars/main.yml
@@ -0,0 +1,33 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+targets1:
+ - {mp: equal, tt: [k0_x0, k1_x1]}
+ - {mp: starts_with, tt: [k0, k1]}
+ - {mp: ends_with, tt: [x0, x1]}
+ - {mp: regex, tt: ['^.*[01]_x.*$']}
+ - {mp: regex, tt: '^.*[01]_x.*$'}
+
+list1:
+ - {k0_x0: A0, k1_x1: B0, k2_x2: [C0], k3_x3: foo}
+ - {k0_x0: A1, k1_x1: B1, k2_x2: [C1], k3_x3: bar}
+
+result1:
+ - {k2_x2: [C0], k3_x3: foo}
+ - {k2_x2: [C1], k3_x3: bar}
+
+targets2:
+ - {mp: equal, tt: k0_x0}
+ - {mp: starts_with, tt: k0}
+ - {mp: ends_with, tt: x0}
+ - {mp: regex, tt: '^.*0_x.*$'}
+
+list2:
+ - {k0_x0: A0, k1_x1: B0, k2_x2: [C0], k3_x3: foo}
+ - {k0_x0: A1, k1_x1: B1, k2_x2: [C1], k3_x3: bar}
+
+result2:
+ - {k1_x1: B0, k2_x2: [C0], k3_x3: foo}
+ - {k1_x1: B1, k2_x2: [C1], k3_x3: bar}
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/aliases b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/aliases
new file mode 100644
index 000000000..12d1d6617
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/aliases
@@ -0,0 +1,5 @@
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+azp/posix/2
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/fn-test-replace_keys.yml b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/fn-test-replace_keys.yml
new file mode 100644
index 000000000..e324376a5
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/fn-test-replace_keys.yml
@@ -0,0 +1,21 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Test replace keys
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(item.result) | length) == 0
+ success_msg: |
+ [OK] {{ item.label }}
+ result:
+ {{ rr | to_nice_yaml(indent=2) | indent(2) }}
+ fail_msg: |
+ [ERR] {{ item.label }}
+ result:
+ {{ rr | to_nice_yaml(indent=2) | indent(2) }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ vars:
+ rr: "{{ item.data |
+ community.general.replace_keys(target=item.target, matching_parameter=item.match) }}"
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/main.yml
new file mode 100644
index 000000000..35addaf94
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Test replace_keys
+ import_tasks: replace_keys.yml
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/replace_keys.yml b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/replace_keys.yml
new file mode 100644
index 000000000..a57921b81
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/tasks/replace_keys.yml
@@ -0,0 +1,56 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+- name: Debug ansible_version
+ ansible.builtin.debug:
+ var: ansible_version
+ when: not quiet_test | d(true) | bool
+ tags: ansible_version
+
+- name: Test replace keys equal (default)
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ vars:
+ rr: "{{ list1 | community.general.replace_keys(target=tt) }}"
+ tt:
+ - {before: k0_x0, after: a0}
+ - {before: k1_x1, after: a1}
+ tags: equal_default
+
+- name: Test replace keys targets1
+ ansible.builtin.assert:
+ that:
+ - (rr | difference(result1) | length) == 0
+ success_msg: |
+ [OK] result:
+ {{ rr | to_yaml }}
+ fail_msg: |
+ [ERR] result:
+ {{ rr | to_yaml }}
+ quiet: "{{ quiet_test | d(true) | bool }}"
+ loop: "{{ targets1 | dict2items }}"
+ loop_control:
+ label: "{{ item.key }}"
+ vars:
+ rr: "{{ list1 | community.general.replace_keys(target=item.value, matching_parameter=item.key) }}"
+ tags: targets1
+
+- name: Test replace keys targets2
+ include_tasks:
+ file: fn-test-replace_keys.yml
+ apply:
+ tags: targets2
+ loop: "{{ targets2 }}"
+ loop_control:
+ label: "{{ item.label }}"
+ tags: targets2
diff --git a/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/vars/main.yml b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/vars/main.yml
new file mode 100644
index 000000000..167e08396
--- /dev/null
+++ b/ansible_collections/community/general/tests/integration/targets/filter_replace_keys/vars/main.yml
@@ -0,0 +1,58 @@
+---
+# Copyright (c) Ansible Project
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+list1:
+ - {k0_x0: A0, k1_x1: B0, k2_x2: [C0], k3_x3: foo}
+ - {k0_x0: A1, k1_x1: B1, k2_x2: [C1], k3_x3: bar}
+
+result1:
+ - {a0: A0, a1: B0, k2_x2: [C0], k3_x3: foo}
+ - {a0: A1, a1: B1, k2_x2: [C1], k3_x3: bar}
+
+targets1:
+ equal:
+ - {before: k0_x0, after: a0}
+ - {before: k1_x1, after: a1}
+ starts_with:
+ - {before: k0, after: a0}
+ - {before: k1, after: a1}
+ ends_with:
+ - {before: x0, after: a0}
+ - {before: x1, after: a1}
+ regex:
+ - {before: "^.*0_x.*$", after: a0}
+ - {before: "^.*1_x.*$", after: a1}
+
+list2:
+ - {aaa1: A, bbb1: B, ccc1: C}
+ - {aaa2: D, bbb2: E, ccc2: F}
+
+targets2:
+ - label: If more keys match the same attribute before the last one will be used.
+ match: regex
+ target:
+ - {before: "^.*_x.*$", after: X}
+ data: "{{ list1 }}"
+ result:
+ - X: foo
+ - X: bar
+ - label: If there are items with equal attribute before the first one will be used.
+ match: regex
+ target:
+ - {before: "^.*_x.*$", after: X}
+ - {before: "^.*_x.*$", after: Y}
+ data: "{{ list1 }}"
+ result:
+ - X: foo
+ - X: bar
+ - label: If there are more matches for a key the first one will be used.
+ match: starts_with
+ target:
+ - {before: a, after: X}
+ - {before: aa, after: Y}
+ data: "{{ list2 }}"
+ result:
+ - {X: A, bbb1: B, ccc1: C}
+ - {X: D, bbb2: E, ccc2: F}
diff --git a/ansible_collections/community/general/tests/integration/targets/git_config/tasks/unset_value.yml b/ansible_collections/community/general/tests/integration/targets/git_config/tasks/unset_value.yml
index dfa535a2d..5f8c52c96 100644
--- a/ansible_collections/community/general/tests/integration/targets/git_config/tasks/unset_value.yml
+++ b/ansible_collections/community/general/tests/integration/targets/git_config/tasks/unset_value.yml
@@ -25,4 +25,28 @@
- unset_result.diff.before == option_value + "\n"
- unset_result.diff.after == "\n"
- get_result.config_value == ''
+
+- import_tasks: setup_value.yml
+
+- name: unsetting value with value specified
+ git_config:
+ name: "{{ option_name }}"
+ scope: "{{ option_scope }}"
+ value: "{{ option_value }}"
+ state: absent
+ register: unset_result
+
+- name: getting value
+ git_config:
+ name: "{{ option_name }}"
+ scope: "{{ option_scope }}"
+ register: get_result
+
+- name: assert unset changed and deleted value
+ assert:
+ that:
+ - unset_result is changed
+ - unset_result.diff.before == option_value + "\n"
+ - unset_result.diff.after == "\n"
+ - get_result.config_value == ''
...
diff --git a/ansible_collections/community/general/tests/integration/targets/keycloak_client/tasks/main.yml b/ansible_collections/community/general/tests/integration/targets/keycloak_client/tasks/main.yml
index 5e7c7fae3..e1a7d2ebf 100644
--- a/ansible_collections/community/general/tests/integration/targets/keycloak_client/tasks/main.yml
+++ b/ansible_collections/community/general/tests/integration/targets/keycloak_client/tasks/main.yml
@@ -103,3 +103,131 @@
assert:
that:
- check_client_when_present_and_changed is changed
+
+- name: Desire client with flow binding overrides
+ community.general.keycloak_client:
+ auth_keycloak_url: "{{ url }}"
+ auth_realm: "{{ admin_realm }}"
+ auth_username: "{{ admin_user }}"
+ auth_password: "{{ admin_password }}"
+ realm: "{{ realm }}"
+ client_id: "{{ client_id }}"
+ state: present
+ redirect_uris: '{{redirect_uris1}}'
+ attributes: '{{client_attributes1}}'
+ protocol_mappers: '{{protocol_mappers1}}'
+ authentication_flow_binding_overrides:
+ browser_name: browser
+ direct_grant_name: direct grant
+ register: desire_client_with_flow_binding_overrides
+
+- name: Assert flows are set
+ assert:
+ that:
+ - desire_client_with_flow_binding_overrides is changed
+ - "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
+ - desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser | length > 0
+ - desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant | length > 0
+
+- name: Backup flow UUIDs
+ set_fact:
+ flow_browser_uuid: "{{ desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser }}"
+ flow_direct_grant_uuid: "{{ desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant }}"
+
+- name: Desire client with flow binding overrides remove direct_grant_name
+ community.general.keycloak_client:
+ auth_keycloak_url: "{{ url }}"
+ auth_realm: "{{ admin_realm }}"
+ auth_username: "{{ admin_user }}"
+ auth_password: "{{ admin_password }}"
+ realm: "{{ realm }}"
+ client_id: "{{ client_id }}"
+ state: present
+ redirect_uris: '{{redirect_uris1}}'
+ attributes: '{{client_attributes1}}'
+ protocol_mappers: '{{protocol_mappers1}}'
+ authentication_flow_binding_overrides:
+ browser_name: browser
+ register: desire_client_with_flow_binding_overrides
+
+- name: Assert flows are updated
+ assert:
+ that:
+ - desire_client_with_flow_binding_overrides is changed
+ - "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
+ - desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser | length > 0
+ - "'direct_grant' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
+
+- name: Desire client with flow binding overrides remove browser add direct_grant
+ community.general.keycloak_client:
+ auth_keycloak_url: "{{ url }}"
+ auth_realm: "{{ admin_realm }}"
+ auth_username: "{{ admin_user }}"
+ auth_password: "{{ admin_password }}"
+ realm: "{{ realm }}"
+ client_id: "{{ client_id }}"
+ state: present
+ redirect_uris: '{{redirect_uris1}}'
+ attributes: '{{client_attributes1}}'
+ protocol_mappers: '{{protocol_mappers1}}'
+ authentication_flow_binding_overrides:
+ direct_grant_name: direct grant
+ register: desire_client_with_flow_binding_overrides
+
+- name: Assert flows are updated
+ assert:
+ that:
+ - desire_client_with_flow_binding_overrides is changed
+ - "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
+ - "'browser' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
+ - desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant | length > 0
+
+- name: Desire client with flow binding overrides with UUIDs
+ community.general.keycloak_client:
+ auth_keycloak_url: "{{ url }}"
+ auth_realm: "{{ admin_realm }}"
+ auth_username: "{{ admin_user }}"
+ auth_password: "{{ admin_password }}"
+ realm: "{{ realm }}"
+ client_id: "{{ client_id }}"
+ state: present
+ redirect_uris: '{{redirect_uris1}}'
+ attributes: '{{client_attributes1}}'
+ protocol_mappers: '{{protocol_mappers1}}'
+ authentication_flow_binding_overrides:
+ browser: "{{ flow_browser_uuid }}"
+ direct_grant: "{{ flow_direct_grant_uuid }}"
+ register: desire_client_with_flow_binding_overrides
+
+- name: Assert flows are updated
+ assert:
+ that:
+ - desire_client_with_flow_binding_overrides is changed
+ - "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
+ - desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.browser == flow_browser_uuid
+ - desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides.direct_grant == flow_direct_grant_uuid
+
+- name: Unset flow binding overrides
+ community.general.keycloak_client:
+ auth_keycloak_url: "{{ url }}"
+ auth_realm: "{{ admin_realm }}"
+ auth_username: "{{ admin_user }}"
+ auth_password: "{{ admin_password }}"
+ realm: "{{ realm }}"
+ client_id: "{{ client_id }}"
+ state: present
+ redirect_uris: '{{redirect_uris1}}'
+ attributes: '{{client_attributes1}}'
+ protocol_mappers: '{{protocol_mappers1}}'
+ authentication_flow_binding_overrides:
+ browser: "{{ None }}"
+ direct_grant: null
+ register: desire_client_with_flow_binding_overrides
+
+- name: Assert flows are removed
+ assert:
+ that:
+ - desire_client_with_flow_binding_overrides is changed
+ - "'authenticationFlowBindingOverrides' in desire_client_with_flow_binding_overrides.end_state"
+ - "'browser' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides"
+ - "'direct_grant' not in desire_client_with_flow_binding_overrides.end_state.authenticationFlowBindingOverrides" \ No newline at end of file