Test playbook execution with travis

This commit is contained in:
Emilien Mantel
2016-09-25 12:47:36 +02:00
parent 17f3731450
commit 293ee332dd
5 changed files with 32 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]
CMD ["sh", "tests/travis.sh"]

View File

@@ -3,8 +3,8 @@
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
DIR=$( dirname $0 )
INVENTORY_FILE="$DIR/inventory"
PLAYBOOK="$DIR/test.yml"
INVENTORY_FILE="localhost,"
PLAYBOOK="$DIR/travis.yml"
set -ev
@@ -12,10 +12,10 @@ set -ev
ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK
# Check role
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK
ansible-playbook -i $INVENTORY_FILE -c local -e "{ mysql_vendor: $VENDOR, mysql_origin: $ORIGIN }" --sudo -vv $PLAYBOOK
# Check indempotence
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK \
ansible-playbook -i $INVENTORY_FILE -c local -e "{ mysql_vendor: $VENDOR, mysql_origin: $ORIGIN }" --sudo -vv $PLAYBOOK \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)

13
tests/travis.yml Normal file
View File

@@ -0,0 +1,13 @@
---
- hosts: all
vars:
mysql_replication_master: true
mysql_bind_address: '{{ ansible_eth0.ipv4.address }}'
mariadb_galera_members:
- '{{ ansible_eth0.ipv4.address }}'
roles:
- ../../
post_tasks:
- name: TEST | SHELL | Test mysql
shell: mysql -e "SHOW DATABASES;"