Skip to content

Commit a037a69

Browse files
author
Christopher M. Neill
committed
winner winner chicken dinner
1 parent b9ce1b5 commit a037a69

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
IMAGE_NAME="$1"
4+
RUNNING_CONTAINERS=""
5+
6+
CONTAINERS=`docker ps | grep -v '^CONTAINER' | awk '{print $1}'`
7+
8+
if [ "" = "${CONTAINERS}" ] ; then
9+
exit 0
10+
else
11+
for container in ${CONTAINERS} ; do
12+
docker inspect ${container} | grep -q ${IMAGE_NAME}
13+
if [ ${?} -eq 0 ] ; then
14+
RUNNING_CONTAINERS="${container} "
15+
fi
16+
done
17+
fi
18+
19+
echo "${RUNNING_CONTAINERS}"

ansible/roles/container_kill_start/tasks/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@
1313
shell: sudo docker rm {{ item }}
1414
with_items: stopped_containers.stdout_lines
1515

16+
# copy findTagRunning.sh
17+
- name: "copy find running containers with this image tag util script"
18+
sudo: yes
19+
copy:
20+
src=findTagRunning.sh
21+
dest=/root/findTagRunning.sh
22+
mode=0700
23+
1624
# get current running container with this image
1725
- name: "look for running containers running {{ container_image }}"
18-
shell: "sudo docker ps | grep -v '^CONTAINER' | awk '{print $1,$2}' | grep -e {{ container_image }} -v -e ':'|awk -F' ' '{print $1}'"
26+
#shell: "sudo docker ps | grep -v '^CONTAINER' | awk '{print $1,$2}' | grep -e {{ container_image }} -v -e ':'|awk -F' ' '{print $1}'"
27+
sudo: yes
28+
shell: "/root/findTagRunning.sh {{ container_image }}"
1929
register: old_containers_id
2030
changed_when: old_containers_id.stdout != ''
2131

0 commit comments

Comments
 (0)