From 0751b97b87b87a4f1f19c95054acbdb0c4e8a43f Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Tue, 12 Apr 2022 12:07:06 +0200 Subject: [PATCH] Add custom xml parameter and test scenario --- molecule/default/converge.yml | 9 +- molecule/default/roles | 1 + molecule/overridexml/converge.yml | 43 ++ molecule/overridexml/molecule.yml | 53 ++ molecule/overridexml/prepare.yml | 12 + molecule/overridexml/requirements.yml | 10 + molecule/overridexml/roles | 1 + molecule/overridexml/templates/custom.xml.j2 | 604 +++++++++++++++++++ molecule/overridexml/verify.yml | 11 + molecule/quarkus/converge.yml | 2 +- roles/keycloak/README.md | 1 + roles/keycloak/defaults/main.yml | 1 + roles/keycloak/meta/argument_specs.yml | 5 + roles/keycloak/tasks/install.yml | 6 +- roles/keycloak/vars/main.yml | 1 + 15 files changed, 751 insertions(+), 9 deletions(-) create mode 120000 molecule/default/roles create mode 100644 molecule/overridexml/converge.yml create mode 100644 molecule/overridexml/molecule.yml create mode 100644 molecule/overridexml/prepare.yml create mode 100644 molecule/overridexml/requirements.yml create mode 120000 molecule/overridexml/roles create mode 100644 molecule/overridexml/templates/custom.xml.j2 create mode 100644 molecule/overridexml/verify.yml diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 2ab6ad5..938aaa0 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -3,13 +3,12 @@ hosts: all vars: keycloak_admin_password: "remembertochangeme" + roles: + - role: keycloak tasks: - - name: Include keycloak role - include_role: - name: ../../roles/keycloak - name: Keycloak Realm Role - include_role: - name: ../../roles/keycloak_realm + ansible.builtin.include_role: + name: keycloak_realm vars: keycloak_client_default_roles: - TestRoleAdmin diff --git a/molecule/default/roles b/molecule/default/roles new file mode 120000 index 0000000..b741aa3 --- /dev/null +++ b/molecule/default/roles @@ -0,0 +1 @@ +../../roles \ No newline at end of file diff --git a/molecule/overridexml/converge.yml b/molecule/overridexml/converge.yml new file mode 100644 index 0000000..9304eba --- /dev/null +++ b/molecule/overridexml/converge.yml @@ -0,0 +1,43 @@ +--- +- name: Converge + hosts: all + vars: + keycloak_admin_password: "remembertochangeme" + keycloak_config_override_template: custom.xml.j2 + keycloak_http_port: 8081 + keycloak_management_http_port: 19990 + roles: + - role: keycloak + tasks: + - name: Keycloak Realm Role + ansible.builtin.include_role: + name: keycloak_realm + vars: + keycloak_client_default_roles: + - TestRoleAdmin + - TestRoleUser + keycloak_client_users: + - username: TestUser + password: password + client_roles: + - client: TestClient + role: TestRoleUser + realm: "{{ keycloak_realm }}" + - username: TestAdmin + password: password + client_roles: + - client: TestClient + role: TestRoleUser + realm: "{{ keycloak_realm }}" + - client: TestClient + role: TestRoleAdmin + realm: "{{ keycloak_realm }}" + keycloak_realm: TestRealm + keycloak_clients: + - name: TestClient + roles: "{{ keycloak_client_default_roles }}" + realm: "{{ keycloak_realm }}" + public_client: "{{ keycloak_client_public }}" + web_origins: "{{ keycloak_client_web_origins }}" + users: "{{ keycloak_client_users }}" + client_id: TestClient diff --git a/molecule/overridexml/molecule.yml b/molecule/overridexml/molecule.yml new file mode 100644 index 0000000..ea8ad61 --- /dev/null +++ b/molecule/overridexml/molecule.yml @@ -0,0 +1,53 @@ +--- +dependency: + name: shell + command: ansible-galaxy collection install -r molecule/default/requirements.yml -p $HOME/.ansible/collections --force-with-deps +driver: + name: docker +lint: | + ansible-lint --version + ansible-lint -v +platforms: + - name: instance + image: registry.access.redhat.com/ubi8/ubi-init:latest + pre_build_image: true + privileged: true + command: "/usr/sbin/init" + port_bindings: + - "8080/tcp" + - "8443/tcp" + - "8009/tcp" +provisioner: + name: ansible + config_options: + defaults: + interpreter_python: auto_silent + ssh_connection: + pipelining: false + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: verify.yml + inventory: + host_vars: + localhost: + ansible_python_interpreter: "{{ ansible_playbook_python }}" + env: + ANSIBLE_FORCE_COLOR: "true" +verifier: + name: ansible +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/molecule/overridexml/prepare.yml b/molecule/overridexml/prepare.yml new file mode 100644 index 0000000..03433c0 --- /dev/null +++ b/molecule/overridexml/prepare.yml @@ -0,0 +1,12 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: Disable beta repos + ansible.builtin.command: yum config-manager --disable '*beta*' + ignore_errors: yes + + - name: Install sudo + ansible.builtin.yum: + name: sudo + state: present diff --git a/molecule/overridexml/requirements.yml b/molecule/overridexml/requirements.yml new file mode 100644 index 0000000..9aa3437 --- /dev/null +++ b/molecule/overridexml/requirements.yml @@ -0,0 +1,10 @@ +--- +collections: + - name: middleware_automation.redhat_csp_download + version: ">=1.2.1" + - name: middleware_automation.wildfly + version: ">=0.0.5" + - name: community.general + - name: community.docker + version: ">=1.9.1" + diff --git a/molecule/overridexml/roles b/molecule/overridexml/roles new file mode 120000 index 0000000..b741aa3 --- /dev/null +++ b/molecule/overridexml/roles @@ -0,0 +1 @@ +../../roles \ No newline at end of file diff --git a/molecule/overridexml/templates/custom.xml.j2 b/molecule/overridexml/templates/custom.xml.j2 new file mode 100644 index 0000000..a59561a --- /dev/null +++ b/molecule/overridexml/templates/custom.xml.j2 @@ -0,0 +1,604 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + h2 + + sa + sa + + + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + auth + + + classpath:${jboss.home.dir}/providers/* + + + master + 900 + + 2592000 + true + true + ${jboss.home.dir}/themes + + + + + + + + + + + + + jpa + + + basic + + + + + + + + + + + + + + + + + + + default + + + + + + + + ${keycloak.jta.lookup.provider:jboss} + + + + + + + + + + + ${keycloak.x509cert.lookup.provider:default} + + + + default + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/molecule/overridexml/verify.yml b/molecule/overridexml/verify.yml new file mode 100644 index 0000000..ef973cd --- /dev/null +++ b/molecule/overridexml/verify.yml @@ -0,0 +1,11 @@ +--- +- name: Verify + hosts: all + tasks: + - name: Populate service facts + ansible.builtin.service_facts: + - name: Check if keycloak service started + ansible.builtin.assert: + that: + - ansible_facts.services["keycloak.service"]["state"] == "running" + - ansible_facts.services["keycloak.service"]["status"] == "enabled" diff --git a/molecule/quarkus/converge.yml b/molecule/quarkus/converge.yml index 452212b..1f77fe5 100644 --- a/molecule/quarkus/converge.yml +++ b/molecule/quarkus/converge.yml @@ -3,12 +3,12 @@ hosts: all vars: keycloak_quarkus_admin_pass: "remembertochangeme" + keycloak_admin_password: "remembertochangeme" keycloak_realm: TestRealm roles: - role: keycloak_quarkus - role: keycloak_realm keycloak_context: '' - keycloak_admin_password: "remembertochangeme" keycloak_client_default_roles: - TestRoleAdmin - TestRoleUser diff --git a/roles/keycloak/README.md b/roles/keycloak/README.md index 3588b86..7ef3cb5 100644 --- a/roles/keycloak/README.md +++ b/roles/keycloak/README.md @@ -99,6 +99,7 @@ Role Defaults |`keycloak_jboss_home` | Installation work directory | `{{ keycloak_rhsso_installdir if keycloak_rhsso_enable else keycloak_installdir }}` | |`keycloak_config_dir` | Path for configuration | `{{ keycloak_jboss_home }}/standalone/configuration` | |`keycloak_config_path_to_standalone_xml` | Custom path for configuration | `{{ keycloak_jboss_home }}/standalone/configuration/{{ keycloak_config_standalone_xml }}` | +|`keycloak_config_override_template` | Path to custom template for standalone.xml configuration | `''` | |`keycloak_auth_realm` | Name for rest authentication realm | `master` | |`keycloak_auth_client` | Authentication client for configuration REST calls | `admin-cli` | |`keycloak_force_install` | Remove pre-existing versions of service | `False` | diff --git a/roles/keycloak/defaults/main.yml b/roles/keycloak/defaults/main.yml index c9d8d29..f33d332 100644 --- a/roles/keycloak/defaults/main.yml +++ b/roles/keycloak/defaults/main.yml @@ -27,6 +27,7 @@ keycloak_jboss_home: "{{ keycloak_rhsso_installdir if keycloak_rhsso_enable else keycloak_config_dir: "{{ keycloak_jboss_home }}/standalone/configuration" keycloak_config_standalone_xml: "keycloak.xml" keycloak_config_path_to_standalone_xml: "{{ keycloak_jboss_home }}/standalone/configuration/{{ keycloak_config_standalone_xml }}" +keycloak_config_override_template: '' keycloak_service_user: keycloak keycloak_service_group: keycloak keycloak_service_pidfile: "/run/keycloak.pid" diff --git a/roles/keycloak/meta/argument_specs.yml b/roles/keycloak/meta/argument_specs.yml index 3c428c9..67121c2 100644 --- a/roles/keycloak/meta/argument_specs.yml +++ b/roles/keycloak/meta/argument_specs.yml @@ -106,6 +106,11 @@ argument_specs: default: "{{ keycloak_jboss_home }}/standalone/configuration/{{ keycloak_config_standalone_xml }}" description: "Custom path for configuration" type: "str" + keycloak_config_override_template: + # line 30 of keycloak/defaults/main.yml + default: "" + description: "Path to custom template for standalone.xml configuration" + type: "str" keycloak_service_user: # line 29 of keycloak/defaults/main.yml default: "keycloak" diff --git a/roles/keycloak/tasks/install.yml b/roles/keycloak/tasks/install.yml index c45a842..9e0dbd3 100644 --- a/roles/keycloak/tasks/install.yml +++ b/roles/keycloak/tasks/install.yml @@ -181,17 +181,17 @@ jdbc_driver_module_name: "{{ keycloak_jdbc[keycloak_jdbc_engine].driver_module_name }}" when: keycloak_jdbc[keycloak_jdbc_engine].enabled -- name: "Deploy {{ keycloak.service_name }} config to {{ keycloak_config_path_to_standalone_xml }}" +- name: "Deploy {{ keycloak.service_name }} config to {{ keycloak_config_path_to_standalone_xml }} from {{ keycloak.config_template_source }}" become: yes ansible.builtin.template: - src: templates/standalone.xml.j2 + src: "templates/{{ keycloak.config_template_source }}" dest: "{{ keycloak_config_path_to_standalone_xml }}" owner: "{{ keycloak_service_user }}" group: "{{ keycloak_service_group }}" mode: 0640 notify: - restart keycloak - when: not keycloak_remotecache.enabled + when: not keycloak_remotecache.enabled or keycloak_config_override_template|length > 0 - name: "Deploy {{ keycloak.service_name }} config with remote cache store to {{ keycloak_config_path_to_standalone_xml }}" become: yes diff --git a/roles/keycloak/vars/main.yml b/roles/keycloak/vars/main.yml index 437eac0..f639970 100644 --- a/roles/keycloak/vars/main.yml +++ b/roles/keycloak/vars/main.yml @@ -20,6 +20,7 @@ keycloak: service_name: "{{ 'rhsso' if keycloak_rhsso_enable else 'keycloak' }}" health_url: "{{ keycloak_management_url }}/health" cli_path: "{{ keycloak_jboss_home }}/bin/jboss-cli.sh" + config_template_source: "{{ keycloak_config_override_template if keycloak_config_override_template | length > 0 else 'standalone.xml.j2' }}" # database keycloak_jdbc: