Skip to content

Commit

Permalink
Merge pull request #23 from ANXS/soupdiver/issue_10
Browse files Browse the repository at this point in the history
Switched to nodesource
  • Loading branch information
David Farrington committed May 4, 2016
2 parents a656fab + 8c39f77 commit af85389
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 35 deletions.
27 changes: 17 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ python: "2.7"
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
env:
- ROLE_OPTIONS="nodejs_install_method=source"
- ROLE_OPTIONS="nodejs_install_method=package"
- ROLE_OPTIONS="nodejs_install_method=binary"
install:
- pip install ansible==1.8.4
- pip install -U ansible
# Install dependencies
- ansible-galaxy install -r tests/requirements.yml
script:
- echo localhost > inventory
- mkdir -p ~/roles/
- ansible-galaxy install -r requirements.yml
- ansible-playbook -i inventory -e nodejs_install_method=binary test.yml --syntax-check
- ansible-playbook -i inventory -e nodejs_install_method=binary test.yml --connection=local --sudo
- >
ansible-playbook -i inventory -e nodejs_install_method=binary test.yml --connection=local --sudo
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)

# Syntax check
- ansible-playbook -i inventory tests/playbook.yml --syntax-check

# Play test
- ansible-playbook -i inventory tests/playbook.yml --connection=local --sudo -e "$ROLE_OPTIONS"

# Idempotence test
- ansible-playbook -i inventory tests/playbook.yml --connection=local --sudo -e "$ROLE_OPTIONS" > idempotence_out
- ./tests/idempotence_check.sh idempotence_out
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ANXS - nodejs [![Build Status](https://travis-ci.org/ANXS/nodejs.png)](https://travis-ci.org/ANXS/nodejs)
## ANXS - nodejs [![Build Status](https://travis-ci.org/ANXS/nodejs.png?branch=master)](https://travis-ci.org/ANXS/nodejs)

Ansible role for installing nodejs, from package or by building it from source.

Expand All @@ -21,6 +21,17 @@ nodejs_version: "0.11.13" # nodejs version to install.
nodejs_install_method: "binary" # "source" or "binary" (package is not available for 0.11)
```
#### Testing
This project comes with a Vagrantfile, this is a fast and easy way to test changes to the role, fire it up with `vagrant up`

See [vagrant docs](https://docs.vagrantup.com/v2/) for getting setup with vagrant

Once your VM is up, you can reprovision it using either `vagrant provision`, or `ansible-playbook tests/playbook.yml -i vagrant-inventory`

If you want to toy with the test play, see [tests/playbook.yml](./tests/playbook.yml), and change the variables in [tests/vars.yml](./tests/vars.yml)

If you are contributing, please first test your changes within the vagrant environment, (using the targeted distribution), and if possible, ensure your change is covered in the tests found in [.travis.yml](./.travis.yml)

#### Thanks to
- [Nicolas Bazire](https://github.com/nicbaz)
- [Luís Couto](https://github.com/Couto)
Expand Down
22 changes: 16 additions & 6 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
nodejs_install_method = ENV.key?('NODEJS_INSTALL_METHOD') ? ENV['NODEJS_INSTALL_METHOD'] : 'source'

Vagrant.configure('2') do |config|
config.vm.define 'anxs' do |c|
c.vm.box = 'ubuntu/trusty64'
c.vm.network :private_network, ip: '192.168.88.17'
c.vm.hostname = 'anxs.local'
c.vm.provision 'ansible' do |ansible|
ansible.playbook = 'test.yml'
# Ensure we use our vagrant private key
config.ssh.insert_key = false
config.ssh.private_key_path = '~/.vagrant.d/insecure_private_key'

config.vm.define 'anxs' do |machine|
machine.vm.box = "ubuntu/trusty64"
#machine.vm.box = "ubuntu/precise64"
#machine.vm.box = "debian/jessie64"
#machine.vm.box = "debian/wheezy64"
#machine.vm.box = "chef/centos-7.1"
#machine.vm.box = "chef/centos-6.6"

machine.vm.network :private_network, ip: '192.168.88.17'
machine.vm.hostname = 'anxs.local'
machine.vm.provision 'ansible' do |ansible|
ansible.playbook = 'tests/playbook.yml'
ansible.sudo = true
ansible.inventory_path = 'vagrant-inventory'
ansible.host_key_checking = false
Expand Down
2 changes: 1 addition & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[defaults]
roles_path = ~/roles/
roles_path = ../
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# file: nodejs/defaults/main.yml

nodejs_install_method : "source"
nodejs_version : "0.10.26"
nodejs_version : "0.10.44"

nodejs_directory : "/usr/local/nodejs"
nodejs_source_url : "https://nodejs.org/dist/v{{nodejs_version}}/node-v{{nodejs_version}}.tar.gz"
Expand Down
4 changes: 0 additions & 4 deletions requirements.yml

This file was deleted.

19 changes: 15 additions & 4 deletions tasks/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@
pkg: python-pycurl
state: present

- name: nodejs | Add the nodejs repository
apt_repository:
repo: ppa:chris-lea/node.js
- name: node.js | add signing key
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present

- name: node.js | add sources.list entry
lineinfile:
dest: /etc/apt/sources.list.d/nodesource.list
create: yes
line: "{{ item }}"
state: present
with_items:
- "deb https://deb.nodesource.com/node {{ ansible_lsb.codename }} main"
- "deb-src https://deb.nodesource.com/node {{ ansible_lsb.codename }} main"

- name: node.js | Install the node.js package
apt:
pkg: nodejs={{nodejs_version}}
pkg: "nodejs={{ nodejs_version }}-1nodesource1~{{ ansible_lsb.codename }}1"
update_cache: yes
state: present
7 changes: 0 additions & 7 deletions test.yml

This file was deleted.

28 changes: 28 additions & 0 deletions tests/idempotence_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Process the output of the given file (should contain a plays stdout/err)
# If we pass, return with 0 else return with 1, and print useful output

_file="$1"

# Assert filename has been passed
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; }

# Assert file exists
[ ! -f "$_file" ] && { echo "$0: $_file file not found."; exit 2; }

# Make sure nothing has changed or failed
grep -q 'changed=0.*failed=0' $_file

# Success condition
if [ $? -eq 0 ]; then
echo 'Idempotence test: pass'
exit

# Failure condition, extract useful information and exit
else
echo 'Idempotence test: fail'
echo ''
grep --color=auto -B1 -A1 "\(changed\|failed\):" $_file
exit 1
fi
9 changes: 9 additions & 0 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- hosts: all
remote_user: root
become: yes
vars_files:
- ./vars.yml
roles:
- role: nodejs
3 changes: 3 additions & 0 deletions tests/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- role: ANXS.build-essential
4 changes: 4 additions & 0 deletions tests/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

nodejs_install_method : "package"
nodejs_version : "0.10.44"
2 changes: 1 addition & 1 deletion vagrant-inventory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[anxs]
anxs.local ansible_ssh_host=192.168.88.17 ansible_ssh_port=22
anxs.local ansible_ssh_host=192.168.88.17 ansible_ssh_port=22 ansible_ssh_user=vagrant ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key

0 comments on commit af85389

Please sign in to comment.