2015-03-17 22:40:10 +01:00
|
|
|
- name: Configure a private docker registry
|
|
|
|
service:
|
|
|
|
name: docker-registry
|
|
|
|
state: started
|
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
- name: Retrieve busybox image from docker hub
|
|
|
|
docker:
|
|
|
|
image: busybox
|
|
|
|
state: present
|
|
|
|
pull: missing
|
|
|
|
|
2015-03-17 22:40:10 +01:00
|
|
|
- name: Get busybox image id
|
|
|
|
shell: "docker images | grep busybox | awk '{ print $3 }'"
|
|
|
|
register: image_id
|
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
- name: Tag docker image into the local registry
|
2015-03-18 21:40:19 +01:00
|
|
|
command: "docker tag {{ image_id.stdout_lines[0] }} localhost:5000/mine"
|
2015-03-17 22:40:10 +01:00
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
- name: Push docker image into the private registry
|
2015-03-18 21:40:19 +01:00
|
|
|
command: "docker push localhost:5000/mine"
|
2015-03-17 22:40:10 +01:00
|
|
|
|
2015-03-19 01:57:29 +01:00
|
|
|
- name: Remove all images from the local docker
|
2015-12-10 19:10:17 +01:00
|
|
|
shell: "docker rmi -f {{image_id.stdout_lines[0]}}"
|
2015-03-17 22:40:10 +01:00
|
|
|
|
|
|
|
- name: Get number of images in docker
|
2015-03-18 21:40:19 +01:00
|
|
|
command: "docker images"
|
2015-03-17 22:40:10 +01:00
|
|
|
register: docker_output
|
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
# docker prints a header so the header should be all that's present
|
2015-03-17 22:40:10 +01:00
|
|
|
- name: Check that there are no images in docker
|
|
|
|
assert:
|
|
|
|
that:
|
2015-03-18 21:40:19 +01:00
|
|
|
- "{{ docker_output.stdout_lines| length }} <= 1 "
|
2015-03-17 22:40:10 +01:00
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
- name: Retrieve the image from private docker registry
|
2015-03-17 22:40:10 +01:00
|
|
|
docker:
|
|
|
|
image: "localhost:5000/mine"
|
|
|
|
state: present
|
|
|
|
pull: missing
|
|
|
|
insecure_registry: True
|
|
|
|
|
|
|
|
- name: Run a small script in the new image
|
|
|
|
docker:
|
|
|
|
image: "localhost:5000/mine"
|
|
|
|
state: reloaded
|
|
|
|
pull: always
|
|
|
|
command: "nc -l -p 2000 -e xargs -n1 echo hello"
|
|
|
|
detach: True
|
|
|
|
insecure_registry: True
|
|
|
|
|
|
|
|
- name: Get the docker container id
|
|
|
|
shell: "docker ps | grep mine | 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 01:57:29 +01:00
|
|
|
- name: Pause a few moments because docker is not reliable
|
|
|
|
pause:
|
|
|
|
seconds: 40
|
|
|
|
|
2015-03-17 22:40:10 +01: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 20:15:42 +01:00
|
|
|
|
2015-03-19 01:57:29 +01:00
|
|
|
|
|
|
|
- name: Remove containers
|
2015-12-10 19:10:17 +01:00
|
|
|
shell: "docker rm -f $(docker ps -aq)"
|
2015-03-19 01:57:29 +01:00
|
|
|
|
2015-12-10 19:10:17 +01:00
|
|
|
- shell: docker images -q
|
2015-03-19 01:57:29 +01:00
|
|
|
- name: Remove all images from the local docker
|
|
|
|
shell: "docker rmi -f $(docker images -q)"
|
2015-03-18 20:15:42 +01:00
|
|
|
|
|
|
|
- name: Get number of images in docker
|
2015-03-18 21:40:19 +01:00
|
|
|
command: "docker images"
|
2015-03-18 20:15:42 +01:00
|
|
|
register: docker_output
|
|
|
|
|
|
|
|
- name: Check that there are no images in docker
|
|
|
|
assert:
|
|
|
|
that:
|
2015-03-18 21:40:19 +01:00
|
|
|
- "{{ docker_output.stdout_lines| length }} <= 1"
|
2015-03-18 20:15:42 +01:00
|
|
|
|
2015-03-19 02:56:46 +01:00
|
|
|
#
|
|
|
|
# Private registry secured with an SSL proxy
|
|
|
|
#
|
|
|
|
|
|
|
|
- name: Set selinux to allow docker to connect to nginx
|
|
|
|
seboolean:
|
|
|
|
name: docker_connect_any
|
|
|
|
state: yes
|
|
|
|
|
|
|
|
- name: Set selinux to allow nginx to connect to docker
|
|
|
|
seboolean:
|
|
|
|
name: httpd_can_network_connect
|
|
|
|
state: yes
|
|
|
|
|
2015-03-18 20:15:42 +01:00
|
|
|
- name: Setup nginx with a user/password
|
|
|
|
copy:
|
|
|
|
src: docker-registry.htpasswd
|
2016-04-18 16:47:38 +02:00
|
|
|
dest: /etc/nginx/docker-registry.htpasswd
|
2015-03-18 20:15:42 +01:00
|
|
|
|
|
|
|
- name: Setup nginx with a config file
|
|
|
|
copy:
|
|
|
|
src: nginx-docker-registry.conf
|
2016-04-18 16:47:38 +02:00
|
|
|
dest: /etc/nginx/conf.d/nginx-docker-registry.conf
|
2015-03-18 20:15:42 +01:00
|
|
|
|
|
|
|
- name: Setup nginx docker cert
|
|
|
|
copy:
|
|
|
|
src: dockertest.ansible.com.crt
|
|
|
|
dest: /etc/pki/tls/certs/dockertest.ansible.com.crt
|
|
|
|
|
|
|
|
- name: Setup nginx docker key
|
|
|
|
copy:
|
|
|
|
src: dockertest.ansible.com.key
|
|
|
|
dest: /etc/pki/tls/private/dockertest.ansible.com.key
|
|
|
|
|
|
|
|
- name: Setup the ca keys
|
|
|
|
copy:
|
|
|
|
src: devdockerCA.crt
|
|
|
|
dest: /etc/pki/ca-trust/source/anchors/devdockerCA.crt
|
|
|
|
|
|
|
|
- name: Update the ca bundle
|
|
|
|
command: update-ca-trust extract
|
|
|
|
|
|
|
|
- name: Restart docker daemon
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: restarted
|
|
|
|
|
|
|
|
- name: Start nginx
|
|
|
|
service:
|
|
|
|
name: nginx
|
|
|
|
state: restarted
|
|
|
|
|
|
|
|
- name: Add domain name to hosts
|
|
|
|
lineinfile:
|
|
|
|
line: "127.0.0.1 dockertest.ansible.com"
|
|
|
|
dest: /etc/hosts
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Start a container after getting it from a secured private registry
|
|
|
|
docker:
|
|
|
|
image: dockertest.ansible.com:8080/mine
|
|
|
|
registry: dockertest.ansible.com:8080
|
|
|
|
username: "testdocker"
|
|
|
|
password: "testdocker"
|
|
|
|
state: running
|
|
|
|
command: "nc -l -p 2000 -e xargs -n1 echo hello"
|
|
|
|
detach: True
|
|
|
|
|
|
|
|
- name: Get the docker container id
|
|
|
|
shell: "docker ps | grep mine | 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 01:57:29 +01:00
|
|
|
- name: Pause a few moments because docker is not reliable
|
|
|
|
pause:
|
|
|
|
seconds: 40
|
|
|
|
|
2015-03-18 20:15:42 +01: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:57:29 +01:00
|
|
|
- name: Remove containers
|
|
|
|
shell: "docker rm $(docker ps -aq)"
|
|
|
|
|
|
|
|
- name: Remove all images from the local docker
|
|
|
|
shell: "docker rmi -f $(docker images -q)"
|
2015-03-18 20:15:42 +01:00
|
|
|
|
|
|
|
- name: Remove domain name to hosts
|
|
|
|
lineinfile:
|
|
|
|
line: "127.0.0.1 dockertest.ansible.com"
|
|
|
|
dest: /etc/hosts
|
|
|
|
state: absent
|