From c6b20f81656351db4444789aa3a8ba92269919f6 Mon Sep 17 00:00:00 2001 From: Melekhin Anton Date: Mon, 2 Sep 2024 23:53:22 +0400 Subject: [PATCH 1/2] merge OS-specific variables into the `vars/main.yml` file --- tasks/install-Debian.yml | 2 +- tasks/main.yml | 3 --- templates/microsoft.list.j2 | 4 ++-- templates/microsoft.repo.j2 | 4 ++-- vars/Debian.yml | 6 ------ vars/RedHat.yml | 3 --- vars/main.yml | 14 ++++++++++++++ 7 files changed, 19 insertions(+), 17 deletions(-) delete mode 100644 vars/Debian.yml delete mode 100644 vars/RedHat.yml create mode 100644 vars/main.yml diff --git a/tasks/install-Debian.yml b/tasks/install-Debian.yml index b277d42..2aa5d27 100644 --- a/tasks/install-Debian.yml +++ b/tasks/install-Debian.yml @@ -15,7 +15,7 @@ - name: 'Debian | Add the Microsoft repository GPG key' ansible.builtin.apt_key: url: '{{ microsoft_repository_gpgkey_url }}' - keyring: '{{ _microsoft_repository_local_gpgkey_path }}' + keyring: '{{ __microsoft_repository_gpgkey_keyring }}' state: 'present' - name: 'Debian | Add the Microsoft repository' diff --git a/tasks/main.yml b/tasks/main.yml index 4479d2b..bc2c135 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,3 @@ --- -- name: 'Load the Microsoft repository OS-specific variables' - ansible.builtin.include_vars: '{{ ansible_os_family }}.yml' - - name: 'Install Microsoft packages' ansible.builtin.include_tasks: 'install-{{ ansible_os_family }}.yml' diff --git a/templates/microsoft.list.j2 b/templates/microsoft.list.j2 index e5988ab..dfb0fc2 100644 --- a/templates/microsoft.list.j2 +++ b/templates/microsoft.list.j2 @@ -2,8 +2,8 @@ {% for microsoft_repository_dir in microsoft_repository_dirs_list %} {% if microsoft_repository_dir.type is defined and microsoft_repository_dir.type == 'alternative' %} -deb [arch=amd64,arm64,armhf signed-by={{ _microsoft_repository_local_gpgkey_path }}] {{ _microsoft_repository_alternative_mirror_url }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main +deb [arch=amd64,arm64,armhf signed-by={{ __microsoft_repository_gpgkey_keyring }}] {{ __microsoft_repository_alternative }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main {% else %} -deb [arch=amd64,arm64,armhf signed-by={{ _microsoft_repository_local_gpgkey_path }}] {{ _microsoft_repository_base_mirror_url }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main +deb [arch=amd64,arm64,armhf signed-by={{ __microsoft_repository_gpgkey_keyring }}] {{ __microsoft_repository_base }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main {% endif %} {% endfor %} diff --git a/templates/microsoft.repo.j2 b/templates/microsoft.repo.j2 index ffd76ca..87bfbc3 100644 --- a/templates/microsoft.repo.j2 +++ b/templates/microsoft.repo.j2 @@ -3,9 +3,9 @@ {% for microsoft_repository_dir in microsoft_repository_dirs_list %} [packages-microsoft-com-{{ microsoft_repository_dir.name }}] {% if microsoft_repository_dir.type is defined and microsoft_repository_dir.type == 'alternative' %} -baseurl = {{ _microsoft_repository_alternative_mirror_url }}/{{ microsoft_repository_dir.name }} +baseurl = {{ __microsoft_repository_alternative }}/{{ microsoft_repository_dir.name }} {% else %} -baseurl = {{ _microsoft_repository_base_mirror_url }}/{{ microsoft_repository_dir.name }} +baseurl = {{ __microsoft_repository_base }}/{{ microsoft_repository_dir.name }} {% endif %} enabled = 1 gpgcheck = 1 diff --git a/vars/Debian.yml b/vars/Debian.yml deleted file mode 100644 index 3b904b4..0000000 --- a/vars/Debian.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -_microsoft_repository_local_gpgkey_path: '/usr/share/keyrings/microsoft-archive-keyring.gpg' - -_microsoft_repository_distribution_version: "{{ (ansible_distribution == 'Ubuntu') | ternary(ansible_distribution_version, ansible_distribution_major_version) }}" -_microsoft_repository_base_mirror_url: '{{ microsoft_repository_mirror_url }}/{{ ansible_distribution | lower }}/{{ _microsoft_repository_distribution_version }}' -_microsoft_repository_alternative_mirror_url: '{{ microsoft_repository_mirror_url }}/repos' diff --git a/vars/RedHat.yml b/vars/RedHat.yml deleted file mode 100644 index 981c475..0000000 --- a/vars/RedHat.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -_microsoft_repository_base_mirror_url: '{{ microsoft_repository_mirror_url }}/rhel/{{ ansible_distribution_major_version }}' -_microsoft_repository_alternative_mirror_url: '{{ microsoft_repository_mirror_url }}/yumrepos' diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..b8f514e --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,14 @@ +--- +__microsoft_repository_gpgkey_keyring: '/usr/share/keyrings/microsoft-archive-keyring.gpg' + +__microsoft_repository_base_dict: + Debian: "{{ microsoft_repository_mirror_url }}/{{ ansible_distribution | lower }}/{{ (ansible_distribution == 'Ubuntu') | ternary(ansible_distribution_version, ansible_distribution_major_version) }}" + RedHat: '{{ microsoft_repository_mirror_url }}/rhel/{{ ansible_distribution_major_version }}' + +__microsoft_repository_base: '{{ __microsoft_repository_base_dict[ansible_os_family] }}' + +__microsoft_repository_alternative_dict: + Debian: '{{ microsoft_repository_mirror_url }}/repos' + RedHat: '{{ microsoft_repository_mirror_url }}/yumrepos' + +__microsoft_repository_alternative: '{{ __microsoft_repository_alternative_dict[ansible_os_family] }}' From 21f4266584979216be43dd4ebf6a0b214d0e5135 Mon Sep 17 00:00:00 2001 From: Melekhin Anton Date: Tue, 3 Sep 2024 00:00:08 +0400 Subject: [PATCH 2/2] minor update installation tasks --- tasks/install-Debian.yml | 5 +++-- tasks/install-RedHat.yml | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tasks/install-Debian.yml b/tasks/install-Debian.yml index 2aa5d27..e2843cf 100644 --- a/tasks/install-Debian.yml +++ b/tasks/install-Debian.yml @@ -9,8 +9,9 @@ - 'ca-certificates' - 'gnupg' update_cache: true + cache_valid_time: 3600 state: 'present' - when: not ansible_check_mode + check_mode: false - name: 'Debian | Add the Microsoft repository GPG key' ansible.builtin.apt_key: @@ -31,4 +32,4 @@ name: '{{ microsoft_repository_packages }}' update_cache: true state: 'present' - when: not ansible_check_mode + ignore_errors: '{{ ansible_check_mode }}' diff --git a/tasks/install-RedHat.yml b/tasks/install-RedHat.yml index 6609d8a..917e58f 100644 --- a/tasks/install-RedHat.yml +++ b/tasks/install-RedHat.yml @@ -4,7 +4,9 @@ block: - name: 'RedHat | Ensure the dependencies are installed' ansible.builtin.package: - name: 'yum-utils' + name: + - 'ca-certificates' + - 'yum-utils' state: 'present' - name: 'RedHat | Add the Microsoft repository' @@ -19,4 +21,4 @@ ansible.builtin.package: name: '{{ microsoft_repository_packages }}' state: 'present' - when: not ansible_check_mode + ignore_errors: '{{ ansible_check_mode }}'