blob: 8793d954ea5cb758188973d6f00f4e3e6c29a56f (
plain)
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
|
---
# Include this play once for each container you want to create and use as a test host.
#
# Optional parameters on the include are as follows:
# * scenario = unique name for the container to be started
# * image = name of the image to start in the container
# * command = command to run in the container
# * l_groups = host groups that the container should be added to
# * l_host_vars = any variables that should be added to the host
- name: Start container for specified test host
gather_facts: no
hosts: localhost
connection: local
tasks:
- set_fact:
# This is a little weird but if we use a var instead of a fact,
# a different random value is generated for each task. See:
# https://opensolitude.com/2015/05/27/ansible-lookups-variables-vs-facts.html
container_name: openshift_ansible_test_{{ scenario | default(100000000000000 | random) }}
- name: start container
docker_container:
name: "{{ container_name }}"
image: "{{ lookup('env', 'IMAGE_PREFIX') | default('openshift-ansible-integration-', true) }}{{ image | default('test-target-base') }}"
command: "{{ command | default('sleep 1800') }}"
recreate: yes
# NOTE: When/if we need to run containers that are docker hosts as well:
# volumes: [ "/var/run/docker.sock:/var/run/docker.sock:z" ]
- name: add container as host in inventory
add_host:
ansible_connection: docker
name: "{{ container_name }}"
groups: '{{ l_groups | default("masters,nodes,etcd") }}'
# There ought to be a better way to transfer the host vars, but see:
# https://groups.google.com/forum/#!topic/Ansible-project/Jwx8RYhqxPA
- name: set host facts per test parameters
set_fact:
"{{ item.key }}": "{{ item.value }}"
delegate_facts: True
delegate_to: "{{ container_name }}"
with_dict: "{{ l_host_vars | default({}) }}"
|