Skip to content
Extraits de code Groupes Projets
update-service.yml 1,82 ko
Newer Older
nono's avatar
nono a validé
# Check if there is a keycloak directory in the base_path
- name: Check for existing keycloak installation
  find:
    paths: "{{ keycloak_base_path }}/keycloak-*"
    file_type: "directory"
    depth: 1
  register: keycloak_existing_installations
nono's avatar
nono a validé

nono's avatar
nono a validé
- name: Checking if there is an existing installation that needs to be updated
  block:
    # We need to extract the version of each directory and add them to a list
    # If so, what is it's version ? ( cut from  "keycloak-$version ")
    - name: Check existing versions from directorie's names
      set_fact: keycloak_list_of_versions="{{ keycloak_existing_installations.files | map(attribute='path') | regex_search('-([0-9]+\.[0-9]+\.[0-9]+\b)$') | list }}"
    
    # Compare such version to the one given
    - name: Compare every version with the keycloak_version 
      set_fact: keycloak_needs_an_update="keycloak_list_of_versions | version(keycloak_list_of_versions, "<") | reject(false, omit) | list"
    # If the $old_version < $new_version, we need to update

  # They may be multi keycloak directories
  when: keycloak_existing_installations.matched >= 1
nono's avatar
nono a validé
- name: Updating if keycloak needs an update
  block:
    # Stop the service
    - name: Stopping the service for the update.
      become: yes
      systemd:
        name: "{{ keycloak_service_name }}"
        state: stopped

nono's avatar
nono a validé
    # NB: We are installing to a new directory. 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.
nono's avatar
nono a validé
  when: true in keycloak_needs_an_update
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