Skip to content

Commit

Permalink
Issue #221: Add tests for current multi-server ad-hoc orchestration e…
Browse files Browse the repository at this point in the history
…xamples.
  • Loading branch information
geerlingguy committed Aug 3, 2020
1 parent b510094 commit 9fa380e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Expand Up @@ -80,9 +80,7 @@ env:
- playbook: nodejs-role.yml
distro: centos7

# TODO: Not easy to test in CI at this time.
# - playbook: orchestration.yml
# distro: ubuntu2004
- shell_script: orchestration.sh

- playbook: security.yml
distro: centos8
Expand Down
3 changes: 3 additions & 0 deletions orchestration/scripts/ansible.cfg
@@ -0,0 +1,3 @@
[defaults]
inventory = hosts.ini
nocows = True
19 changes: 19 additions & 0 deletions orchestration/scripts/app.sh
@@ -0,0 +1,19 @@
#!/bin/bash
#
# App server orchestration ad-hoc tasks.
set -e

# Configure Django on app server.
ansible app -b -m yum -a "name=MySQL-python state=present"
ansible app -b -m yum -a "name=python-setuptools state=present"
ansible app -b -m easy_install -a "name=django<2 state=present"

# Check Django version.
ansible app -a "python -c 'import django; print django.get_version()'"

# Other commands from the book.
ansible app -b -a "service ntpd status"
ansible app -b -m group -a "name=admin state=present"
ansible app -b -m user -a "name=johndoe group=admin createhome=yes"
ansible app -b -m user -a "name=johndoe state=absent remove=yes"
ansible app -b -m package -a "name=git state=present"
14 changes: 14 additions & 0 deletions orchestration/scripts/db.sh
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Database server orchestration ad-hoc tasks.
set -e

# Configure MySQL (MariaDB) server.
ansible db -b -m yum -a "name=mariadb-server state=present"
ansible db -b -m service -a "name=mariadb state=started enabled=yes"
ansible db -b -a "iptables -F"
ansible db -b -a "iptables -A INPUT -s 192.168.60.0/24 -p tcp -m tcp --dport 3306 -j ACCEPT"

# Configure DB user for Django.
ansible db -b -m yum -a "name=MySQL-python state=present"
ansible db -b -m mysql_user -a "name=django host=% password=12345 priv=*.*:ALL state=present"
6 changes: 6 additions & 0 deletions orchestration/scripts/hosts.ini
@@ -0,0 +1,6 @@
[multi]
app
db

[multi:vars]
ansible_connection=docker
14 changes: 14 additions & 0 deletions orchestration/scripts/multi.sh
@@ -0,0 +1,14 @@
#!/bin/bash
#
# Multi-server tests for the orchestration example.
set -e

# Other commands from the book.
ansible multi -m stat -a "path=/etc/environment"
ansible multi -m copy -a "src=/etc/hosts dest=/tmp/hosts"
ansible multi -b -m fetch -a "src=/etc/hosts dest=/tmp"
ansible multi -m file -a "dest=/tmp/test mode=644 state=directory"
ansible multi -m file -a "dest=/tmp/test state=absent"
ansible multi -b -B 3600 -P 0 -a "yum -y update"
ansible multi -b -a "tail /var/log/messages"
ansible multi -b -m shell -a "tail /var/log/messages | grep ansible-command | wc -l"
25 changes: 25 additions & 0 deletions tests/orchestration.sh
@@ -0,0 +1,25 @@
#!/bin/bash
#
# Orchestration tests.
set -e

# Make sure pip3 is available.
sudo apt-get update
sudo apt-get install -y python3-pip python3-setuptools
pip3 install --upgrade setuptools pip

# Install dependencies.
sudo pip3 install ansible

cd orchestration/scripts

# Test Django app installation.
docker run -d --name app -p 80:80 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-centos7-ansible
./django-app.sh

# Test Django db installation.
docker run -d --name db -p 3360:3360 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-centos7-ansible
./django-db.sh

# Other tests from the book.
./orchestration.sh

0 comments on commit 9fa380e

Please sign in to comment.