Skip to content

Commit

Permalink
improv!: update variables (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
antmelekhin authored Sep 13, 2024
1 parent a2ee73b commit 37d493a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 38 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Microsoft Repository

An Ansible role that adds the [Microsoft repository](https://packages.microsoft.com) to Linux distributions and installs packages from it.

Upgrade to 2.x
--------------

Since version 2.0.0, the variable `microsoft_repository_dirs_list` has changed to `microsoft_repository_enable_prod_repository` and `microsoft_repository_additional_directories`.

Requirements
------------

Expand Down Expand Up @@ -56,8 +61,8 @@ Add the `Microsoft Prod` repository and install `dotnet-sdk-3.1` and `powershell
roles:
- role: antmelekhin.microsoft_repository
microsoft_repository_packages:
- dotnet-sdk-3.1
- powershell
- 'dotnet-sdk-3.1'
- 'powershell'
```

Add the `Microsoft Azure CLI` repository and install the azure-cli package:
Expand All @@ -69,11 +74,10 @@ Add the `Microsoft Azure CLI` repository and install the azure-cli package:
roles:
- role: antmelekhin.microsoft_repository
microsoft_repository_dirs_list:
- name: azure-cli
type: alternative
microsoft_repository_additional_directories:
- 'azure-cli'
microsoft_repository_packages:
- azure-cli
- 'azure-cli'
```

License
Expand Down
6 changes: 2 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
microsoft_repository_mirror_url: 'https://packages.microsoft.com'
microsoft_repository_gpgkey_url: '{{ microsoft_repository_mirror_url }}/keys/microsoft.asc'

microsoft_repository_dirs_list:
- name: 'prod'

microsoft_repository_enable_prod_repository: true
microsoft_repository_additional_directories: []
microsoft_repository_packages: []
8 changes: 6 additions & 2 deletions meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ argument_specs:
- 'Specify where to fetch the Microsoft repository GPG key file from.'
- 'By default, the role uses the official Microsoft repository GPG key.'
default: '{{ microsoft_repository_mirror_url }}/keys/microsoft.asc'
microsoft_repository_dirs_list:
microsoft_repository_enable_prod_repository:
type: 'bool'
description: 'Specifies whether prod repository is enabled.'
default: true
microsoft_repository_additional_directories:
type: 'list'
elements: 'dict'
elements: 'str'
description: 'A list of repository directories.'
microsoft_repository_packages:
type: 'list'
Expand Down
6 changes: 2 additions & 4 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
hosts: all
roles:
- role: antmelekhin.microsoft_repository
microsoft_repository_dirs_list:
- name: 'prod'
- name: 'azure-cli'
type: 'alternative'
microsoft_repository_additional_directories:
- 'azure-cli'
microsoft_repository_packages:
- 'powershell'
- 'azure-cli'
9 changes: 4 additions & 5 deletions templates/microsoft.list.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{ ansible_managed | comment }}

{% 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_gpgkey_keyring }}] {{ __microsoft_repository_alternative }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main
{% else %}
deb [arch=amd64,arm64,armhf signed-by={{ __microsoft_repository_gpgkey_keyring }}] {{ __microsoft_repository_base }}/{{ microsoft_repository_dir.name }} {{ ansible_distribution_release }} main
{% if microsoft_repository_enable_prod_repository | bool %}
deb [arch=amd64,arm64,armhf signed-by={{ __microsoft_repository_gpgkey_keyring }}] {{ __microsoft_repository_prod_repository }}
{% endif %}
{% for microsoft_repository_additional_directory in microsoft_repository_additional_directories %}
deb [arch=amd64,arm64,armhf signed-by={{ __microsoft_repository_gpgkey_keyring }}] {{ microsoft_repository_mirror_url }}/repos/{{ microsoft_repository_additional_directory }} {{ ansible_distribution_release }} main
{% endfor %}
19 changes: 12 additions & 7 deletions templates/microsoft.repo.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{{ ansible_managed | comment }}

{% 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 }}/{{ microsoft_repository_dir.name }}
{% else %}
baseurl = {{ __microsoft_repository_base }}/{{ microsoft_repository_dir.name }}
{% if microsoft_repository_enable_prod_repository | bool %}
[packages-microsoft-com-prod]
name = packages-microsoft-com-prod
baseurl = {{ __microsoft_repository_prod_repository }}
enabled = 1
gpgcheck = 1
gpgkey = {{ microsoft_repository_gpgkey_url }}
{% endif %}

{% for microsoft_repository_additional_directory in microsoft_repository_additional_directories %}
[{{ microsoft_repository_additional_directory }}]
name = {{ microsoft_repository_additional_directory }}
baseurl = {{ microsoft_repository_mirror_url }}/yumrepos/{{ microsoft_repository_additional_directory }}
enabled = 1
gpgcheck = 1
gpgkey = {{ microsoft_repository_gpgkey_url }}
name = packages-microsoft-com-{{ microsoft_repository_dir.name }}

{% endfor %}
14 changes: 4 additions & 10 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
---
__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_prod_repository_dict:
Debian: "{{ microsoft_repository_mirror_url }}/{{ ansible_distribution | lower }}/{{ (ansible_distribution == 'Ubuntu') | ternary(ansible_distribution_version, ansible_distribution_major_version) }}/prod {{ ansible_distribution_release }} main"
RedHat: '{{ microsoft_repository_mirror_url }}/rhel/{{ ansible_distribution_major_version }}/prod'

__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] }}'
__microsoft_repository_prod_repository: '{{ __microsoft_repository_prod_repository_dict[ansible_os_family] }}'

0 comments on commit 37d493a

Please sign in to comment.