From 31e75cfc40a3045f2045f49a92c54ae700f74f39 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Sun, 23 Feb 2020 01:05:57 +0000 Subject: [PATCH] Added Mirror support (#173) If you want to use a mirror server, then with this you can override the server protocol and URL, e.g. on the command line by using ansible extra-vars. Adding leading directories is possible if needed, but no trailing slash should be used. The default-key for this feature has that form: ```yaml visual_studio_code_mirror: "https://packages.microsoft.com" ``` --- README.md | 5 +++++ defaults/main.yml | 5 +++++ tasks/install-apt.yml | 4 ++-- tasks/install-dnf.yml | 4 ++-- tasks/install-yum.yml | 4 ++-- tasks/install-zypper.yml | 2 +- templates/vscode.repo.j2 | 4 ++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2a4113b..232aafb 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,11 @@ visual_studio_code_version: '' # Ubuntu only (code-insiders isn't in Microsoft's RPM repo) visual_studio_code_build: stable +# Mirror server for fetching the public keys and the Visual Studio Code +# installation package. The URL may include directories. The URL must not end +# with a trailing slash. +visual_studio_code_mirror: 'https://packages.microsoft.com' + # Users to install extensions for and/or write settings.json users: [] ``` diff --git a/defaults/main.yml b/defaults/main.yml index e62dbd2..f20d05b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,5 +9,10 @@ visual_studio_code_build: stable # Directory to store files downloaded for Visual Studio Code installation visual_studio_code_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}" +# Mirror server for fetching the public keys and the Visual Studio Code +# installation package. The URL may include directories. The URL must not end +# with a trailing slash. +visual_studio_code_mirror: 'https://packages.microsoft.com' + # Users to install extensions for and/or write settings.json users: [] diff --git a/tasks/install-apt.yml b/tasks/install-apt.yml index 28ccd55..e35eb27 100644 --- a/tasks/install-apt.yml +++ b/tasks/install-apt.yml @@ -14,13 +14,13 @@ - name: install key (apt) become: yes apt_key: - url: 'https://packages.microsoft.com/keys/microsoft.asc' + url: '{{ visual_studio_code_mirror }}/keys/microsoft.asc' state: present - name: install VS Code repo (apt) become: yes apt_repository: - repo: deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main + repo: 'deb [arch=amd64] {{ visual_studio_code_mirror }}/repos/vscode stable main' filename: vscode state: present diff --git a/tasks/install-dnf.yml b/tasks/install-dnf.yml index d76dc9b..af343ae 100644 --- a/tasks/install-dnf.yml +++ b/tasks/install-dnf.yml @@ -13,8 +13,8 @@ name: code description: Visual Studio Code repo file: vscode - baseurl: https://packages.microsoft.com/yumrepos/vscode - gpgkey: https://packages.microsoft.com/keys/microsoft.asc + baseurl: '{{ visual_studio_code_mirror }}/yumrepos/vscode' + gpgkey: '{{ visual_studio_code_mirror }}/keys/microsoft.asc' gpgcheck: yes - name: install VS Code (dnf) diff --git a/tasks/install-yum.yml b/tasks/install-yum.yml index f229f94..5e8cea1 100644 --- a/tasks/install-yum.yml +++ b/tasks/install-yum.yml @@ -11,8 +11,8 @@ name: code description: Visual Studio Code repo file: vscode - baseurl: https://packages.microsoft.com/yumrepos/vscode - gpgkey: https://packages.microsoft.com/keys/microsoft.asc + baseurl: '{{ visual_studio_code_mirror }}/yumrepos/vscode' + gpgkey: '{{ visual_studio_code_mirror }}/keys/microsoft.asc' gpgcheck: yes - name: install VS Code (yum) diff --git a/tasks/install-zypper.yml b/tasks/install-zypper.yml index 430040b..09207dc 100644 --- a/tasks/install-zypper.yml +++ b/tasks/install-zypper.yml @@ -9,7 +9,7 @@ become: yes rpm_key: state: present - key: https://packages.microsoft.com/keys/microsoft.asc + key: '{{ visual_studio_code_mirror }}/keys/microsoft.asc' - name: write repo configuration (zypper) become: yes diff --git a/templates/vscode.repo.j2 b/templates/vscode.repo.j2 index c70da0a..9cee331 100644 --- a/templates/vscode.repo.j2 +++ b/templates/vscode.repo.j2 @@ -1,8 +1,8 @@ {{ ansible_managed | comment }} [code] name=Visual Studio Code -baseurl=https://packages.microsoft.com/yumrepos/vscode +baseurl={{ visual_studio_code_mirror }}/yumrepos/vscode enabled=1 type=rpm-md gpgcheck=1 -gpgkey=https://packages.microsoft.com/keys/microsoft.asc +gpgkey={{ visual_studio_code_mirror }}/keys/microsoft.asc