-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.yml
34 lines (29 loc) · 1.1 KB
/
main.yml
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
31
32
33
34
---
- name: Restart Containers
hosts: all
become: true
gather_facts: true
# vars_files:
# ./vars/vars.yml
tasks:
- name: Get running containers
community.docker.docker_host_info:
containers: true
register: pre_restart
- name: Show Number of containers running
ansible.builtin.debug:
msg: "Hostname - {{ pre_restart.host_info.Name }} has {{ pre_restart.host_info.ContainersRunning }} Containers "
- name: Restart containers
community.docker.docker_container:
name: "{{ item }}"
state: started
restart: true
loop: "{{ pre_restart.containers | map(attribute='Id') | list }}"
- name: Get running containers
community.docker.docker_host_info:
containers: true
register: post_restart
- name: Compare Pre - Post Containers
ansible.builtin.debug:
msg: "Pre-reboot Containers {{ pre_restart.host_info.ContainersRunning }} - Post-reboot Containers {{ post_restart.host_info.ContainersRunning }}"
failed_when: pre_restart.host_info.ContainersRunning != post_restart.host_info.ContainersRunning