Skip to content
Extraits de code Groupes Projets
update-service.yml 2,22 ko
Newer Older
nono's avatar
nono a validé
# Update the keycloak installation
- name: Checking for pre-existing installation
  stat:
    path: "{{ keycloak_base_path }}/keycloak-{{ keycloak_previous_version }}"
  register: is_there_an_existing_keycloak
nono's avatar
nono a validé

- name: Printing status of pre-existing installation
  debug:
    msg: "{{ is_there_an_existing_keycloak }}"

- name: Updating if needed
  block:
    # Stop the service
    - name: Stopping the service for the update.
      become: yes
      systemd:
        name: "{{ keycloak_service_name }}"
        state: stopped
      ignore_errors: true

    # Delete the data/tx-object-store/ transaction directory
    - name: Deleting the data/tx-object-store/ transaction directory
      file:
        path: "{{ keycloak_base_path }}/keycloak-{{ keycloak_previous_version }}/standalone/data/tx-object-store/"
        state: absent

    # Backup the old installation
    #- name: Making a copy of the current installation
    # NB: Not needed as we are installing to a new directory anyways. We don't touch
    # the old directory.

    # Backup the database
    - name: Backing up the of database
      become: yes
      shell: mysqldump keycloak > /root/keycloak-backup-$(date --iso).sql

    # Upgrade the server
    #- name: Upgrading the server with the new files
    # This is actually reinstalling the files.

    # copy the KEYCLOAK_HOME/standalone/ directory from the previous installation over the directory in the new installation.
    - name: Copying the standalone directory from the previous installation
      become: yes
      copy:
        src: "{{ keycloak_base_path }}/keycloak-{{ keycloak_previous_version }}/standalone"
        dest: "{{ keycloak_base_path }}/keycloak-{{ keycloak_version }}/standalone"
        remote_src: yes

    # Run the upgrade script
    # bin/jboss-cli.sh --file=bin/migrate-standalone-ha.cli
    - name: Running the upgrade script
      shell: "{{ keycloak_jboss_home}}/bin/jboss-cli.sh --file={{ keycloak_jboss_home}}/bin/migrate-standalone-ha.cli"

  when: is_there_an_existing_keycloak.stat.exists

- name: Update state
  debug:
    msg: "No update done."
  when: not is_there_an_existing_keycloak.stat.exists
nono's avatar
nono a validé

- name:  Force systemd to reread configs
  become: yes
nono's avatar
nono a validé
  ansible.builtin.systemd:
    daemon_reload: yes