|
| 1 | +--- |
| 2 | + |
| 3 | +# Find installed FLUX-CLI Version |
| 4 | +- name: "FLUX-CLI::INSTALL - Get Flux CD version if installed" |
| 5 | + ansible.builtin.command: flux version --client |
| 6 | + register: fluxcli_version_output |
| 7 | + changed_when: false |
| 8 | + ignore_errors: true |
| 9 | + |
| 10 | +# Define Flux CD Version as Variable if Installed |
| 11 | +- name: "FLUX-CLI::INSTALL - Define FLUX-CLI Version as Variable if Installed" |
| 12 | + ansible.builtin.set_fact: |
| 13 | + installed_fluxcli_version: "{{ fluxcli_version_output.stdout | regex_replace('^flux\\s*:\\s*v([0-9.]+).*', '\\1') | regex_replace('^v', '') }}" |
| 14 | + fluxcli_semantic_version: "{{ fluxcli_version.split('+')[0] | regex_replace('^v', '') }}" |
| 15 | + when: fluxcli_version_output.rc == 0 |
| 16 | + |
| 17 | +# Print Vars |
| 18 | +- name: "FLUX-CLI::INSTALL - Show Installed Version Result [({{ ansible_distribution }})]" |
| 19 | + ansible.builtin.debug: |
| 20 | + var: fluxcli_version_output |
| 21 | + |
| 22 | +# Print Vars |
| 23 | +- name: "FLUX-CLI::INSTALL - Show Facts [({{ ansible_distribution }})]" |
| 24 | + ansible.builtin.debug: |
| 25 | + msg: |
| 26 | + - "FLUX-CLI Installed Version : {{ installed_fluxcli_version | default('') }}" |
| 27 | + - "FLUX-CLI Required Version : {{ fluxcli_semantic_version | default('') }}" |
| 28 | + - "FLUX-CLI Original Version : {{ fluxcli_version }}" |
| 29 | + |
| 30 | +# Download and install FLUX-CLI if not yet installed |
| 31 | +- name: "FLUX-CLI::INSTALL - Installation Block [({{ ansible_distribution }})]" |
| 32 | + when: |
| 33 | + - fluxcli_version_output.rc != 0 or installed_fluxcli_version is version(fluxcli_semantic_version, '<') |
| 34 | + block: |
| 35 | + |
| 36 | + # Create Required Directories |
| 37 | + - name: "FLUX-CLI::INSTALL - Ensure FLUX-CLI directories are created [({{ ansible_distribution }})]" |
| 38 | + ansible.builtin.file: |
| 39 | + path: "{{ item.path }}" |
| 40 | + state: directory |
| 41 | + mode: "{{ item.mode | default('u+rwx,g+rwx,o+x') }}" |
| 42 | + recurse: true |
| 43 | + loop: |
| 44 | + - { path: "{{ fluxcli_extraction_root_dir }}", mode: "u+rwx,g+rwx,o+rwx" } |
| 45 | + |
| 46 | + # Download and Unarchive Flux CD |
| 47 | + - name: "FLUX-CLI::INSTALL - Download and Unarchive FLUX-CLI [({{ ansible_distribution }})]" |
| 48 | + ansible.builtin.unarchive: |
| 49 | + src: "{{ fluxcli_archive_url }}" |
| 50 | + dest: "{{ fluxcli_extraction_root_dir }}" |
| 51 | + remote_src: true |
| 52 | + |
| 53 | + # Install Flux CD |
| 54 | + - name: "FLUX-CLI::INSTALL - Install FLUX-CLI [({{ ansible_distribution }})]" |
| 55 | + ansible.builtin.copy: |
| 56 | + src: "{{ fluxcli_extraction_root_dir }}/flux" |
| 57 | + dest: "{{ fluxcd_binary_path }}/flux" |
| 58 | + remote_src: true |
| 59 | + force: true |
| 60 | + backup: true |
| 61 | + mode: '0755' |
0 commit comments