From 47cc10588bb0bee408931e760a57f62015a65708 Mon Sep 17 00:00:00 2001 From: Anton Melekhin <44847512+antmelekhin@users.noreply.github.com> Date: Sun, 10 Mar 2024 22:19:59 +0300 Subject: [PATCH] Improv: update variable names and add other changes (#12) --- README.md | 6 +++--- defaults/main.yml | 4 ++-- molecule/default/converge.yml | 2 +- tasks/install-Debian.yml | 3 ++- tasks/install-RedHat.yml | 5 ----- templates/microsoft.list.j2 | 6 +++--- templates/microsoft.repo.j2 | 8 ++++---- vars/Debian.yml | 3 ++- vars/RedHat.yml | 3 ++- vars/Ubuntu.yml | 3 ++- 10 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index f874628..636b5bd 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ Requirements Role Variables -------------- -- `microsoft_repository_mirror` Mirror of `Microsoft` repository (default: `https://packages.microsoft.com`). -- `microsoft_repository_key_url` URL to `Microsoft's` GPG public key file (default: `https://packages.microsoft.com/keys/microsoft.asc`). +- `microsoft_repository_mirror_url` Mirror of `Microsoft` repository (default: `https://packages.microsoft.com`). +- `microsoft_repository_gpgkey` URL to `Microsoft's` GPG public key file (default: `https://packages.microsoft.com/keys/microsoft.asc`). - `microsoft_repository_dirs_list` List of repository directories. See [repository structure](https://packages.microsoft.com/). Available values: @@ -75,7 +75,7 @@ Example Playbook - role: antmelekhin.microsoft_repository microsoft_repository_dirs_list: - name: azure-cli - type: alternate + type: alternative microsoft_repository_packages: - azure-cli ``` diff --git a/defaults/main.yml b/defaults/main.yml index 2d22782..37988e8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,6 @@ --- -microsoft_repository_mirror: 'https://packages.microsoft.com' -microsoft_repository_key_url: 'https://packages.microsoft.com/keys/microsoft.asc' +microsoft_repository_mirror_url: 'https://packages.microsoft.com' +microsoft_repository_gpgkey: '{{ microsoft_repository_mirror_url }}/keys/microsoft.asc' microsoft_repository_dirs_list: - name: prod diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index d89a008..d3a378f 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -6,7 +6,7 @@ microsoft_repository_dirs_list: - name: prod - name: azure-cli - type: alternate + type: alternative microsoft_repository_packages: - powershell - azure-cli diff --git a/tasks/install-Debian.yml b/tasks/install-Debian.yml index 76d8a6f..1fdd740 100644 --- a/tasks/install-Debian.yml +++ b/tasks/install-Debian.yml @@ -12,7 +12,8 @@ - name: 'Add Microsoft APT key' ansible.builtin.apt_key: - url: '{{ microsoft_repository_key_url }}' + url: '{{ microsoft_repository_gpgkey }}' + keyring: '/usr/share/keyrings/microsoft-archive-keyring.gpg' state: present when: not ansible_check_mode diff --git a/tasks/install-RedHat.yml b/tasks/install-RedHat.yml index 10782ca..7365bc0 100644 --- a/tasks/install-RedHat.yml +++ b/tasks/install-RedHat.yml @@ -2,11 +2,6 @@ - name: 'Configure DNF/YUM repository and install Microsoft packages' become: true block: - - name: 'Add Microsoft DNF/YUM key' - ansible.builtin.rpm_key: - key: '{{ microsoft_repository_key_url }}' - state: present - - name: 'Add Microsoft DNF/YUM repository' ansible.builtin.template: src: 'microsoft.repo.j2' diff --git a/templates/microsoft.list.j2 b/templates/microsoft.list.j2 index fa6ca9d..2314934 100644 --- a/templates/microsoft.list.j2 +++ b/templates/microsoft.list.j2 @@ -1,9 +1,9 @@ {{ ansible_managed | comment }} {% for microsoft_repository_dir in microsoft_repository_dirs_list %} -{% if microsoft_repository_dir.type is defined and microsoft_repository_dir.type == 'alternate' %} -deb [arch=amd64,arm64,armhf] {{ microsoft_repository_mirror }}/repos/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main +{% if microsoft_repository_dir.type is defined and microsoft_repository_dir.type == 'alternative' %} +deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] {{ _microsoft_repository_alternative_mirror_url }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main {% else %} -deb [arch=amd64,arm64,armhf] {{ _microsoft_repository_baseurl }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main +deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] {{ _microsoft_repository_base_mirror_url }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main {% endif %} {% endfor %} \ No newline at end of file diff --git a/templates/microsoft.repo.j2 b/templates/microsoft.repo.j2 index 22ded50..ed7e278 100644 --- a/templates/microsoft.repo.j2 +++ b/templates/microsoft.repo.j2 @@ -2,14 +2,14 @@ {% 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 == 'alternate' %} -baseurl = {{ microsoft_repository_mirror }}/yumrepos/{{ 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 }} {% else %} -baseurl = {{ _microsoft_repository_baseurl }}/{{ microsoft_repository_dir.name }} +baseurl = {{ _microsoft_repository_base_mirror_url }}/{{ microsoft_repository_dir.name }} {% endif %} enabled = 1 gpgcheck = 1 -gpgkey = {{ microsoft_repository_key_url }} +gpgkey = {{ microsoft_repository_gpgkey }} name = packages-microsoft-com-{{ microsoft_repository_dir.name }} {% endfor %} \ No newline at end of file diff --git a/vars/Debian.yml b/vars/Debian.yml index 72bb85b..fe8fa9b 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,2 +1,3 @@ --- -_microsoft_repository_baseurl: '{{ microsoft_repository_mirror }}/{{ ansible_distribution | lower }}/{{ ansible_distribution_major_version }}' +_microsoft_repository_base_mirror_url: '{{ microsoft_repository_mirror_url }}/{{ ansible_distribution | lower }}/{{ ansible_distribution_major_version }}' +_microsoft_repository_alternative_mirror_url: '{{ microsoft_repository_mirror_url }}/repos' diff --git a/vars/RedHat.yml b/vars/RedHat.yml index 87c513b..981c475 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,2 +1,3 @@ --- -_microsoft_repository_baseurl: '{{ microsoft_repository_mirror }}/rhel/{{ ansible_distribution_major_version }}' +_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/Ubuntu.yml b/vars/Ubuntu.yml index 3e4fb67..d08ab61 100644 --- a/vars/Ubuntu.yml +++ b/vars/Ubuntu.yml @@ -1,2 +1,3 @@ --- -_microsoft_repository_baseurl: '{{ microsoft_repository_mirror }}/{{ ansible_distribution | lower }}/{{ ansible_distribution_version }}' +_microsoft_repository_base_mirror_url: '{{ microsoft_repository_mirror_url }}/{{ ansible_distribution | lower }}/{{ ansible_distribution_version }}' +_microsoft_repository_alternative_mirror_url: '{{ microsoft_repository_mirror_url }}/repos'