Skip to content

Commit 3c069f3

Browse files
authored
Merge pull request #309 from geerlingguy/221-orchestration-tests
Issue #221: Add tests for current multi-server ad-hoc orchestration examples.
2 parents 98ee43a + 7577ca3 commit 3c069f3

File tree

9 files changed

+87
-5
lines changed

9 files changed

+87
-5
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/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Ansible playbooks are flexible and powerful. But sometimes, you just need to run
44

55
Just like the device in Ender's Game, the `ansible` command allows you to run commands or call Ansible modules immediately on one or one hundred of servers.
66

7-
This simple Vagrantfile configures three Virtual Machines using Vagrant and VirtualBox: `app1`, `app2`, and `db`, to emulate a small-scale real-world infrastructure (two application servers and a database server), so you can practice running `ansible` commands across them, and work on a flexible Ansible inventory.
7+
This project configures three Virtual Machines using Vagrant and VirtualBox: `app1`, `app2`, and `db`, to emulate a small-scale real-world infrastructure (two application servers and a database server), so you can practice running `ansible` commands across them, and work on a flexible Ansible inventory.
88

99
## Quick Start Guide
1010

orchestration/Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VAGRANTFILE_API_VERSION = "2"
55

66
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
77
# General Vagrant VM configuration.
8-
config.vm.box = "geerlingguy/centos7"
8+
config.vm.box = "geerlingguy/centos8"
99
config.ssh.insert_key = false
1010
config.vm.synced_folder ".", "/vagrant", disabled: true
1111
config.vm.provider :virtualbox do |v|

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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=python3-pip state=present"
8+
ansible app -b -m pip -a "name=django<4 state=present"
9+
10+
# Check Django version.
11+
ansible app -a "python3 -m django --version"
12+
13+
# Other commands from the book.
14+
# ansible app -b -a "systemctl status chronyd"
15+
ansible app -b -m group -a "name=admin state=present"
16+
ansible app -b -m user -a "name=johndoe group=admin createhome=yes"
17+
ansible app -b -m user -a "name=johndoe state=absent remove=yes"
18+
ansible app -b -m package -a "name=git state=present"

orchestration/scripts/db.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
10+
# Configure firewalld.
11+
ansible db -b -m yum -a "name=firewalld state=present"
12+
ansible db -b -m service -a "name=firewalld state=started enabled=yes"
13+
ansible db -b -m firewalld -a "zone=database state=present permanent=yes"
14+
ansible db -b -m firewalld -a "source=192.168.60.0/24 zone=database state=enabled permanent=yes"
15+
ansible db -b -m firewalld -a "port=3306/tcp zone=database state=enabled permanent=yes"
16+
17+
# Configure DB user for Django.
18+
ansible db -b -m yum -a "name=python3-PyMySQL state=present"
19+
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 -b -m yum -a "name=chrony state=present"
8+
ansible multi -m stat -a "path=/etc/environment"
9+
ansible multi -m copy -a "src=/etc/hosts dest=/tmp/hosts"
10+
ansible multi -b -m fetch -a "src=/etc/hosts dest=/tmp"
11+
ansible multi -m file -a "dest=/tmp/test mode=644 state=directory"
12+
ansible multi -m file -a "dest=/tmp/test state=absent"
13+
ansible multi -b -B 3600 -P 0 -a "yum -y update"

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-centos8-ansible
18+
./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-centos8-ansible
22+
./db.sh
23+
24+
# Other tests from the book.
25+
./multi.sh

0 commit comments

Comments
 (0)