My requirement is I want to run apt-get update and apt-get upgrade, and then I want to print the containers and their status.
Below is my code.
I want to list all the containers with their status(Running/Exited)
Print the value (debug) as a list. Here I have a seperate debug for each value
---
- name: 'Run sudo apt update'
hosts: myhost
become: yes
tasks:
- name: 'Run the equivalent of "apt-get update" as a separate step'
ansible.builtin.apt:
update_cache: yes
upgrade: yes
- name: Get info on docker host
community.docker.docker_host_info:
register: result
- name: Get info on docker host and list images
community.docker.docker_host_info:
images: true
register: result
- debug:
var: result.host_info.Containers
- debug:
var: result.host_info.ContainersRunning
- debug:
var: result.host_info.ContainersStopped
That is working thanks, but little modification, It is printing the item details also, which is making difficult to read the exact msg. Below is the exact output…
Expected:
"msg": "Name: /containername - Status: Up 9 hours"