ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
810 stars 1.49k forks source link

Keycloak 19.0.1 Quarkus: cannot create realm #5127

Open agr-schleupen opened 2 years ago

agr-schleupen commented 2 years ago

Summary

I'm trying to create a realm with the module community.general.keycloak_realm and receive a Keycloak error:

"msg": "Could not create realm testrealm: HTTP Error 500: Internal Server Error"

This is the playbook straight from the documentation:

This is the keycloak error:

ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-87) Uncaught server error: java.lang.NullPointerException: Cannot invoke "String.toLowerCase()" because the return value of "org.keycloak.representations.idm.RealmRepresentation.getRealm()" is null```

### Issue Type

Bug Report

### Component Name

community.general.keycloak_realm

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.13.2]
  config file = /home/artur.grzella/.ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/xxx/ansible6/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/xxx/ansible6/bin/ansible
  python version = 3.8.11 (default, Sep  1 2021, 12:33:46) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
  jinja version = 3.1.2
  libyaml = True

Community.general Version

# /home/xxx/ansible6/lib64/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.4.0

# /home/xxx/ansible6/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.4.0

Configuration

$ ansible-config dump --only-changed
COLOR_VERBOSE(/home/xxx/.ansible.cfg) = bright blue
DEFAULT_ASK_PASS(/home/xxx/.ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/home/xxx/.ansible.cfg) = True
DEFAULT_FORKS(/home/xxx/.ansible.cfg) = 25
HOST_KEY_CHECKING(/home/xxx/.ansible.cfg) = False

OS / Environment

CentOS 7

Steps to Reproduce

- name: create realm
  hosts: id
  gather_facts: false
  tasks:
  - name: create an test realm
    community.general.keycloak_realm:
      auth_client_id: admin-cli
      auth_keycloak_url: http://localhost:8080/auth
      auth_realm: master
      auth_username: "{{ user }}"
      auth_password: "{{ pw }}"
      id: testrealm
      state: present
      validate_certs: false
    when: "ansible_version.full is version_compare('2.13.2', '>=')"
  - tags: create_realm

Expected Results

I expect the realm to get created

Actual Results

ansible-playbook [core 2.13.2]
  config file = /home/xxx/.ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/xxx/ansible6/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/xxx/ansible6/bin/ansible-playbook
  python version = 3.8.11 (default, Sep  1 2021, 12:33:46) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
  jinja version = 3.1.2
  libyaml = True
Using /home/xxx/.ansible.cfg as config file
SSH password:
BECOME password[defaults to SSH password]:
setting up inventory plugins
host_list declined parsing /home/xxx/ansible/ansible-inventory/local_inventory as it did not pass its verify_file() method
script declined parsing /home/xxx/ansible/ansible-inventory/local_inventory as it did not pass its verify_file() method
auto declined parsing /home/xxx/ansible/ansible-inventory/local_inventory as it did not pass its verify_file() method
Parsed /home/xxx/ansible/ansible-inventory/local_inventory inventory source with ini plugin
Loading collection community.general from /home/xxx/ansible6/lib64/python3.8/site-packages/ansible_collections/community/general
redirecting (type: modules) community.general.keycloak_realm to community.general.identity.keycloak.keycloak_realm
Loading callback plugin default of type stdout, v2.0 from /home/xxx/ansible6/lib64/python3.8/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: config.yml ***************************************************************************************************
Positional arguments: config.yml
verbosity: 4
connection: smart
timeout: 10
ask_pass: True
become_method: sudo
become_ask_pass: True
tags: ('all',)
inventory: ('/home/xxx/ansible/ansible-inventory/local_inventory',)
extra_vars: ('pw=!qweR7350!',)
forks: 25
1 plays in config.yml

PLAY [First test configuring Keycloak with Ansible] ********************************************************************
META: ran handlers

TASK [create an test realm] ********************************************************************************************
task path: /home/xxx/ansible/smgw/keycloak/config.yml:5
redirecting (type: modules) community.general.keycloak_realm to community.general.identity.keycloak.keycloak_realm
redirecting (type: modules) community.general.keycloak_realm to community.general.identity.keycloak.keycloak_realm
<keycloak> Attempting python interpreter discovery
<keycloak.localdomain.localsite> ESTABLISH SSH CONNECTION FOR USER: None
<keycloak.localdomain.localsite> SSH: EXEC sshpass -d10 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=1800s -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o 'ControlPath="/home/xxx/.ansible/cp/91dde67379"' keycloak.localdomain.localsite '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.5'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<keycloak.localdomain.localsite> (0, b'PLATFORM\nLinux\nFOUND\n/usr/bin/python3.6\n/usr/bin/python3\n/usr/libexec/platform-python\n/usr/bin/python2.7\n/usr/bin/python\n/usr/bin/python\nENDFOUND\n', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /home/xxx/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 65143\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<keycloak.localdomain.localsite> ESTABLISH SSH CONNECTION FOR USER: None
<keycloak.localdomain.localsite> SSH: EXEC sshpass -d10 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=1800s -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o 'ControlPath="/home/xxx/.ansible/cp/91dde67379"' keycloak.localdomain.localsite '/bin/sh -c '"'"'/usr/bin/python3.6 && sleep 0'"'"''
<keycloak.localdomain.localsite> (0, b'{"platform_dist_result": ["centos", "7.9.2009", "Core"], "osrelease_content": "NAME=\\"CentOS Linux\\"\\nVERSION=\\"7 (Core)\\"\\nID=\\"centos\\"\\nID_LIKE=\\"rhel fedora\\"\\nVERSION_ID=\\"7\\"\\nPRETTY_NAME=\\"CentOS Linux 7 (Core)\\"\\nANSI_COLOR=\\"0;31\\"\\nCPE_NAME=\\"cpe:/o:centos:centos:7\\"\\nHOME_URL=\\"https://www.centos.org/\\"\\nBUG_REPORT_URL=\\"https://bugs.centos.org/\\"\\n\\nCENTOS_MANTISBT_PROJECT=\\"CentOS-7\\"\\nCENTOS_MANTISBT_PROJECT_VERSION=\\"7\\"\\nREDHAT_SUPPORT_PRODUCT=\\"centos\\"\\nREDHAT_SUPPORT_PRODUCT_VERSION=\\"7\\"\\n\\n"}\n', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /home/xxx/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 65143\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
Using module file /home/xxx/ansible6/lib64/python3.8/site-packages/ansible_collections/community/general/plugins/modules/identity/keycloak/keycloak_realm.py
Pipelining is enabled.
<keycloak.localdomain.localsite> ESTABLISH SSH CONNECTION FOR USER: None
<keycloak.localdomain.localsite> SSH: EXEC sshpass -d10 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=1800s -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o 'ControlPath="/home/xxx/.ansible/cp/91dde67379"' keycloak.localdomain.localsite '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=uhdzdubzdybbexlzwjwoypjwenemqiyl] password:" -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-uhdzdubzdybbexlzwjwoypjwenemqiyl ; /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<keycloak.localdomain.localsite> (1, b'\n{"msg": "Could not create realm testrealm: HTTP Error 500: Internal Server Error", "failed": true, "exception": "Traceback (most recent call last):\\n  File \\"/tmp/ansible_community.general.keycloak_realm_payload_N2t5Xu/ansible_community.general.keycloak_realm_payload.zip/ansible_collections/community/general/plugins/module_utils/identity/keycloak/keycloak.py\\", line 315, in create_realm\\n    data=json.dumps(realmrep), validate_certs=self.validate_certs)\\n  File \\"/tmp/ansible_community.general.keycloak_realm_payload_N2t5Xu/ansible_community.general.keycloak_realm_payload.zip/ansible/module_utils/urls.py\\", line 1581, in open_url\\n    unredirected_headers=unredirected_headers)\\n  File \\"/tmp/ansible_community.general.keycloak_realm_payload_N2t5Xu/ansible_community.general.keycloak_realm_payload.zip/ansible/module_utils/urls.py\\", line 1486, in open\\n    return urllib_request.urlopen(request, None, timeout)\\n  File \\"/usr/lib64/python2.7/urllib2.py\\", line 154, in urlopen\\n    return opener.open(url, data, timeout)\\n  File \\"/usr/lib64/python2.7/urllib2.py\\", line 437, in open\\n    response = meth(req, response)\\n  File \\"/usr/lib64/python2.7/urllib2.py\\", line 550, in http_response\\n    \'http\', request, response, code, msg, hdrs)\\n  File \\"/usr/lib64/python2.7/urllib2.py\\", line 475, in error\\n    return self._call_chain(*args)\\n  File \\"/usr/lib64/python2.7/urllib2.py\\", line 409, in _call_chain\\n    result = func(*args)\\n  File \\"/usr/lib64/python2.7/urllib2.py\\", line 558, in http_error_default\\n    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)\\nHTTPError: HTTP Error 500: Internal Server Error\\n", "invocation": {"module_args": {"remember_me": null, "client_authentication_flow": null, "max_delta_time_seconds": null, "ssl_required": null, "auth_keycloak_url": "http://localhost:8080/auth", "display_name": null, "direct_grant_flow": null, "failure_factor": null, "access_token_lifespan_for_implicit_flow": null, "admin_events_enabled": null, "otp_policy_digits": null, "otp_supported_applications": null, "otp_policy_type": null, "access_code_lifespan_login": null, "max_failure_wait_seconds": null, "token": null, "otp_policy_initial_counter": null, "validate_certs": false, "account_theme": null, "login_with_email_allowed": null, "permanent_lockout": null, "registration_flow": null, "auth_client_secret": null, "reset_password_allowed": null, "default_groups": null, "smtp_server": null, "display_name_html": null, "state": "present", "duplicate_emails_allowed": null, "brute_force_protected": null, "edit_username_allowed": null, "otp_policy_period": null, "refresh_token_max_reuse": null, "supported_locales": null, "minimum_quick_login_wait_seconds": null, "registration_allowed": null, "internationalization_enabled": null, "offline_session_idle_timeout": null, "attributes": null, "otp_policy_look_ahead_window": null, "default_roles": null, "password_policy": null, "auth_realm": "master", "default_signature_algorithm": null, "verify_email": null, "auth_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "events_expiration": null, "otp_policy_algorithm": null, "access_token_lifespan": null, "browser_security_headers": null, "default_default_client_scopes": null, "events_listeners": null, "connection_timeout": 10, "auth_client_id": "admin-cli", "sso_session_max_lifespan_remember_me": null, "default_optional_client_scopes": null, "access_code_lifespan": null, "enabled": null, "registration_email_as_username": null, "access_code_lifespan_user_action": null, "sso_session_max_lifespan": null, "offline_session_max_lifespan": null, "events_enabled": null, "sso_session_idle_timeout_remember_me": null, "client_scope_mappings": null, "docker_authentication_flow": null, "wait_increment_seconds": null, "id": "testrealm", "enabled_event_types": null, "revoke_refresh_token": null, "reset_credentials_flow": null, "admin_events_details_enabled": null, "not_before": null, "user_managed_access_allowed": null, "action_token_generated_by_user_lifespan": null, "offline_session_max_lifespan_enabled": null, "browser_flow": null, "default_locale": null, "quick_login_check_milli_seconds": null, "action_token_generated_by_admin_lifespan": null, "http_agent": "Ansible", "admin_theme": null, "realm": null, "auth_username": "xxx@schleupen.de", "login_theme": null, "sso_session_idle_timeout": null, "email_theme": null}}}\n', b'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /home/xxx/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 65143\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n')
<keycloak.localdomain.localsite> Failed to connect to the host via ssh: OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /home/xxx/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 65143
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_community.general.keycloak_realm_payload_N2t5Xu/ansible_community.general.keycloak_realm_payload.zip/ansible_collections/community/general/plugins/module_utils/identity/keycloak/keycloak.py", line 315, in create_realm
    data=json.dumps(realmrep), validate_certs=self.validate_certs)
  File "/tmp/ansible_community.general.keycloak_realm_payload_N2t5Xu/ansible_community.general.keycloak_realm_payload.zip/ansible/module_utils/urls.py", line 1581, in open_url
    unredirected_headers=unredirected_headers)
  File "/tmp/ansible_community.general.keycloak_realm_payload_N2t5Xu/ansible_community.general.keycloak_realm_payload.zip/ansible/module_utils/urls.py", line 1486, in open
    return urllib_request.urlopen(request, None, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib64/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: Internal Server Error
fatal: [keycloak]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "access_code_lifespan": null,
            "access_code_lifespan_login": null,
            "access_code_lifespan_user_action": null,
            "access_token_lifespan": null,
            "access_token_lifespan_for_implicit_flow": null,
            "account_theme": null,
            "action_token_generated_by_admin_lifespan": null,
            "action_token_generated_by_user_lifespan": null,
            "admin_events_details_enabled": null,
            "admin_events_enabled": null,
            "admin_theme": null,
            "attributes": null,
            "auth_client_id": "admin-cli",
            "auth_client_secret": null,
            "auth_keycloak_url": "http://localhost:8080/auth",
            "auth_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "auth_realm": "master",
            "auth_username": "xxx@schleupen.de",
            "browser_flow": null,
            "browser_security_headers": null,
            "brute_force_protected": null,
            "client_authentication_flow": null,
            "client_scope_mappings": null,
            "connection_timeout": 10,
            "default_default_client_scopes": null,
            "default_groups": null,
            "default_locale": null,
            "default_optional_client_scopes": null,
            "default_roles": null,
            "default_signature_algorithm": null,
            "direct_grant_flow": null,
            "display_name": null,
            "display_name_html": null,
            "docker_authentication_flow": null,
            "duplicate_emails_allowed": null,
            "edit_username_allowed": null,
            "email_theme": null,
            "enabled": null,
            "enabled_event_types": null,
            "events_enabled": null,
            "events_expiration": null,
            "events_listeners": null,
            "failure_factor": null,
            "http_agent": "Ansible",
            "id": "testrealm",
            "internationalization_enabled": null,
            "login_theme": null,
            "login_with_email_allowed": null,
            "max_delta_time_seconds": null,
            "max_failure_wait_seconds": null,
            "minimum_quick_login_wait_seconds": null,
            "not_before": null,
            "offline_session_idle_timeout": null,
            "offline_session_max_lifespan": null,
            "offline_session_max_lifespan_enabled": null,
            "otp_policy_algorithm": null,
            "otp_policy_digits": null,
            "otp_policy_initial_counter": null,
            "otp_policy_look_ahead_window": null,
            "otp_policy_period": null,
            "otp_policy_type": null,
            "otp_supported_applications": null,
            "password_policy": null,
            "permanent_lockout": null,
            "quick_login_check_milli_seconds": null,
            "realm": null,
            "refresh_token_max_reuse": null,
            "registration_allowed": null,
            "registration_email_as_username": null,
            "registration_flow": null,
            "remember_me": null,
            "reset_credentials_flow": null,
            "reset_password_allowed": null,
            "revoke_refresh_token": null,
            "smtp_server": null,
            "ssl_required": null,
            "sso_session_idle_timeout": null,
            "sso_session_idle_timeout_remember_me": null,
            "sso_session_max_lifespan": null,
            "sso_session_max_lifespan_remember_me": null,
            "state": "present",
            "supported_locales": null,
            "token": null,
            "user_managed_access_allowed": null,
            "validate_certs": false,
            "verify_email": null,
            "wait_increment_seconds": null
        }
    },
    "msg": "Could not create realm testrealm: HTTP Error 500: Internal Server Error"
}

PLAY RECAP *************************************************************************************************************
keycloak             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Code of Conduct

ansibullbot commented 2 years ago

Files identified in the description:

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

ansibullbot commented 2 years ago

cc @eikef @kris2kris @ndclt click here for bot help

agr-schleupen commented 2 years ago

By chance I found that it is required to provide the parameter realm = "testrealm".

ansibullbot commented 1 year ago

Files identified in the description:

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

ansibullbot commented 1 year ago

cc @mattock click here for bot help

ansibullbot commented 1 month ago

cc @thomasbach-dev click here for bot help