Repository: ansible-collections/community.general

Issue:
Keycloak authentication - validate_certs value is ignored
### Summary

community.general.keycloak_authentication module ignore value `False` and I can't disable TLS validation for self signed instance without adding certificate into trust store. I think this should works by default as this is useful for development instances with self signed cert. 

### Issue Type

Bug Report

### Component Name

keycloak_authentication

### Ansible Version

```console (paste below)
$ ansible --version
ansible 2.9.27
  config file = /home/myuser/.ansible.cfg
  configured module search path = ['/home/myuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.2 (main, Jan 17 2022, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)]
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```

### OS / Environment

Fedora release 35 (Thirty Five)

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: Modify authentication flow for browser
  community.general.keycloak_authentication:
    auth_keycloak_url: "{{ keycloak_configuration_auth_url }}"
    auth_realm: "{{ keycloak_configuration_auth_realm }}"
    auth_username: "{{ keycloak_configuration_auth_username }}"
    auth_password: "{{ keycloak_configuration_auth_password }}"
    validate_certs: False
    realm: "{{ auth.realm }}"
    alias: "{{ auth.alias }}"
    copyFrom: "{{ auth.copyFrom }}"
    description: "{{ auth.description | default(omit) }}"
    authenticationExecutions:
      "{{ auth.authenticationExecutions | default(omit) }}"
    force: "{{ auth.force | default(omit) }}"
    providerId: "{{ auth.providerId | default(omit) }}"
    state: present
  register: auth_results
  delegate_to: localhost
  loop: "{{ keycloak_configuration_authentication }}"
  loop_control:
    loop_var: auth
```


### Expected Results

Task play should use `False` value and ignore not trusted certificate.

### Actual Results

```console (paste below)
` <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for`
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/identity/keycloak/keycloak_authentication.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/identity/keycloak/keycloak_authentication.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Gaetan2907 @eikef @elfelip @ndclt
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
This is (very likely) fixed by #4382.

Resolving patch:
diff --git a/plugins/module_utils/identity/keycloak/keycloak.py b/plugins/module_utils/identity/keycloak/keycloak.py
--- a/plugins/module_utils/identity/keycloak/keycloak.py
+++ b/plugins/module_utils/identity/keycloak/keycloak.py
@@ -1237,7 +1237,7 @@ def get_authentication_flow_by_alias(self, alias, realm='master'):
             authentication_flow = {}
             # Check if the authentication flow exists on the Keycloak serveraders
             authentications = json.load(open_url(URL_AUTHENTICATION_FLOWS.format(url=self.baseurl, realm=realm), method='GET',
-                                                 headers=self.restheaders, timeout=self.connection_timeout))
+                                                 headers=self.restheaders, timeout=self.connection_timeout, validate_certs=self.validate_certs))
             for authentication in authentications:
                 if authentication["alias"] == alias:
                     authentication_flow = authentication
@@ -1281,14 +1281,16 @@ def copy_auth_flow(self, config, realm='master'):
                 method='POST',
                 headers=self.restheaders,
                 data=json.dumps(new_name),
-                timeout=self.connection_timeout)
+                timeout=self.connection_timeout,
+                validate_certs=self.validate_certs)
             flow_list = json.load(
                 open_url(
                     URL_AUTHENTICATION_FLOWS.format(url=self.baseurl,
                                                     realm=realm),
                     method='GET',
                     headers=self.restheaders,
-                    timeout=self.connection_timeout))
+                    timeout=self.connection_timeout,
+                    validate_certs=self.validate_certs))
             for flow in flow_list:
                 if flow["alias"] == config["alias"]:
                     return flow
@@ -1318,7 +1320,8 @@ def create_empty_auth_flow(self, config, realm='master'):
                 method='POST',
                 headers=self.restheaders,
                 data=json.dumps(new_flow),
-                timeout=self.connection_timeout)
+                timeout=self.connection_timeout,
+                validate_certs=self.validate_certs)
             flow_list = json.load(
                 open_url(
                     URL_AUTHENTICATION_FLOWS.format(
@@ -1326,7 +1329,8 @@ def create_empty_auth_flow(self, config, realm='master'):
                         realm=realm),
                     method='GET',
                     headers=self.restheaders,
-                    timeout=self.connection_timeout))
+                    timeout=self.connection_timeout,
+                    validate_certs=self.validate_certs))
             for flow in flow_list:
                 if flow["alias"] == config["alias"]:
                     return flow
@@ -1351,7 +1355,8 @@ def update_authentication_executions(self, flowAlias, updatedExec, realm='master
                 method='PUT',
                 headers=self.restheaders,
                 data=json.dumps(updatedExec),
-                timeout=self.connection_timeout)
+                timeout=self.connection_timeout,
+                validate_certs=self.validate_certs)
         except Exception as e:
             self.module.fail_json(msg="Unable to update executions %s: %s" % (updatedExec, str(e)))
 
@@ -1371,7 +1376,8 @@ def add_authenticationConfig_to_execution(self, executionId, authenticationConfi
                 method='POST',
                 headers=self.restheaders,
                 data=json.dumps(authenticationConfig),
-                timeout=self.connection_timeout)
+                timeout=self.connection_timeout,
+                validate_certs=self.validate_certs)
         except Exception as e:
             self.module.fail_json(msg="Unable to add authenticationConfig %s: %s" % (executionId, str(e)))
 
@@ -1395,7 +1401,8 @@ def create_subflow(self, subflowName, flowAlias, realm='master'):
                 method='POST',
                 headers=self.restheaders,
                 data=json.dumps(newSubFlow),
-                timeout=self.connection_timeout)
+                timeout=self.connection_timeout,
+                validate_certs=self.validate_certs)
         except Exception as e:
             self.module.fail_json(msg="Unable to create new subflow %s: %s" % (subflowName, str(e)))
 
@@ -1418,7 +1425,8 @@ def create_execution(self, execution, flowAlias, realm='master'):
                 method='POST',
                 headers=self.restheaders,
                 data=json.dumps(newExec),
-                timeout=self.connection_timeout)
+                timeout=self.connection_timeout,
+                validate_certs=self.validate_certs)
         except Exception as e:
             self.module.fail_json(msg="Unable to create new execution %s: %s" % (execution["provider"], str(e)))
 
@@ -1440,7 +1448,8 @@ def change_execution_priority(self, executionId, diff, realm='master'):
                             id=executionId),
                         method='POST',
                         headers=self.restheaders,
-                        timeout=self.connection_timeout)
+                        timeout=self.connection_timeout,
+                        validate_certs=self.validate_certs)
             elif diff < 0:
                 for i in range(-diff):
                     open_url(
@@ -1450,7 +1459,8 @@ def change_execution_priority(self, executionId, diff, realm='master'):
                             id=executionId),
                         method='POST',
                         headers=self.restheaders,
-                        timeout=self.connection_timeout)
+                        timeout=self.connection_timeout,
+                        validate_certs=self.validate_certs)
         except Exception as e:
             self.module.fail_json(msg="Unable to change execution priority %s: %s" % (executionId, str(e)))
 
@@ -1471,7 +1481,8 @@ def get_executions_representation(self, config, realm='master'):
                         flowalias=quote(config["alias"])),
                     method='GET',
                     headers=self.restheaders,
-                    timeout=self.connection_timeout))
+                    timeout=self.connection_timeout,
+                    validate_certs=self.validate_certs))
             for execution in executions:
                 if "authenticationConfig" in execution:
                     execConfigId = execution["authenticationConfig"]
@@ -1483,7 +1494,8 @@ def get_executions_representation(self, config, realm='master'):
                                 id=execConfigId),
                             method='GET',
                             headers=self.restheaders,
-                            timeout=self.connection_timeout))
+                            timeout=self.connection_timeout,
+                            validate_certs=self.validate_certs))
                     execution["authenticationConfig"] = execConfig
             return executions
         except Exception as e:


Test patch: