Last active
April 7, 2024 13:13
-
-
Save ninjarobot/16484d0d524c5d1e48dedf2e086a932d to your computer and use it in GitHub Desktop.
Ansible playbook to install the .NET Core SDK on an Ubuntu server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
tasks: | |
- name: Download MS product repository | |
get_url: | |
url: https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb | |
dest: /tmp/packages-microsoft-prod.deb | |
- name: Install MS product repository | |
apt: deb=/tmp/packages-microsoft-prod.deb | |
become: true | |
- name: Make sure HTTPS is supported by apt | |
apt: | |
name: apt-transport-https | |
state: present | |
update_cache: no | |
become: true | |
- name: Install .NET Core SDK | |
apt: | |
name: dotnet-sdk-2.2 | |
state: present | |
update_cache: yes | |
become: true |
There's a PPA for it as well if you prefer that to managing pip-installed versions: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Thanks @baronfel, but I'm virtualenv
all the way :)
Oh duh, I completely skipped past the virtualenv :)
Alternatively install .NET with install-dotnet script.
#https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install
---
- hosts: all
vars:
dotnet_runtime: dotnet
dotnet_channel: 6.0
dotnet_script_path: /tmp
dotnet_installation_path: /home/jashu-local-001
dotnet_dependencies:
- libc6
- libgcc1
- libgssapi-krb5-2
- libicu66
- libssl1.1
- libstdc++6
- zlib1g
tasks:
- name : Make sure HTTPS is supported by apt
apt:
name: apt-transport-https
state: latest
update_cache: yes
become: yes
- name: Install dotnet dependencies #https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-2004#dependencies
apt:
name: "{{ dotnet_dependencies }}"
state: latest
update_cache: yes
become: yes
- name: Download MS dotnet-install script
get_url:
url: https://dot.net/v1/dotnet-install.sh
dest: "{{ dotnet_script_path }}/dotnet-install.sh"
force: true
- name: Make dotnet-install script executable
ansible.builtin.command: chmod +x "{{ dotnet_script_path }}/dotnet-install.sh"
become_user: yes
- name: Install dotnet
ansible.builtin.shell:
cmd: "{{ dotnet_script_path }}/dotnet-install.sh --channel {{ dotnet_channel }} --runtime {{ dotnet_runtime }}"
chdir: "{{ dotnet_installation_path }}"
- name: Cleanup dotnet-install files
ansible.builtin.file:
path: "{{ dotnet_script_path }}/dotnet-install.sh"
state: absent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From a bare system, to get ansible on the controller machine (in a virtualenv so as not to pollute things):