2015-03-17 21:31:54 +01:00
|
|
|
- name: Start docker daemon
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: started
|
|
|
|
|
|
|
|
- name: Download busybox image
|
|
|
|
docker:
|
|
|
|
image: busybox
|
|
|
|
state: present
|
|
|
|
pull: missing
|
|
|
|
|
|
|
|
- name: Run a small script in busybox
|
|
|
|
docker:
|
|
|
|
image: busybox
|
|
|
|
state: reloaded
|
|
|
|
pull: always
|
|
|
|
command: "nc -l -p 2000 -e xargs -n1 echo hello"
|
|
|
|
detach: True
|
|
|
|
|
|
|
|
- name: Get the docker container ip
|
2015-12-10 19:10:17 +01:00
|
|
|
set_fact: container_ip="{{docker_containers[0].NetworkSettings.IPAddress}}"
|
2015-03-19 01:57:29 +01:00
|
|
|
|
2015-03-17 21:31:54 +01:00
|
|
|
- name: Try to access the server
|
2015-12-10 19:10:17 +01:00
|
|
|
shell: "echo 'world' | nc {{ container_ip }} 2000"
|
2015-03-17 21:31:54 +01:00
|
|
|
register: docker_output
|
|
|
|
|
|
|
|
- name: check that the script ran
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'hello world' in docker_output.stdout_lines"
|
2015-03-18 20:15:42 +01:00
|
|
|
|
|
|
|
- name: Run a script that sets environment in busybox
|
|
|
|
docker:
|
|
|
|
image: busybox
|
|
|
|
state: reloaded
|
|
|
|
pull: always
|
|
|
|
env:
|
|
|
|
TEST: hello
|
|
|
|
command: '/bin/sh -c "nc -l -p 2000 -e xargs -n1 echo $TEST"'
|
|
|
|
detach: True
|
|
|
|
|
|
|
|
- name: Get the docker container ip
|
2015-12-10 19:10:17 +01:00
|
|
|
set_fact: container_ip="{{docker_containers[0].NetworkSettings.IPAddress}}"
|
2015-03-19 01:57:29 +01:00
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
- name: Try to access the server
|
2015-12-10 19:10:17 +01:00
|
|
|
shell: "echo 'world' | nc {{ container_ip }} 2000"
|
2015-03-18 20:15:42 +01:00
|
|
|
register: docker_output
|
|
|
|
|
|
|
|
- name: check that the script ran
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'hello world' in docker_output.stdout_lines"
|
|
|
|
|
2015-03-19 02:56:46 +01:00
|
|
|
- name: Remove containers
|
2015-12-10 19:10:17 +01:00
|
|
|
shell: "docker rm -f $(docker ps -aq)"
|
2015-03-19 02:56:46 +01:00
|
|
|
|
|
|
|
- name: Remove all images from the local docker
|
2015-03-19 01:57:29 +01:00
|
|
|
shell: "docker rmi -f $(docker images -q)"
|