How to import an area into Keycloak and exit

I followed the Keycloak admin guide to export and import areas using standalone.shit works, but it starts the server and does not exit.

This is a problem for me, because I want to automate this process using the Ansible executable, and therefore I cannot, because the task never ends.

I found a workaround in Ansible with asyncand wait_for, but was hoping for a better way that does not require the use of the Admin REST API.

- name: Stop keycloak
  service:
    name: keycloak
    state: stopped
- name: Import realm into Keycloak
  shell: "{{keycloak_home}}/bin/standalone.sh -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=master -Dkeycloak.migration.usersExportStrategy=SAME_FILE -Dkeycloak.migration.realmName=master"
  async: 30
  poll: 0
- name: Wait for Keycloak to be started and listen on port 8080
  wait_for:
    host: 0.0.0.0
    port: 8080
    delay: 10
- name: Restart keycloak
  service:
    name: keycloak
    state: restarted
+4
source share

Source: https://habr.com/ru/post/1672392/


All Articles