Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improv: merge OS-specific variables into the vars/main.yml file #17

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tasks/install-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
- '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:
url: '{{ microsoft_repository_gpgkey_url }}'
keyring: '{{ _microsoft_repository_local_gpgkey_path }}'
keyring: '{{ __microsoft_repository_gpgkey_keyring }}'
state: 'present'

- name: 'Debian | Add the Microsoft repository'
Expand All @@ -31,4 +32,4 @@
name: '{{ microsoft_repository_packages }}'
update_cache: true
state: 'present'
when: not ansible_check_mode
ignore_errors: '{{ ansible_check_mode }}'
6 changes: 4 additions & 2 deletions tasks/install-RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,4 +21,4 @@
ansible.builtin.package:
name: '{{ microsoft_repository_packages }}'
state: 'present'
when: not ansible_check_mode
ignore_errors: '{{ ansible_check_mode }}'
3 changes: 0 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 2 additions & 2 deletions templates/microsoft.list.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
4 changes: 2 additions & 2 deletions templates/microsoft.repo.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions vars/Debian.yml

This file was deleted.

3 changes: 0 additions & 3 deletions vars/RedHat.yml

This file was deleted.

14 changes: 14 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -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] }}'