From 7cb1c6b16b469f44dae342d1e66861199b927aff Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Sat, 4 Apr 2020 15:56:40 -0400 Subject: [PATCH] ensure-yarn: refactor to use ensure-package-repositories This patch refactors ensure-yarn to use the new generic role to allow it to be cross-platform in the future. Change-Id: I32bb40f5afb26d0d906f332c1c8440859367d97a --- roles/ensure-yarn/tasks/Debian.yaml | 14 -------------- roles/ensure-yarn/tasks/RedHat.yaml | 8 -------- roles/ensure-yarn/tasks/main.yaml | 28 ++++++++++++++++++++++++---- roles/ensure-yarn/vars/debian.yaml | 4 ++++ roles/ensure-yarn/vars/redhat.yaml | 6 ++++++ 5 files changed, 34 insertions(+), 26 deletions(-) delete mode 100644 roles/ensure-yarn/tasks/Debian.yaml delete mode 100644 roles/ensure-yarn/tasks/RedHat.yaml create mode 100644 roles/ensure-yarn/vars/debian.yaml create mode 100644 roles/ensure-yarn/vars/redhat.yaml diff --git a/roles/ensure-yarn/tasks/Debian.yaml b/roles/ensure-yarn/tasks/Debian.yaml deleted file mode 100644 index 3559acfd5..000000000 --- a/roles/ensure-yarn/tasks/Debian.yaml +++ /dev/null @@ -1,14 +0,0 @@ -- name: Add yarnpkg repository key - apt_key: - url: https://dl.yarnpkg.com/debian/pubkey.gpg - become: yes - -- name: Add yarnpkg apt source repository - apt_repository: - repo: "deb https://dl.yarnpkg.com/debian/ stable main" - state: present - update_cache: yes - become: yes - -- name: Install yarn - include: yarn.yaml diff --git a/roles/ensure-yarn/tasks/RedHat.yaml b/roles/ensure-yarn/tasks/RedHat.yaml deleted file mode 100644 index 8065b7fdf..000000000 --- a/roles/ensure-yarn/tasks/RedHat.yaml +++ /dev/null @@ -1,8 +0,0 @@ -- name: Add yarnpkg repo file - get_url: - url: https://dl.yarnpkg.com/rpm/yarn.repo - dest: /etc/yum.repos.d/yarn.repo - become: yes - -- name: Install yarn - include: yarn.yaml diff --git a/roles/ensure-yarn/tasks/main.yaml b/roles/ensure-yarn/tasks/main.yaml index 508aedef3..70beafd19 100644 --- a/roles/ensure-yarn/tasks/main.yaml +++ b/roles/ensure-yarn/tasks/main.yaml @@ -1,3 +1,26 @@ +- name: Gather variables for each operating system + include_vars: "{{ zj_item }}" + with_first_found: + - skip: true + files: + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yaml" + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yaml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yaml" + - "{{ ansible_distribution | lower }}.yaml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yaml" + - "{{ ansible_os_family | lower }}.yaml" + loop_control: + loop_var: zj_item + tags: + - always + +- name: Add all repositories + include_role: + name: ensure-package-repositories + vars: + repositories_keys: "{{ _yarn_keys | default([]) }}" + repositories_list: "{{ _yarn_repos | default([]) }}" + - name: Check for yarn.lock file stat: path: "{{ yarn_lock_file_path }}" @@ -7,9 +30,6 @@ register: yarn_lock - name: Install yarn if needed - include: "{{ item }}" - with_first_found: - - "{{ ansible_distribution }}.yaml" - - "{{ ansible_os_family }}.yaml" + include: yarn.yaml when: - yarn_lock.stat.exists diff --git a/roles/ensure-yarn/vars/debian.yaml b/roles/ensure-yarn/vars/debian.yaml new file mode 100644 index 000000000..b13a10da5 --- /dev/null +++ b/roles/ensure-yarn/vars/debian.yaml @@ -0,0 +1,4 @@ +_yarn_keys: + - url: https://dl.yarnpkg.com/debian/pubkey.gpg +_yarn_repos: + - repo: deb https://dl.yarnpkg.com/debian/ stable main diff --git a/roles/ensure-yarn/vars/redhat.yaml b/roles/ensure-yarn/vars/redhat.yaml new file mode 100644 index 000000000..1e4532969 --- /dev/null +++ b/roles/ensure-yarn/vars/redhat.yaml @@ -0,0 +1,6 @@ +_yarn_repos: + - name: yarn + description: Yarn Repository + baseurl: https://dl.yarnpkg.com/rpm/ + gpgcheck: yes + gpgkey: https://dl.yarnpkg.com/rpm/pubkey.gpg