ansible all  -m shell -a "docker ps -a --format \" '{{ '{{'}}.Image{{ '}}' }}'|'{{ '{{'}}.Names{{ '}}' }}'|'{{ '{{'}}.Status{{ '}}' }}'|'{{ '{{'}}.CreatedAt{{ '}}' }}'\""

直接扔上命令,输出docker各容器的状态,其中双花括号需要转义见文章:https://blog.csdn.net/michaelwoshi/article/details/107967540

原始命令为:

docker ps -a --format "table {{.Image}}|{{.Names}}|{{.Status}}"

其中format 可输出不同的数据

-format="TEMPLATE"
Pretty-print containers using a Go template.
Valid placeholders:
.ID - Container ID
.Image - Image ID
.Command - Quoted command
.CreatedAt - Time when the container was created.
.RunningFor - Elapsed time since the container was started.
.Ports - Exposed ports.
.Status - Container status.
.Size - Container disk size.
.Names - Container names.
.Labels - All labels assigned to the container.
.Label - Value of a specific label for this container. For example {{.Label "com.docker.swarm.cpu"}}
.Mounts - Names of the volumes mounted in this container.

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐