Skip to content

Commit cd7ee5d

Browse files
committed
Issue geerlingguy#202: Add collection test.
1 parent f89a5c6 commit cd7ee5d

File tree

8 files changed

+56
-1
lines changed

8 files changed

+56
-1
lines changed

Diff for: .travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ branches:
66
- master
77

88
env:
9+
- playbook: collection.yml
10+
distro: centos7
11+
912
# Run each test playbook in a separate environment.
1013
- playbook: deployments.yml
1114
distro: ubuntu1804

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Here is an outline of all the examples contained in this repository, by chapter:
4242
### Chapter 7
4343

4444
- [`test-plugin`](test-plugin/): A simple test plugin that verifies a given value is representative of the color blue.
45-
- [`collection`](collection/): TODO.
45+
- [`collection`](collection/): An example local collection to demonstrate the basic structure of content collections.
4646

4747
### Chapter 8
4848

Diff for: collection/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ansible Local Collection Example
2+
3+
TODO.

Diff for: collection/ansible.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[defaults]
2+
collections_paths = ./
3+
nocows = 1
+7
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]>
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+
}

Diff for: collection/main.yml

+14
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"

Diff for: tests/collection.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
- import_playbook: ../collection/main.yml

0 commit comments

Comments
 (0)