forked from projectatomic/atomic-host-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
150 lines (127 loc) · 4.43 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
# vim: set ft=ansible:
#
# !!!NOTE!!! This playbook was tested using Ansible 2.2; any other versions
# are not supported.
#
# This playbook aims to verify that the changes to the Atomic Host platform
# do not disrupt the ability for users to build/run containers built on top
# of various base images. The base images from Docker Hub were selected
# based on 'popularity' (aka number of pulls).
#
# Each base image is used to build an httpd container, which is then run,
# and the content returned by the container is verified to be correct.
# Afterwards, the container and build image are removed from the system.
#
# In order to use less 'hacks', the playbook is actually multiple playbooks
# that are divided into setup, tests, and cleanup. As such, this playbook
# is meant to be run in its entirety and not separately.
#
- name: Docker build httpd - setup
hosts: all
become: yes
tags:
- docker_build_setup
vars_files:
- vars.yml
pre_tasks:
- name: Fail if variables are not defined
fail:
msg: "Required variables are not defined. Please check tests/docker-build-httpd/vars.yml."
when: base_images is undefined or image_names is undefined
- name: Fail if RHEL variables are not defined
fail:
msg: "Required RHEL variables are not defined. Please check tests/docker-build-httpd/vars.yml"
when: (rhel_base_images is undefined or rhel_image_names is undefined) and
ansible_distribution == "RedHat"
roles:
# This playbook requires Ansible 2.2 and an Atomic Host
- role: ansible_version_check
avc_major: "2"
avc_minor: "2"
tags:
- ansible_version_check
- role: redhat_subscription
when: ansible_distribution == "RedHat"
tags:
- redhat_subscription
post_tasks:
- name: Create working directory
command: mktemp -d
register: mktemp
- name: Set the working_dir fact
set_fact:
working_dir: "{{ mktemp.stdout }}"
- name: Copy Dockerfiles
synchronize:
src: files/
dest: "{{ working_dir }}/"
recursive: yes
- name: Pull all the upstream base images
command: "docker pull {{ item }}"
with_items: "{{ base_images }}"
register: dp_upstream
retries: 5
delay: 60
until: dp_upstream|success
- name: Pull the Red Hat base images
command: "docker pull {{ item }}"
with_items: "{{ rhel_base_images }}"
register: dp_rhel
retries: 5
delay: 60
until: dp_rhel|success
when: ansible_distribution == "RedHat"
- name: Docker build httpd - test
hosts: all
become: yes
tags:
- docker_build_test
vars_files:
- vars.yml
pre_tasks:
- name: Fail if variables are not defined
fail:
msg: "Required variables are not defined. Please check tests/docker-build-httpd/vars.yml."
when: base_images is undefined or image_names is undefined
- name: Fail if RHEL variables are not defined
fail:
msg: "Required RHEL variables are not defined. Please check tests/docker-build-httpd/vars.yml"
when: (rhel_base_images is undefined or rhel_image_names is undefined) and
ansible_distribution == "RedHat"
tasks:
# I would have used a 'block' of 'roles' here, but that is not
# compatible with the 'with_items' loop control, so I stuck all
# the tasks into a single role file and used an 'include:'
# statement on that file.
#
# Added the ability to skip broken images with the 'cli_skipped_images'
# variable. This can be set via the CLI like so:
# ansible-playbook -e "cli_skipped_images=busybox_httpd,debian_httpd"
#
- include: tasks/build_run_remove.yml
vars:
base_dir: "{{ working_dir }}"
image_name: "{{ item }}"
skipped_images: "{{ cli_skipped_images | default('') }}"
with_items: "{{ image_names }}"
- include: tasks/build_run_remove.yml
vars:
base_dir: "{{ working_dir }}"
image_name: "{{ item }}"
skipped_images: "{{ cli_skipped_images | default('') }}"
with_items: "{{ rhel_image_names }}"
when: ansible_distribution == "RedHat"
- name: Docker build httpd - Cleanup
hosts: all
become: yes
tags:
- docker_build_cleanup
roles:
- role: docker_remove_all
tags:
- docker_remove_all
- role: redhat_unsubscribe
when: ansible_distribution == "RedHat"
tags:
- redhat_unsubscribe