Skip to content

Commit 9fa380e

Browse files
committed
Issue #221: Add tests for current multi-server ad-hoc orchestration examples.
1 parent b510094 commit 9fa380e

File tree

7 files changed

+82
-3
lines changed

7 files changed

+82
-3
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ env:
8080
- playbook: nodejs-role.yml
8181
distro: centos7
8282

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

8785
- playbook: security.yml
8886
distro: centos8

orchestration/scripts/ansible.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[defaults]
2+
inventory = hosts.ini
3+
nocows = True

orchestration/scripts/app.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# App server orchestration ad-hoc tasks.
4+
set -e
5+
6+
# Configure Django on app server.
7+
ansible app -b -m yum -a "name=MySQL-python state=present"
8+
ansible app -b -m yum -a "name=python-setuptools state=present"
9+
ansible app -b -m easy_install -a "name=django<2 state=present"
10+
11+
# Check Django version.
12+
ansible app -a "python -c 'import django; print django.get_version()'"
13+
14+
# Other commands from the book.
15+
ansible app -b -a "service ntpd status"
16+
ansible app -b -m group -a "name=admin state=present"
17+
ansible app -b -m user -a "name=johndoe group=admin createhome=yes"
18+
ansible app -b -m user -a "name=johndoe state=absent remove=yes"
19+
ansible app -b -m package -a "name=git state=present"

orchestration/scripts/db.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#
3+
# Database server orchestration ad-hoc tasks.
4+
set -e
5+
6+
# Configure MySQL (MariaDB) server.
7+
ansible db -b -m yum -a "name=mariadb-server state=present"
8+
ansible db -b -m service -a "name=mariadb state=started enabled=yes"
9+
ansible db -b -a "iptables -F"
10+
ansible db -b -a "iptables -A INPUT -s 192.168.60.0/24 -p tcp -m tcp --dport 3306 -j ACCEPT"
11+
12+
# Configure DB user for Django.
13+
ansible db -b -m yum -a "name=MySQL-python state=present"
14+
ansible db -b -m mysql_user -a "name=django host=% password=12345 priv=*.*:ALL state=present"

orchestration/scripts/hosts.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[multi]
2+
app
3+
db
4+
5+
[multi:vars]
6+
ansible_connection=docker

orchestration/scripts/multi.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#
3+
# Multi-server tests for the orchestration example.
4+
set -e
5+
6+
# Other commands from the book.
7+
ansible multi -m stat -a "path=/etc/environment"
8+
ansible multi -m copy -a "src=/etc/hosts dest=/tmp/hosts"
9+
ansible multi -b -m fetch -a "src=/etc/hosts dest=/tmp"
10+
ansible multi -m file -a "dest=/tmp/test mode=644 state=directory"
11+
ansible multi -m file -a "dest=/tmp/test state=absent"
12+
ansible multi -b -B 3600 -P 0 -a "yum -y update"
13+
ansible multi -b -a "tail /var/log/messages"
14+
ansible multi -b -m shell -a "tail /var/log/messages | grep ansible-command | wc -l"

tests/orchestration.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
#
3+
# Orchestration tests.
4+
set -e
5+
6+
# Make sure pip3 is available.
7+
sudo apt-get update
8+
sudo apt-get install -y python3-pip python3-setuptools
9+
pip3 install --upgrade setuptools pip
10+
11+
# Install dependencies.
12+
sudo pip3 install ansible
13+
14+
cd orchestration/scripts
15+
16+
# Test Django app installation.
17+
docker run -d --name app -p 80:80 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-centos7-ansible
18+
./django-app.sh
19+
20+
# Test Django db installation.
21+
docker run -d --name db -p 3360:3360 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-centos7-ansible
22+
./django-db.sh
23+
24+
# Other tests from the book.
25+
./orchestration.sh

0 commit comments

Comments
 (0)