From c07a4980e63892f83737522f0901b630cd50d244 Mon Sep 17 00:00:00 2001 From: Adrien Date: Mon, 6 Apr 2020 00:01:40 +0200 Subject: [PATCH] Update for CentOS 8 and tags --- defaults/main.yml | 2 ++ tasks/add_repo_Debian.yml | 3 +-- tasks/add_repo_RedHat.yml | 2 +- tasks/install.yml | 6 ++++++ tasks/main.yml | 25 +++++++++++++++++++------ tasks/uninstall.yml | 26 ++++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 defaults/main.yml create mode 100644 tasks/install.yml create mode 100644 tasks/uninstall.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..425bdf1 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +powershell_uninstall: false diff --git a/tasks/add_repo_Debian.yml b/tasks/add_repo_Debian.yml index c1c45f9..0a6ccd3 100644 --- a/tasks/add_repo_Debian.yml +++ b/tasks/add_repo_Debian.yml @@ -24,5 +24,4 @@ - name: Install public repository GPG keys apt_key: url: /etc/apt/sources.list.d/microsoft.list - state: - + state: present diff --git a/tasks/add_repo_RedHat.yml b/tasks/add_repo_RedHat.yml index 82cffde..ae51d4f 100644 --- a/tasks/add_repo_RedHat.yml +++ b/tasks/add_repo_RedHat.yml @@ -1,7 +1,7 @@ --- - name: Registering Powershell repository get_url: - url: https://packages.microsoft.com/config/rhel/7/prod.repo + url: https://packages.microsoft.com/config/rhel/{{ ansible_distribution_major_version }}/prod.repo dest: /etc/yum.repos.d/microsoft.repo owner: root group: root diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..6b087d1 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,6 @@ +--- +- name: Define repo for {{ ansible_os_family }} + include_tasks: add_repo_{{ ansible_os_family }}.yml + +- name: Install packages + package: name='{{ powershell_packages }}' state=latest update_cache=yes diff --git a/tasks/main.yml b/tasks/main.yml index 7c3887b..c97cd44 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,23 @@ --- -- name: Include vars for {{ ansible_os_family }} - include_vars: "{{ ansible_os_family }}.yml" +- block: + - name: Include vars for {{ ansible_os_family }} + include_vars: "{{ ansible_os_family }}.yml" + tags: + - config -- name: Define repo for {{ ansible_os_family }} - include_tasks: add_repo_{{ ansible_os_family }}.yml + - name: Install PowerShell + include_tasks: "install.yml" + when: + - not powershell_uninstall|bool + tags: + - install -- name: Install packages - package: name='{{ powershell_packages }}' state=latest update_cache=yes + - name: Uninstall PowerShell + include_tasks: "uninstall.yml" + when: + - powershell_uninstall|bool + tags: + - uninstall + tags: + - powershell \ No newline at end of file diff --git a/tasks/uninstall.yml b/tasks/uninstall.yml new file mode 100644 index 0000000..0464fdc --- /dev/null +++ b/tasks/uninstall.yml @@ -0,0 +1,26 @@ +--- + - name: Remove PowerShell's files + file: + path: "/etc/yum.repos.d/microsoft.repo" + state: absent + when: + - ansible_os_family == 'RedHat' + + - name: Registering Ubuntu PowerShell repository + file: + path: "/etc/apt/sources.list.d/microsoft.list" + state: absent + when: + - ansible_distribution == "Ubuntu" + + - name: Registering Debian AnsiPowerShellble repository + apt_repository: + repo: deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-{{ ansible_distribution_name }}-prod {{ ansible_distribution_name }} main + filename: microsoft.list + state: absent + update_cache: yes + when: + - ansible_distribution == "Debian" + + - name: Remove AnsiPowerShellble's packages + package: name='{{ powershell_packages }}' state=absent update_cache=yes