---
sudo: required
language: python
python: "2.7"

env:
  - SITE=test.yml

before_install:
  - sudo apt-get update -qq

install:
  # Install Ansible.
  - pip install ansible

  # Add ansible.cfg to pick up roles path.
  - "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"

  # Install dependencies.
  - ansible-galaxy install geerlingguy.memcached geerlingguy.php

script:
  # Check the role/playbook's syntax.
  - "ansible-playbook -i tests/inventory tests/$SITE --syntax-check"

  # Run the role/playbook with ansible-playbook.
  - "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo"

  # Run the role/playbook again, checking to make sure it's idempotent.
  - >
    ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo
    | grep -q 'changed=0.*failed=0'
    && (echo 'Idempotence test: pass' && exit 0)
    || (echo 'Idempotence test: fail' && exit 1)

  # Run script to test if Memcached is available and working.
  - php tests/memcached-test.php

notifications:
  webhooks: https://galaxy.ansible.com/api/v1/notifications/
