2015-03-17 20:31:54 +00:00
|
|
|
- name: Start docker daemon
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: started
|
|
|
|
|
|
|
|
- name: Download busybox image
|
|
|
|
docker:
|
|
|
|
image: busybox
|
|
|
|
state: present
|
|
|
|
pull: missing
|
2015-03-19 00:57:29 +00:00
|
|
|
docker_api_version: "1.14"
|
2015-03-17 20:31:54 +00:00
|
|
|
|
|
|
|
- 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
|
2015-03-19 00:57:29 +00:00
|
|
|
docker_api_version: "1.14"
|
2015-03-17 20:31:54 +00:00
|
|
|
|
|
|
|
- name: Get the docker container id
|
|
|
|
shell: "docker ps | grep busybox | awk '{ print $1 }'"
|
|
|
|
register: container_id
|
|
|
|
|
|
|
|
- name: Get the docker container ip
|
|
|
|
shell: "docker inspect {{ container_id.stdout_lines[0] }} | grep IPAddress | awk -F '\"' '{ print $4 }'"
|
|
|
|
register: container_ip
|
|
|
|
|
2015-03-19 00:57:29 +00:00
|
|
|
- name: Pause a few moments because docker is not reliable
|
|
|
|
pause:
|
|
|
|
seconds: 40
|
|
|
|
|
2015-03-17 20:31:54 +00:00
|
|
|
- name: Try to access the server
|
|
|
|
shell: "echo 'world' | nc {{ container_ip.stdout_lines[0] }} 2000"
|
|
|
|
register: docker_output
|
|
|
|
|
|
|
|
- name: check that the script ran
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'hello world' in docker_output.stdout_lines"
|
2015-03-18 19:15:42 +00: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
|
2015-03-19 00:57:29 +00:00
|
|
|
docker_api_version: "1.14"
|
2015-03-18 19:15:42 +00:00
|
|
|
|
|
|
|
- name: Get the docker container id
|
|
|
|
shell: "docker ps | grep busybox | awk '{ print $1 }'"
|
|
|
|
register: container_id
|
|
|
|
|
|
|
|
- name: Get the docker container ip
|
|
|
|
shell: "docker inspect {{ container_id.stdout_lines[0] }} | grep IPAddress | awk -F '\"' '{ print $4 }'"
|
|
|
|
register: container_ip
|
|
|
|
|
2015-03-19 00:57:29 +00:00
|
|
|
- name: Pause a few moments because docker is not reliable
|
|
|
|
pause:
|
|
|
|
seconds: 40
|
|
|
|
|
2015-03-18 19:15:42 +00:00
|
|
|
- name: Try to access the server
|
|
|
|
shell: "echo 'world' | nc {{ container_ip.stdout_lines[0] }} 2000"
|
|
|
|
register: docker_output
|
|
|
|
|
|
|
|
- name: check that the script ran
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'hello world' in docker_output.stdout_lines"
|
|
|
|
|
2015-03-19 01:56:46 +00:00
|
|
|
- name: Remove containers
|
|
|
|
shell: "docker rm $(docker ps -aq)"
|
|
|
|
|
|
|
|
- name: Remove all images from the local docker
|
2015-03-19 00:57:29 +00:00
|
|
|
shell: "docker rmi -f $(docker images -q)"
|