|
1 | | -- name: "look for stopped {{ container_image }} containers" |
| 1 | +- name: look for stopped {{ container_image }} containers |
2 | 2 | tags: deploy |
| 3 | + become: yes |
3 | 4 | shell: > |
4 | | - sudo docker ps -a | |
| 5 | + docker ps -a | |
5 | 6 | grep Exited | |
6 | 7 | grep {{ container_image }} | |
7 | 8 | awk '{print $1}' |
8 | 9 | register: stopped_containers |
9 | 10 | changed_when: stopped_containers.stdout != '' |
10 | 11 |
|
11 | | -- name: "removed stopped {{ container_image }} containers" |
| 12 | +- name: removed stopped {{ container_image }} containers |
12 | 13 | tags: deploy |
| 14 | + become: yes |
13 | 15 | when: stopped_containers.changed |
14 | | - shell: sudo docker rm {{ item }} |
15 | | - with_items: stopped_containers.stdout_lines |
| 16 | + shell: docker rm {{ item }} |
| 17 | + with_items: "{{ stopped_containers.stdout_lines }}" |
16 | 18 |
|
17 | 19 | # get current running container with this image |
18 | | -- name: "look for running containers running {{ container_image }}" |
| 20 | +- name: look for running containers running {{ container_image }} |
19 | 21 | tags: deploy |
20 | 22 | become: true |
21 | 23 | script: findTagRunning.sh {{ container_image }} |
|
24 | 26 |
|
25 | 27 | # get latest image |
26 | 28 | # tag will default to latest |
27 | | -- name: "pull down docker image {{ container_image }}:{{ container_tag }}" |
| 29 | +- name: pull down docker image {{ container_image }}:{{ container_tag }} |
28 | 30 | tags: deploy |
29 | | - command: sudo docker pull {{ container_image }}:{{ container_tag }} |
| 31 | + become: yes |
| 32 | + command: docker pull {{ container_image }}:{{ container_tag }} |
30 | 33 | when: not do_not_push |
31 | 34 |
|
32 | 35 | # get id of new image |
33 | 36 | - name: get id of the docker image |
34 | 37 | tags: deploy |
| 38 | + become: yes |
35 | 39 | shell: > |
36 | | - sudo docker images |
| 40 | + docker images |
37 | 41 | --no-trunc | |
38 | 42 | grep {{ container_image }}.*{{ container_tag }} | |
39 | 43 | awk '{print $3}' |
|
43 | 47 | - name: stop old containers |
44 | 48 | tags: deploy |
45 | 49 | when: old_containers_id.changed |
46 | | - command: sudo docker stop -t {{ stop_time }} {{ item }} |
47 | | - with_items: old_containers_id.stdout_lines |
| 50 | + become: yes |
| 51 | + command: docker stop -t {{ stop_time }} {{ item }} |
| 52 | + with_items: "{{ old_containers_id.stdout_lines }}" |
48 | 53 |
|
49 | 54 | # remove the old containers that were running previously |
50 | 55 | - name: remove old containers |
51 | 56 | tags: deploy |
52 | 57 | when: old_containers_id.changed |
53 | | - command: sudo docker rm {{ item }} |
54 | | - with_items: old_containers_id.stdout_lines |
| 58 | + become: yes |
| 59 | + command: docker rm {{ item }} |
| 60 | + with_items: "{{ old_containers_id.stdout_lines }}" |
55 | 61 |
|
56 | 62 | - name: pause to allow for any odd conditions in system caching tables |
57 | 63 | tags: deploy |
58 | 64 | when: pause_length_minutes is defined and old_containers_id.changed |
59 | | - pause: minutes={{pause_length_minutes}} |
| 65 | + pause: minutes={{ pause_length_minutes }} |
60 | 66 |
|
61 | 67 | # start our new container with options and args |
62 | 68 | - name: start container |
63 | 69 | tags: deploy |
| 70 | + become: yes |
64 | 71 | command: > |
65 | | - sudo docker run |
| 72 | + docker run |
66 | 73 | --log-driver={{ log_driver }} |
67 | 74 | --log-opt syslog-facility={{ log_facility }} |
68 | 75 | --log-opt tag="{{ log_tag | default ( name ) }}" |
69 | 76 | -v {{ app_log_dir }}:{{ app_log_dir }}:rw |
70 | 77 | --restart={{ restart_policy | default('always') }} |
71 | | - {{ container_run_opts}} |
| 78 | + {{ container_run_opts }} |
72 | 79 | {{ container_image }}:{{ container_tag }} |
73 | 80 | {{ container_run_args }} |
74 | 81 | register: new_container_id |
|
0 commit comments