From ecdde55933a7b3aca72859945cae7ec363436fd0 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Tue, 29 Aug 2017 18:45:30 +0300
Subject: [PATCH] - Forked from the example role. - Seems done.

---
 .travis.yml          |  3 ---
 README.rst           | 10 ++++------
 defaults/main.yml    |  4 +++-
 handlers/main.yml    |  2 +-
 meta/main.yml        |  9 ++-------
 molecule.yml         |  2 +-
 tasks/main.yml       | 33 ++++++++++++++++++++++++++++++---
 tests/playbook.yml   |  6 +++---
 tests/test_nodejs.py | 12 ++++++++++++
 tox.ini              |  2 +-
 vars/main.yml        |  2 +-
 11 files changed, 58 insertions(+), 27 deletions(-)
 create mode 100644 tests/test_nodejs.py

diff --git a/.travis.yml b/.travis.yml
index f8d9b4c..f89e093 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,13 +9,10 @@ env:
         - VBOX_MEMORY=2048
         - VBOX_HWVIRTEX=off
     matrix:
-        - TOXENV=openbsd60
         - TOXENV=xenial
         - TOXENV=trusty
-        - TOXENV=precise
         - &stretch TOXENV=stretch
         - &jessie TOXENV=jessie
-        - TOXENV=wheezy
 
 cache:
   - pip
diff --git a/README.rst b/README.rst
index d50fb09..f3ecfc6 100644
--- a/README.rst
+++ b/README.rst
@@ -1,12 +1,10 @@
-Example
+Node.js
 #######
 
-.. image:: https://travis-ci.org/adarnimrod/example.svg?branch=master
-    :target: https://travis-ci.org/adarnimrod/example
+.. image:: https://travis-ci.org/adarnimrod/nodejs.svg?branch=master
+    :target: https://travis-ci.org/adarnimrod/nodejs
 
-An (empty) example Ansible role complete with working tests out of the box. For
-more information read the `blog post
-<https://www.shore.co.il/blog/ansible-example-role/>`_.
+Install Node.js on Debian or Ubuntu from packages in NodeSource' repository.
 
 Requirements
 ------------
diff --git a/defaults/main.yml b/defaults/main.yml
index 0a97962..a5a9974 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,2 +1,4 @@
 ---
-# defaults file for example
+# defaults file for nodejs
+
+nodejs_version: 8 # or 6.
diff --git a/handlers/main.yml b/handlers/main.yml
index bd0df0d..7c65bbd 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -1,2 +1,2 @@
 ---
-# handlers file for example
+# handlers file for nodejs
diff --git a/meta/main.yml b/meta/main.yml
index d768011..e3c47ed 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -1,22 +1,17 @@
 galaxy_info:
   author: Nimrod Adar
-  description: An example Ansible role
+  description: Install Node.js on Debian or Ubuntu from packages in NodeSource' repository
   company: Shore technologies
   license: MIT
   min_ansible_version: 2.3
   platforms:
-  - name: OpenBSD
-    versions:
-    - 6.0
   - name: Ubuntu
     versions:
     - xenial
     - trusty
-    - precise
   - name: Debian
     versions:
     - stretch
     - jessie
-    - wheezy
-  galaxy_tags: [ ansible ]
+  galaxy_tags: [ nodejs ]
 dependencies: []
diff --git a/molecule.yml b/molecule.yml
index 013e6c7..81f9e3c 100644
--- a/molecule.yml
+++ b/molecule.yml
@@ -35,7 +35,7 @@ vagrant:
   - name: wheezy
     box: bmorg/debian-wheezy-i386
   instances:
-  - name: example
+  - name: nodejs
     options:
         append_platform_to_hostname: yes
   raw_config_args:
diff --git a/tasks/main.yml b/tasks/main.yml
index 0ab13c5..d522eed 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,8 +1,35 @@
 ---
-# tasks file for example
+# tasks file for nodejs
 
 - name: Assertions
   assert:
     that:
-        - ansible_os_family in ['OpenBSD', 'Debian']
-        - ansible_distribution_release in ['xenial', 'trusty', 'precise', 'stretch', 'jessie', 'wheezy'] or ansible_distribution_version in ['6.0']
+        - ansible_os_family == 'Debian'
+        - ansible_lsb.codename in ['buster', 'jessie', 'sid', 'stretch', 'trusty', 'xenial', 'yakkety', 'zesty']
+        - nodejs_version in [6, 8]
+
+- name: APT install prerequisites
+  apt:
+      name: apt-transport-https
+      state: present
+      update_cache: True
+      cache_valid_time: 3600
+
+- name: Add APT repository key
+  apt_key:
+      url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
+      state: present
+
+- name: Add APT repository
+  apt_repository:
+      repo: |
+          deb https://deb.nodesource.com/node_{{ nodejs_version }}.x {{ ansible_lsb.codename }} main
+      state: present
+      update_cache: True
+
+- name: APT install
+  apt:
+      name: nodejs
+      state: present
+      update_cache: True
+      cache_valid_time: 3600
diff --git a/tests/playbook.yml b/tests/playbook.yml
index 55444f3..dcc12fb 100644
--- a/tests/playbook.yml
+++ b/tests/playbook.yml
@@ -1,5 +1,5 @@
 ---
-- hosts: example-openbsd*
+- hosts: nodejs-openbsd*
   gather_facts: false
   roles:
       - openbsd-bootstrap
@@ -8,7 +8,7 @@
         users_use_sudo: True
         users_lock_root_ssh: False
 
-- hosts: [example-xenial, example-wheezy]
+- hosts: [nodejs-xenial, nodejs-wheezy]
   gather_facts: false
   roles:
       - debian-bootstrap
@@ -19,4 +19,4 @@
 
 - hosts: all
   roles:
-    - role: example
+    - role: nodejs
diff --git a/tests/test_nodejs.py b/tests/test_nodejs.py
new file mode 100644
index 0000000..0b83ec7
--- /dev/null
+++ b/tests/test_nodejs.py
@@ -0,0 +1,12 @@
+from testinfra.utils.ansible_runner import AnsibleRunner
+
+testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
+
+
+def test_nodejs(host):
+    assert host.run('node --version').rc == 0
+    assert host.run('nodejs --version').rc == 0
+
+
+def test_root(host):
+    assert host.run('npm --version').rc == 0
diff --git a/tox.ini b/tox.ini
index c80d480..2209e50 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,7 +1,7 @@
 [tox]
 skip_install = True
 skipsdist = True
-envlist = openbsd60,xenial,trusty,precise,stretch,jessie,wheezy
+envlist = xenial,trusty,stretch,jessie
 
 [testenv]
 envdir = {toxinidir}/.tox/molecule
diff --git a/vars/main.yml b/vars/main.yml
index 7542f3c..6422ced 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,2 +1,2 @@
 ---
-# vars file for example
+# vars file for nodejs
-- 
GitLab