Skip to content

Commit

Permalink
Swithc to role based testing, bump node to 0.10.44, use ansible facts…
Browse files Browse the repository at this point in the history
… rather than shell
  • Loading branch information
David Farrington committed May 4, 2016
1 parent f1c92d4 commit 28dc212
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 26 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
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
4 changes: 4 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[defaults]
<<<<<<< f1c92d4cc19c8c520b8f133992f224dacf43af2a
roles_path = ~/roles/
=======
roles_path = ../
>>>>>>> Swithc to role based testing, bump node to 0.10.44, use ansible facts rather than shell
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.40"
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
11 changes: 3 additions & 8 deletions tasks/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
pkg: python-pycurl
state: present

- name: node.js | get release
shell: lsb_release -c -s
changed_when: false
register: distro

- name: node.js | add signing key
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
Expand All @@ -22,11 +17,11 @@
line: "{{ item }}"
state: present
with_items:
- "deb https://deb.nodesource.com/node {{ distro.stdout }} main"
- "deb-src https://deb.nodesource.com/node {{ distro.stdout }} main"
- "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 }}-1nodesource1~{{ distro.stdout }}1"
pkg: "nodejs={{ nodejs_version }}-1nodesource1~{{ ansible_lsb.codename }}1"
update_cache: yes
state: present
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 28dc212

Please sign in to comment.