-
Notifications
You must be signed in to change notification settings - Fork 80
/
deploy_container.yaml
30 lines (28 loc) · 971 Bytes
/
deploy_container.yaml
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
---
- hosts: "{{hostname}}"
become: true
vars:
- create_containers: 3
- default_container_name: my_website
- default_container_image: vistasunil/devopsdemo:latest
- container_port: "8"
tasks:
# delete the old version containers
- name: Delete old containers
docker_container:
name: "{{ default_container_name }}{{ item }}"
state: absent
with_sequence: count={{ create_containers }}
- name: Wait for cleanup
shell: sleep 30
# Creates the number of containers defined by the variable create_containers, using values from vars file
- name: Create default containers
docker_container:
name: "{{ default_container_name }}{{ item }}"
image: "{{ default_container_image }}"
state: started
exposed:
- "{{ container_port }}{{ item }}"
ports:
- "{{ container_port }}{{ item }}:80"
with_sequence: count={{ create_containers }}