mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
YAML
59 lines
1.4 KiB
YAML
10 years ago
|
- 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
|
||
9 years ago
|
set_fact: container_ip="{{docker_containers[0].NetworkSettings.IPAddress}}"
|
||
10 years ago
|
|
||
10 years ago
|
- name: Try to access the server
|
||
9 years ago
|
shell: "echo 'world' | nc {{ container_ip }} 2000"
|
||
10 years ago
|
register: docker_output
|
||
|
|
||
|
- name: check that the script ran
|
||
|
assert:
|
||
|
that:
|
||
|
- "'hello world' in docker_output.stdout_lines"
|
||
10 years ago
|
|
||
|
- 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
|
||
9 years ago
|
set_fact: container_ip="{{docker_containers[0].NetworkSettings.IPAddress}}"
|
||
10 years ago
|
|
||
10 years ago
|
- name: Try to access the server
|
||
9 years ago
|
shell: "echo 'world' | nc {{ container_ip }} 2000"
|
||
10 years ago
|
register: docker_output
|
||
|
|
||
|
- name: check that the script ran
|
||
|
assert:
|
||
|
that:
|
||
|
- "'hello world' in docker_output.stdout_lines"
|
||
|
|
||
10 years ago
|
- name: Remove containers
|
||
9 years ago
|
shell: "docker rm -f $(docker ps -aq)"
|
||
10 years ago
|
|
||
|
- name: Remove all images from the local docker
|
||
10 years ago
|
shell: "docker rmi -f $(docker images -q)"
|