constrict0r.jsnode
jsnode
.. image:: https://gitlab.com/constrict0r/jsnode/badges/master/pipeline.svg :alt: pipeline
.. image:: https://travis-ci.com/constrict0r/jsnode.svg :alt: travis
.. image:: https://readthedocs.org/projects/jsnode/badge :alt: readthedocs
Ansible role to use as a wrapper for Yarn <https://yarnpkg.com/>_ to
install nodejs packages.
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/avatar.png :alt: avatar
Full documentation on Readthedocs <https://jsnode.readthedocs.io>_.
Source code on:
Github <https://github.com/constrict0r/jsnode>_.
Gitlab <https://gitlab.com/constrict0r/jsnode>_.
Part of: <https://gitlab.com/explore/projects?tag=doombot>_
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/doombot.png :alt: doombot
Ingredients
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/ingredient.png :alt: ingredient
Contents
Description <#Description>_Usage <#Usage>_Variables <#Variables>_packages_js <#packages-js>_configuration <#configuration>_
YAML <#YAML>_Attributes <#Attributes>_item_expand <#item-expand>_item_path <#item-path>_
Requirements <#Requirements>_Compatibility <#Compatibility>_Limitations <#Limitations>_License <#License>_Links <#Links>_UML <#UML>_Deployment <#deployment>_Main <#main>_
Author <#Author>_
Description
Ansible role to use as a wrapper for yarn <https://yarnpkg.com/>_ to
install nodejs packages.
This role performs the following actions:
Ensure the requirements are installed.
Ensure the current user can obtain administrative (root) permissions.
If not already added, add the nodejs repository to the apt sources.
If not installed, install nodejs.
If the packages_js variable is defined, install the javascript packages listed on it.
If the configuration variable is defined, install the javascript packages listed on it.
Usage
- To install and execute:
..
::
ansible-galaxy install constrict0r.jsnode
ansible localhost -m include_role -a name=constrict0r.jsnode -K
- Passing variables:
..
::
ansible localhost -m include_role -a name=constrict0r.jsnode -K \
-e "{packages_js: [node-red, {name: requests, version: 2.22.0}]}"
- To include the role on a playbook:
..
::
- hosts: servers
roles:
- {role: constrict0r.jsnode}
- To include the role as dependency on another role:
..
::
dependencies:
- role: constrict0r.jsnode
packages_js: [node-red, {name: requests, version: 2.22.0}]
- To use the role from tasks:
..
::
- name: Execute role task.
import_role:
name: constrict0r.jsnode
vars:
packages_js: [node-red, {name: requests, version: 2.22.0}]
To run tests:
::
cd jsnode chmod +x testme.sh ./testme.sh
On some tests you may need to use sudo to succeed.
Variables
The following variables are supported:
packages_js
List of packages to install via yarn.
This list can be modified by passing a packages_js array when including the role on a playbook or via –extra-vars from a terminal.
If you want to install a specific package version, then specify name and version attributes for the package.
This variable is empty by default.
::
Including from terminal.
ansible localhost -m include_role -a name=constrict0r.jsnode -K -e
"{packages_js: [node-red, {name: requests, version: 2.22.0}]}"
Including on a playbook.
- hosts: servers
roles:
- role: constrict0r.jsnode
packages_js:
- node-red
- name: requests version: 2.22.0
- role: constrict0r.jsnode
packages_js:
To a playbook from terminal.
ansible-playbook -i inventory my-playbook.yml -K -e
"{packages_js: [node-red, {name: requests, version: 2.22.0}]}"
configuration
Absolute file path or URL to a .yml file that contains all or some of the variables supported by this role.
It is recommended to use a .yml or .yaml extension for the configuration file.
This variable is empty by default.
::
Using file path.
ansible localhost -m include_role -a name=constrict0r.jsnode -K -e
"configuration=/home/username/my-config.yml"
Using URL.
ansible localhost -m include_role -a name=constrict0r.jsnode -K -e
"configuration=https://my-url/my-config.yml"
To see how to write a configuration file see the YAML file format section.
YAML
When passing configuration files to this role as parameters, it’s recommended to add a .yml or .yaml extension to the each file.
It is also recommended to add three dashes at the top of each file:
::
You can include in the file the variables required for your tasks:
::
packages_js: - [node-red, {name: requests, version: 2.22.0}]
If you want this role to load list of items from files and URLs you can set the expand variable to true:
::
packages_js: /home/username/my-config.yml
expand: true
If the expand variable is false, any file path or URL found will be treated like plain text.
Attributes
On the item level you can use attributes to configure how this role handles the items data.
The attributes supported by this role are:
item_expand
Boolean value indicating if treat this item as a file path or URL or just treat it as plain text.
::
packages_js: - item_expand: true item_path: /home/username/my-config.yml
item_path
Absolute file path or URL to a .yml file.
::
packages_js: - item_path: /home/username/my-config.yml
This attribute also works with URLs.
Requirements
Ansible <https://www.ansible.com>_ >= 2.8.Jinja2 <https://palletsprojects.com/p/jinja/>_.Pip <https://pypi.org/project/pip/>_.Python <https://www.python.org/>_.PyYAML <https://pyyaml.org/>_.Requests <https://2.python-requests.org/en/master/>_.
If you want to run the tests, you will also need:
Docker <https://www.docker.com/>_.Molecule <https://molecule.readthedocs.io/>_.Setuptools <https://pypi.org/project/setuptools/>_.
Compatibility
Debian Buster <https://wiki.debian.org/DebianBuster>_.Debian Raspbian <https://raspbian.org/>_.Debian Stretch <https://wiki.debian.org/DebianStretch>_.Ubuntu Xenial <http://releases.ubuntu.com/16.04/>_.
Limitations
This role uses the latests nodejs Active LTS version, this works well on most cases.
The packages are installed globally.
License
MIT. See the LICENSE file for more details.
Links
Github <https://github.com/constrict0r/jsnode>_.Gitlab <https://gitlab.com/constrict0r/jsnode>_.Gitlab CI <https://gitlab.com/constrict0r/jsnode/pipelines>_.Readthedocs <https://jsnode.readthedocs.io>_.Travis CI <https://travis-ci.com/constrict0r/jsnode>_.
UML
Deployment
The full project structure is shown below:
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/deploy.png :alt: deploy
Main
The project data flow is shown below:
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/main.png :alt: main
Author
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/author.png :alt: author
The Travelling Vaudeville Villain.
Enjoy!!!
.. image:: https://gitlab.com/constrict0r/img/raw/master/jsnode/enjoy.png :alt: enjoy
Wrapper for Yarn to install packages.
ansible-galaxy install constrict0r.jsnode