Skip to content

Commit 182a899

Browse files
authored
Merge pull request geerlingguy#287 from geerlingguy/202-collections
Issue geerlingguy#202: New Collections chapter content.
2 parents 1475f1d + fa7c19f commit 182a899

File tree

11 files changed

+118
-8
lines changed

11 files changed

+118
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.vagrant/
33
vagrant_ansible_inventory_default
4+
__pycache__
45
*.cache
56
*.retry
67
test.sh

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ branches:
66
- master
77

88
env:
9+
- shell_script: collection.sh
10+
911
# Run each test playbook in a separate environment.
1012
- playbook: deployments.yml
1113
distro: ubuntu1804
@@ -74,6 +76,9 @@ env:
7476
- playbook: solr.yml
7577
distro: ubuntu1604
7678

79+
- playbook: test-plugin.yml
80+
distro: centos7
81+
7782
script:
7883
# Use test shim and run playbook if playbook is provided.
7984
- |

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,49 @@ Here is an outline of all the examples contained in this repository, by chapter:
4141

4242
### Chapter 7
4343

44-
- [`dynamic-inventory`](dynamic-inventory/): Two example dynamic inventory scripts (one in PHP, one in Python) for use with Ansible.
44+
- [`test-plugin`](test-plugin/): A simple test plugin that verifies a given value is representative of the color blue.
45+
- [`collection`](collection/): An example local collection to demonstrate the basic structure of content collections.
4546

4647
### Chapter 8
4748

49+
- [`dynamic-inventory`](dynamic-inventory/): Two example dynamic inventory scripts (one in PHP, one in Python) for use with Ansible.
50+
51+
### Chapter 9
52+
4853
- [`lamp-infrastructure`](lamp-infrastructure/): A multi-server LAMP-based web application infrastructure focused on high-availability and performance for a LAMP-stack app.
4954
- [`elk`](elk/): A two-server example of the Elasticsearch-Logstash-Kibana stack, which uses one server to store and visualize logs centrally, and another server to send logs via Filebeat.
5055

51-
### Chapter 9
56+
### Chapter 10
5257

5358
- [`deployments`](deployments/): A playbook that deploys a Ruby on Rails application into an environment that runs Passenger and Nginx to handle web requests.
5459
- [`deployments-balancer`](deployments-balancer/): A playbook that handles zero-downtime deployments to webservers running behind an HAProxy load balancer.
5560
- [`deployments-rolling`](deployments-rolling/): A playbook that demonstrates rolling deployments to multiple servers for a Node.js app.
5661

57-
### Chapter 10
62+
### Chapter 11
5863

5964
- N/A
6065

61-
### Chapter 11
66+
### Chapter 12
6267

6368
- [`jenkins`](jenkins/): A playbook that installs and configures Jenkins for CI/CD.
6469

65-
### Chapter 12
70+
### Chapter 13
6671

6772
- [`molecule`](molecule/): A Molecule example used for testing and developing an Ansible playbook, or for testing in a Continuous Integration (CI) environment.
6873
- [`ci.yml` GitHub Actions workflow](.github/workflows/ci.yml): A GitHub Actions workflow which runs the `molecule` example in a CI environment.
6974

70-
### Chapter 13
75+
### Chapter 14
7176

7277
- [`https-self-signed`](https-self-signed/): A playbook that generates self-signed certificates.
7378
- [`https-letsencrypt`](https-letsencrypt/): A playbook that demonstrates automated certificate management with Let's Encrypt and Ansible.
7479
- [`https-nginx-proxy`](https-nginx-proxy/): A playbook that demonstrates proxying HTTPS traffic through Nginx to HTTP backends.
7580

76-
### Chapter 14
81+
### Chapter 15
7782

7883
- [`docker`](docker/): Very simple playbook demonstrating Ansible's ability to manage Docker container images.
7984
- [`docker-hubot`](docker-hubot/): Slightly more involved example of Ansible's ability to manage and run Docker container images.
8085

81-
### Chapter 15
86+
### Chapter 16
8287

8388
- [`kubernetes`](kubernetes/): A playbook that builds a three-node Kubernetes cluster.
8489

collection/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ansible Local Collection Example
2+
3+
TODO.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
namespace: local
3+
name: colors
4+
version: 1.0.0
5+
readme: README.md
6+
authors:
7+
- your name <[email protected]>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Ansible custom 'blue' test plugin definition.
2+
3+
def is_blue(string):
4+
''' Return True if a valid CSS value of 'blue'. '''
5+
blue_values = [
6+
'blue',
7+
'#0000ff',
8+
'#00f',
9+
'rgb(0,0,255)',
10+
'rgb(0%,0%,100%)',
11+
]
12+
if string in blue_values:
13+
return True
14+
else:
15+
return False
16+
17+
class TestModule(object):
18+
''' Return dict of custom jinja tests. '''
19+
20+
def tests(self):
21+
return {
22+
'blue': is_blue
23+
}

collection/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- hosts: all
3+
4+
vars:
5+
my_color_choice: blue
6+
7+
tasks:
8+
- name: "Verify {{ my_color_choice }} is a form of blue."
9+
assert:
10+
that: my_color_choice is local.colors.blue
11+
12+
- name: "Verify yellow is not a form of blue."
13+
assert:
14+
that: "'yellow' is not local.colors.blue"

test-plugin/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- hosts: all
3+
4+
vars:
5+
my_color_choice: blue
6+
7+
tasks:
8+
- name: "Verify {{ my_color_choice }} is a form of blue."
9+
assert:
10+
that: my_color_choice is blue

test-plugin/test_plugins/blue.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Ansible custom 'blue' test plugin definition.
2+
3+
def is_blue(string):
4+
''' Return True if a valid CSS value of 'blue'. '''
5+
blue_values = [
6+
'blue',
7+
'#0000ff',
8+
'#00f',
9+
'rgb(0,0,255)',
10+
'rgb(0%,0%,100%)',
11+
]
12+
if string in blue_values:
13+
return True
14+
else:
15+
return False
16+
17+
class TestModule(object):
18+
''' Return dict of custom jinja tests. '''
19+
20+
def tests(self):
21+
return {
22+
'blue': is_blue
23+
}

tests/collection.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
#
3+
# Collection playbook 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 collection
15+
16+
# Run Ansible playbook.
17+
ansible-playbook -c local -i 'localhost,' main.yml

0 commit comments

Comments
 (0)