Import the old role. Add support for EL distribution.

This commit is contained in:
Andrea Dell'Amico 2020-08-22 17:54:58 +02:00
parent cc026030ec
commit 22fcca2e1a
7 changed files with 118 additions and 68 deletions

View File

@ -1,31 +1,22 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
A role that installs node.js and, optionally, yarn. <https://nodejs.org/>
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
The most important variables are listed below:
``` yaml
node_js_repo_version: 12
node_js_yarn_install: False
```
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
None
License
-------
@ -35,4 +26,4 @@ EUPL-1.2
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Andrea Dell'Amico, <andrea.dellamico@isti.cnr.it>

View File

@ -1,2 +1,11 @@
---
# defaults file for ansible-role-template
# Latest LTS
node_js_repo_version: 12
node_js_pkgs:
- nodejs
node_js_pkg_state: present
node_js_yarn_install: False
node_js_yarn_pkgs:
- yarn

View File

@ -1,61 +1,28 @@
galaxy_info:
author: your name
description: your description
author: Andrea Dell'Amico
description: Systems Architect
company: ISTI-CNR
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: EUPL-1.2
license: EUPL 1.2+
min_ansible_version: 2.8
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
platforms:
- name: Ubuntu
versions:
- bionic
- name: EL
versions:
- 7
- 8
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
galaxy_tags:
- node.js
- yarn
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@ -1,2 +1,6 @@
---
# tasks file for ansible-role-template
- import_tasks: nodejs_deb.yml
when: ansible_distribution_file_variety == "Debian"
- import_tasks: nodejs_el.yml
when: ansible_distribution_file_variety == "RedHat"

38
tasks/nodejs_deb.yml Normal file
View File

@ -0,0 +1,38 @@
---
- block:
- name: Install the Node.js repository key
apt_key: url={{ node_js_deb_repo_key }} state=present
- name: Install the Node.js repository configuration
apt_repository: repo={{ item }} state=present update_cache=True
with_items: '{{ node_js_deb_repo_urls }}'
- name: Install the Node.js packages
apt: pkg={{ node_js_pkgs }} state={{ node_js_pkg_state }} cache_valid_time=1800
tags: [ 'nodejs', 'node_js' ]
- block:
- name: Install the Node.js yarn repository key
apt_key: url={{ node_js_yarn_deb_repo_key }} state=present
- name: Install the Node.js yarn repository configuration
apt_repository: repo={{ item }} state=present update_cache=True
with_items: '{{ node_js_yarn_deb_repo_urls }}'
- name: Install the Node.js yarn packages
apt: pkg={{ node_js_yarn_pkgs }} state={{ node_js_pkg_state }} cache_valid_time=1800
when: node_js_yarn_install
tags: [ 'nodejs', 'node_js', 'yarn', 'node_js_yarn' ]
- block:
- name: Remove the Node.js yarn packages
apt: pkg={{ node_js_yarn_pkgs }} state=absent
- name: Remove the Node.js yarn repository configuration
apt_repository: repo={{ item }} state=absent update_cache=True
with_items: '{{ node_js_yarn_deb_repo_urls }}'
when: not node_js_yarn_install
tags: [ 'nodejs', 'node_js', 'yarn', 'node_js_yarn' ]

29
tasks/nodejs_el.yml Normal file
View File

@ -0,0 +1,29 @@
---
- block:
- name: Install the Node.js repository package
package: name={{ node_js_el_repo_pkg }} state=present
- name: Install the Node.js packages
package: name={{ node_js_pkgs }} state={{ node_js_pkg_state }}
tags: [ 'nodejs', 'node_js' ]
- block:
- name: Install the Node.js yarn repository configuration
get_url: url={{ node_js_yarn_el_repo_url }} dest=/etc/yum.repos.d/yarn.repo
- name: Install the Node.js yarn packages
package: name={{ node_js_yarn_pkgs }} state={{ node_js_pkg_state }}
when: node_js_yarn_install
tags: [ 'nodejs', 'node_js', 'yarn', 'node_js_yarn' ]
- block:
- name: Remove the Node.js yarn packages
package: name={{ node_js_yarn_pkgs }} state=absent
- name: Remove the Node.js yarn repository configuration
file: dest=/etc/yum.repos.d/yarn.repo state=absent
when: not node_js_yarn_install
tags: [ 'nodejs', 'node_js', 'yarn', 'node_js_yarn' ]

View File

@ -1,2 +1,14 @@
---
# vars file for ansible-role-template
node_js_repo_name: 'node_{{ node_js_repo_version }}.x'
node_js_deb_repo_key: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
node_js_deb_repo_urls:
- 'deb https://deb.nodesource.com/{{ node_js_repo_name }} {{ ansible_distribution_release }} main'
- 'deb-src https://deb.nodesource.com/{{ node_js_repo_name }} {{ ansible_distribution_release }} main'
node_js_el_repo_pkg: 'https://rpm.nodesource.com/pub_{{ node_js_repo_version }}.x/el/{{ ansible_distribution_major_version }}/x86_64/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm'
node_js_yarn_deb_repo_key: https://dl.yarnpkg.com/debian/pubkey.gpg
node_js_yarn_deb_repo_urls:
- 'deb https://dl.yarnpkg.com/debian/ stable main'
node_js_yarn_el_repo_url: 'https://dl.yarnpkg.com/rpm/yarn.repo'