<commit_before>---

## start the installation of keycloak

- name: Include OS-specific variables
  include_vars: "{{ item }}"
  with_first_found:
    - "os/{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
    - "os/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
    - "os/{{ ansible_distribution }}.yml"
    - "os/{{ ansible_os_family }}.yml"
  tags:
    - always

- name: Include keycloak-specific variables
  include_vars: "keycloak/{{ keycloak_version }}.yml"
  tags:
    - always

### Install Java with OS-specific packages
- include: "java/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
  tags:
    - always

### create keycloak_service_user
- name: Create Keycloak service user/group
  user:
    name: "{{ keycloak_service_user }}"
    home: /nonexistent
    shell: /usr/sbin/nologin
    system: yes
    create_home: no
  become: yes
  tags:
    - always

### setup the logs folder (also do some actions to preserve backwards compatibility)
- name: "Setup logs folder"
  include_tasks: "blocks/helpers/setup_logs_folder.yml"
  tags: "keycloak:install:setup_logs_folder"

#### Extract keycloak from archive
- block:
    - name: "Task block: Download keycloak"
      block:
        - name: Create keycloak temp directory
          file:
            path: "/tmp/keycloak-tmp"
            state: directory
        - name: Download keycloak archive file
          get_url:
            url: "{{ keycloak_archive_url }}"
            dest: "/tmp/keycloak_archive"
            timeout: 30
        - name: Compute sha1 hash of archive
          stat:
            path: "/tmp/keycloak_archive"
            checksum_algorithm: sha1
          register: keycloak_sha1
        - name: Create keycloak_home if not exists
          file:
            path: "{{ keycloak_home }}"
            state: directory
        - name: create empty file if not exists
          copy:
            dest: "{{ keycloak_home }}/sha1"
            content: ""
            force: no
        - name: Previous sha1
          shell: "cat {{ keycloak_home }}/sha1"
          register: previous_sha1
        - name: "Compare sha1"
          set_fact:
            is_same_archive: "{{ true if keycloak_sha1.stat.checksum == previous_sha1.stdout else false }}"
      become: yes

    - name: "Task block: Extract keycloak"
      block:
        - name: unpack keycloak
          unarchive:
            src: "/tmp/keycloak_archive"
            dest: "/tmp/keycloak-tmp"
            remote_src: yes
            extra_opts: "--no-same-owner" #since it's run with elevated priviledges, to avoid preserving ownership from the archive
        - name: Find keycloak extracted folder name
          find:
            paths: /tmp/keycloak-tmp
            patterns: 'keycloak*'
            file_type: directory
            recurse: no
          register: find_result
        - name: Remove any previous installation
          file:
            path: "{{ keycloak_home }}"
            state: absent
        - name: Move extracted keycloak to final keycloak folder
          command: "mv {{ find_result.files[0].path }} {{ keycloak_home }}"
          args:
            removes: "{{ find_result.files[0].path }}"
            creates: "{{ keycloak_home }}"

        - name: Store previous sha1
          copy:
            dest: "{{ keycloak_home }}/sha1"
            content: "{{ keycloak_sha1.stat.checksum }}"
      become: yes
      when: not is_same_archive

  always:
    - name: Delete downloaded archive
      file:
        path: "/tmp/keycloak_archive"
        state: absent
  become: yes
  tags: "keycloak:install:download_extract"


- name: "Installation mode determined: {{ keycloak_deployment_mode }}. Importing mode specific tasks"
  import_tasks: "{{ keycloak_deployment_mode }}/install.yml"
  vars:
    - keycloak_deployment_mode: "{% if keycloak_version.split('.')[0] | int >= 18 %}quarkus{% elif keycloak_version.split('.')[0] | int < 18 %}wildfly{% endif %}"


##### configure keycloak

- name: Configure various keycloak aspects
  import_tasks: "configure.yml"
  tags: "keycloak:config"<commit_msg>keycloak role: followed API changes of federation configuration (quarkus and wildfly distinction)<commit_after>---

## start the installation of keycloak

- name: Include OS-specific variables
  include_vars: "{{ item }}"
  with_first_found:
    - "os/{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
    - "os/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
    - "os/{{ ansible_distribution }}.yml"
    - "os/{{ ansible_os_family }}.yml"
  tags:
    - always

- name: Include keycloak-specific variables
  include_vars: "keycloak/{{ keycloak_version }}.yml"
  tags:
    - always

### Install Java with OS-specific packages
- include: "java/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
  tags:
    - always

### create keycloak_service_user
- name: Create Keycloak service user/group
  user:
    name: "{{ keycloak_service_user }}"
    home: /nonexistent
    shell: /usr/sbin/nologin
    system: yes
    create_home: no
  become: yes
  tags:
    - always

### setup the logs folder (also do some actions to preserve backwards compatibility)
- name: "Setup logs folder"
  include_tasks: "blocks/helpers/setup_logs_folder.yml"
  tags: "keycloak:install:setup_logs_folder"

#### Extract keycloak from archive
- block:
    - name: "Task block: Download keycloak"
      block:
        - name: Create keycloak temp directory
          file:
            path: "/tmp/keycloak-tmp"
            state: directory
        - name: Download keycloak archive file
          get_url:
            url: "{{ keycloak_archive_url }}"
            dest: "/tmp/keycloak_archive"
            timeout: 30
        - name: Compute sha1 hash of archive
          stat:
            path: "/tmp/keycloak_archive"
            checksum_algorithm: sha1
          register: keycloak_sha1
        - name: Create keycloak_home if not exists
          file:
            path: "{{ keycloak_home }}"
            state: directory
        - name: create empty file if not exists
          copy:
            dest: "{{ keycloak_home }}/sha1"
            content: ""
            force: no
        - name: Previous sha1
          shell: "cat {{ keycloak_home }}/sha1"
          register: previous_sha1
        - name: "Compare sha1"
          set_fact:
            is_same_archive: "{{ true if keycloak_sha1.stat.checksum == previous_sha1.stdout else false }}"
      become: yes

    - name: "Task block: Extract keycloak"
      block:
        - name: unpack keycloak
          unarchive:
            src: "/tmp/keycloak_archive"
            dest: "/tmp/keycloak-tmp"
            remote_src: yes
            extra_opts: "--no-same-owner" #since it's run with elevated priviledges, to avoid preserving ownership from the archive
        - name: Find keycloak extracted folder name
          find:
            paths: /tmp/keycloak-tmp
            patterns: 'keycloak*'
            file_type: directory
            recurse: no
          register: find_result
        - name: Remove any previous installation
          file:
            path: "{{ keycloak_home }}"
            state: absent
        - name: Move extracted keycloak to final keycloak folder
          command: "mv {{ find_result.files[0].path }} {{ keycloak_home }}"
          args:
            removes: "{{ find_result.files[0].path }}"
            creates: "{{ keycloak_home }}"

        - name: Store previous sha1
          copy:
            dest: "{{ keycloak_home }}/sha1"
            content: "{{ keycloak_sha1.stat.checksum }}"
      become: yes
      when: not is_same_archive

  always:
    - name: Delete downloaded archive
      file:
        path: "/tmp/keycloak_archive"
        state: absent
  become: yes
  tags: "keycloak:install:download_extract"


- import_tasks: "quarkus/install.yml"
  when: keycloak_version.split('.')[0] | int >= 18

- import_tasks: "wildfly/install.yml"
  when: keycloak_version.split('.')[0] | int < 18


##### configure keycloak

- name: Configure various keycloak aspects
  import_tasks: "configure.yml"
  tags: "keycloak:config"
{'fraction_non_alphanumeric': 0.10800585794483769, 'fraction_numerical': 0.005613863802782524, 'mean_word_length': 2.2753796962430055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4527888', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2455, 'n_words': 649}