实例学习ansible系列(12)常用模块之docker

知识点:ansible使用docker可以对其进行管理。基本接近docker-compose对docker的使用支持,非常接近。诸如从port的设定到volume_from都支持,但是需要docker-py0.3.0 以上的支持。

使用前提条件

需要使用docker的module的管理对象节点需要满足如下前提

Package 所需版本
python 2.6 以上
docker-py 0.3.0 以上
docker server 0.10.0 以上

安装docker-py

一般python等基本上无需意识,一般安装了docker-py本模块就能支持。

安装步骤
[root@host32 ~]# yum -y python-pip
[root@host31 ~]# yum -y install python-pip
[root@host31 ~]# pip install docker-py

使用docker模块启动container

事前确认

[root@host31 ~]# ansible host32 -m shell -a "docker images && docker ps -a"
host32 | SUCCESS | rc=0 >>
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/jenkins   latest              b4974ba62598        2 weeks ago         741 MB
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@host31 ~]#

启动container

[root@host31 ~]# ansible host32 -m docker -a "image=docker.io/jenkins ports=8080:8080"
host32 | SUCCESS => {
    "ansible_facts": {
        "docker_containers": [
            {
                "AppArmorProfile": "",
                "Args": [
                    "--",
                    "/usr/local/bin/jenkins.sh"
                ],
                "Config": {
                    "AttachStderr": false,
                    "AttachStdin": false,
                    "AttachStdout": false,
                    "Cmd": null,
                    "Domainname": "",
                    "Entrypoint": [
                        "/bin/tini",
                        "--",
                        "/usr/local/bin/jenkins.sh"
                    ],
                    "Env": [
                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                        "LANG=C.UTF-8",
                        "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64",
                        "JAVA_VERSION=8u91",
                        "JAVA_DEBIAN_VERSION=8u91-b14-1~bpo8+1",
                        "CA_CERTIFICATES_JAVA_VERSION=20140324",
                        "JENKINS_HOME=/var/jenkins_home",
                        "JENKINS_SLAVE_AGENT_PORT=50000",
                        "TINI_VERSION=0.9.0",
                        "TINI_SHA=fa23d1e20732501c3bb8eeeca423c89ac80ed452",
                        "JENKINS_VERSION=2.7.1",
                        "JENKINS_SHA=12d820574c8f586f7d441986dd53bcfe72b95453",
                        "JENKINS_UC=https://updates.jenkins.io",
                        "COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"
                    ],
                    "ExposedPorts": {
                        "50000/tcp": {},
                        "8080/tcp": {}
                    },
                    "Hostname": "283789b73a8e",
                    "Image": "docker.io/jenkins",
                    "Labels": {},
                    "OnBuild": null,
                    "OpenStdin": false,
                    "StdinOnce": false,
                    "Tty": false,
                    "User": "jenkins",
                    "Volumes": {
                        "/var/jenkins_home": {}
                    },
                    "WorkingDir": ""
                },
                "Created": "2016-07-31T03:03:38.350849615Z",
                "Driver": "devicemapper",
                "ExecIDs": null,
                "GraphDriver": {
                    "Data": {
                        "DeviceId": "25",
                        "DeviceName": "docker-253:0-19943542-b5917ff17a3050352a5cf430fa1449362166da5142d76e931553119acb600654",
                        "DeviceSize": "10737418240"
                    },
                    "Name": "devicemapper"
                },
                "HostConfig": {
                    "Binds": null,
                    "BlkioDeviceReadBps": null,
                    "BlkioDeviceReadIOps": null,
                    "BlkioDeviceWriteBps": null,
                    "BlkioDeviceWriteIOps": null,
                    "BlkioWeight": 0,
                    "BlkioWeightDevice": null,
                    "CapAdd": null,
                    "CapDrop": null,
                    "CgroupParent": "",
                    "ConsoleSize": [
                        0,
                        0
                    ],
                    "ContainerIDFile": "",
                    "CpuPeriod": 0,
                    "CpuQuota": 0,
                    "CpuShares": 0,
                    "CpusetCpus": "",
                    "CpusetMems": "",
                    "Devices": null,
                    "Dns": null,
                    "DnsOptions": null,
                    "DnsSearch": null,
                    "ExtraHosts": null,
                    "GroupAdd": null,
                    "IpcMode": "",
                    "Isolation": "",
                    "KernelMemory": 0,
                    "Links": null,
                    "LogConfig": {
                        "Config": {},
                        "Type": "journald"
                    },
                    "Memory": 0,
                    "MemoryReservation": 0,
                    "MemorySwap": 0,
                    "MemorySwappiness": -1,
                    "NetworkMode": "default",
                    "OomKillDisable": false,
                    "OomScoreAdj": 0,
                    "PidMode": "",
                    "PidsLimit": 0,
                    "PortBindings": {
                        "8080/tcp": [
                            {
                                "HostIp": "0.0.0.0",
                                "HostPort": "8080"
                            }
                        ]
                    },
                    "Privileged": false,
                    "PublishAllPorts": false,
                    "ReadonlyRootfs": false,
                    "RestartPolicy": {
                        "MaximumRetryCount": 0,
                        "Name": ""
                    },
                    "SecurityOpt": null,
                    "ShmSize": 67108864,
                    "UTSMode": "",
                    "Ulimits": null,
                    "VolumeDriver": "",
                    "VolumesFrom": null
                },
                "HostnamePath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hostname",
                "HostsPath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hosts",
                "Id": "283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955",
                "Image": "sha256:b4974ba625983cc1250f3399a262d98398b914ff04d2ba360760b81d1c944983",
                "LogPath": "",
                "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c122,c287",
                "Mounts": [
                    {
                        "Destination": "/var/jenkins_home",
                        "Driver": "local",
                        "Mode": "",
                        "Name": "2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f",
                        "Propagation": "",
                        "RW": true,
                        "Source": "/var/lib/docker/volumes/2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f/_data"
                    }
                ],
                "Name": "/goofy_spence",
                "NetworkSettings": {
                    "Bridge": "",
                    "EndpointID": "45fde805822822b90f6e8fabe865ae0ab7faa39ca9e1624e6dea614d4403a6e8",
                    "Gateway": "172.16.96.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "HairpinMode": false,
                    "IPAddress": "172.16.96.2",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "LinkLocalIPv6Address": "",
                    "LinkLocalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:10:60:02",
                    "Networks": {
                        "bridge": {
                            "Aliases": null,
                            "EndpointID": "45fde805822822b90f6e8fabe865ae0ab7faa39ca9e1624e6dea614d4403a6e8",
                            "Gateway": "172.16.96.1",
                            "GlobalIPv6Address": "",
                            "GlobalIPv6PrefixLen": 0,
                            "IPAMConfig": null,
                            "IPAddress": "172.16.96.2",
                            "IPPrefixLen": 24,
                            "IPv6Gateway": "",
                            "Links": null,
                            "MacAddress": "02:42:ac:10:60:02",
                            "NetworkID": "320ec600e4605955d8d83b717a5177b2eaf81c97615af4dc606cba34f3952b29"
                        }
                    },
                    "Ports": {
                        "50000/tcp": null,
                        "8080/tcp": [
                            {
                                "HostIp": "0.0.0.0",
                                "HostPort": "8080"
                            }
                        ]
                    },
                    "SandboxID": "8ebecd9887e411a4294a57e50da61c0e669dddaf193cebc0c2fe0c5a523df0e2",
                    "SandboxKey": "/var/run/docker/netns/8ebecd9887e4",
                    "SecondaryIPAddresses": null,
                    "SecondaryIPv6Addresses": null
                },
                "Path": "/bin/tini",
                "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c122,c287",
                "ResolvConfPath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/resolv.conf",
                "RestartCount": 0,
                "State": {
                    "Dead": false,
                    "Error": "",
                    "ExitCode": 0,
                    "FinishedAt": "0001-01-01T00:00:00Z",
                    "OOMKilled": false,
                    "Paused": false,
                    "Pid": 30604,
                    "Restarting": false,
                    "Running": true,
                    "StartedAt": "2016-07-31T03:03:39.630193596Z",
                    "Status": "running"
                }
            }
        ]
    },
    "changed": true,
    "msg": "started 1 container, created 1 container.",
    "reload_reasons": null,
    "summary": {
        "created": 1,
        "killed": 0,
        "pulled": 0,
        "removed": 0,
        "restarted": 0,
        "started": 1,
        "stopped": 0
    }
}
[root@host31 ~]#

确认结果

[root@host31 ~]# ansible host32 -m shell -a "docker images && docker ps -a"
host32 | SUCCESS | rc=0 >>
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/jenkins   latest              b4974ba62598        2 weeks ago         741 MB
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
283789b73a8e        docker.io/jenkins   "/bin/tini -- /usr/lo"   3 minutes ago       Up 3 minutes        0.0.0.0:8080->8080/tcp, 50000/tcp   goofy_spence

[root@host31 ~]#

实例学习ansible系列(12)常用模块之docker_第1张图片

停止container

实现docker stop 的操作

[root@host31 ~]# ansible host32 -m docker -a "image=docker.io/jenkins state=stopped"
host32 | SUCCESS => {
    "ansible_facts": {
        "docker_containers": [
            {
                "AppArmorProfile": "",
                "Args": [
                    "--",
                    "/usr/local/bin/jenkins.sh"
                ],
                "Config": {
                    "AttachStderr": false,
                    "AttachStdin": false,
                    "AttachStdout": false,
                    "Cmd": null,
                    "Domainname": "",
                    "Entrypoint": [
                        "/bin/tini",
                        "--",
                        "/usr/local/bin/jenkins.sh"
                    ],
                    "Env": [
                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                        "LANG=C.UTF-8",
                        "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64",
                        "JAVA_VERSION=8u91",
                        "JAVA_DEBIAN_VERSION=8u91-b14-1~bpo8+1",
                        "CA_CERTIFICATES_JAVA_VERSION=20140324",
                        "JENKINS_HOME=/var/jenkins_home",
                        "JENKINS_SLAVE_AGENT_PORT=50000",
                        "TINI_VERSION=0.9.0",
                        "TINI_SHA=fa23d1e20732501c3bb8eeeca423c89ac80ed452",
                        "JENKINS_VERSION=2.7.1",
                        "JENKINS_SHA=12d820574c8f586f7d441986dd53bcfe72b95453",
                        "JENKINS_UC=https://updates.jenkins.io",
                        "COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"
                    ],
                    "ExposedPorts": {
                        "50000/tcp": {},
                        "8080/tcp": {}
                    },
                    "Hostname": "283789b73a8e",
                    "Image": "docker.io/jenkins",
                    "Labels": {},
                    "OnBuild": null,
                    "OpenStdin": false,
                    "StdinOnce": false,
                    "Tty": false,
                    "User": "jenkins",
                    "Volumes": {
                        "/var/jenkins_home": {}
                    },
                    "WorkingDir": ""
                },
                "Created": "2016-07-31T03:03:38.350849615Z",
                "Driver": "devicemapper",
                "ExecIDs": null,
                "GraphDriver": {
                    "Data": {
                        "DeviceId": "25",
                        "DeviceName": "docker-253:0-19943542-b5917ff17a3050352a5cf430fa1449362166da5142d76e931553119acb600654",
                        "DeviceSize": "10737418240"
                    },
                    "Name": "devicemapper"
                },
                "HostConfig": {
                    "Binds": null,
                    "BlkioDeviceReadBps": null,
                    "BlkioDeviceReadIOps": null,
                    "BlkioDeviceWriteBps": null,
                    "BlkioDeviceWriteIOps": null,
                    "BlkioWeight": 0,
                    "BlkioWeightDevice": null,
                    "CapAdd": null,
                    "CapDrop": null,
                    "CgroupParent": "",
                    "ConsoleSize": [
                        0,
                        0
                    ],
                    "ContainerIDFile": "",
                    "CpuPeriod": 0,
                    "CpuQuota": 0,
                    "CpuShares": 0,
                    "CpusetCpus": "",
                    "CpusetMems": "",
                    "Devices": null,
                    "Dns": null,
                    "DnsOptions": null,
                    "DnsSearch": null,
                    "ExtraHosts": null,
                    "GroupAdd": null,
                    "IpcMode": "",
                    "Isolation": "",
                    "KernelMemory": 0,
                    "Links": null,
                    "LogConfig": {
                        "Config": {},
                        "Type": "journald"
                    },
                    "Memory": 0,
                    "MemoryReservation": 0,
                    "MemorySwap": 0,
                    "MemorySwappiness": -1,
                    "NetworkMode": "default",
                    "OomKillDisable": false,
                    "OomScoreAdj": 0,
                    "PidMode": "",
                    "PidsLimit": 0,
                    "PortBindings": {
                        "8080/tcp": [
                            {
                                "HostIp": "0.0.0.0",
                                "HostPort": "8080"
                            }
                        ]
                    },
                    "Privileged": false,
                    "PublishAllPorts": false,
                    "ReadonlyRootfs": false,
                    "RestartPolicy": {
                        "MaximumRetryCount": 0,
                        "Name": ""
                    },
                    "SecurityOpt": null,
                    "ShmSize": 67108864,
                    "UTSMode": "",
                    "Ulimits": null,
                    "VolumeDriver": "",
                    "VolumesFrom": null
                },
                "HostnamePath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hostname",
                "HostsPath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hosts",
                "Id": "283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955",
                "Image": "sha256:b4974ba625983cc1250f3399a262d98398b914ff04d2ba360760b81d1c944983",
                "LogPath": "",
                "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c122,c287",
                "Mounts": [
                    {
                        "Destination": "/var/jenkins_home",
                        "Driver": "local",
                        "Mode": "",
                        "Name": "2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f",
                        "Propagation": "",
                        "RW": true,
                        "Source": "/var/lib/docker/volumes/2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f/_data"
                    }
                ],
                "Name": "/goofy_spence",
                "NetworkSettings": {
                    "Bridge": "",
                    "EndpointID": "",
                    "Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "HairpinMode": false,
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "LinkLocalIPv6Address": "",
                    "LinkLocalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "Networks": {
                        "bridge": {
                            "Aliases": null,
                            "EndpointID": "",
                            "Gateway": "",
                            "GlobalIPv6Address": "",
                            "GlobalIPv6PrefixLen": 0,
                            "IPAMConfig": null,
                            "IPAddress": "",
                            "IPPrefixLen": 0,
                            "IPv6Gateway": "",
                            "Links": null,
                            "MacAddress": "",
                            "NetworkID": "320ec600e4605955d8d83b717a5177b2eaf81c97615af4dc606cba34f3952b29"
                        }
                    },
                    "Ports": null,
                    "SandboxID": "8ebecd9887e411a4294a57e50da61c0e669dddaf193cebc0c2fe0c5a523df0e2",
                    "SandboxKey": "/var/run/docker/netns/8ebecd9887e4",
                    "SecondaryIPAddresses": null,
                    "SecondaryIPv6Addresses": null
                },
                "Path": "/bin/tini",
                "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c122,c287",
                "ResolvConfPath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/resolv.conf",
                "RestartCount": 0,
                "State": {
                    "Dead": false,
                    "Error": "",
                    "ExitCode": 143,
                    "FinishedAt": "2016-07-31T03:10:05.113884817Z",
                    "OOMKilled": false,
                    "Paused": false,
                    "Pid": 0,
                    "Restarting": false,
                    "Running": false,
                    "StartedAt": "2016-07-31T03:03:39.630193596Z",
                    "Status": "exited"
                }
            }
        ]
    },
    "changed": true,
    "msg": "stopped 1 container.",
    "reload_reasons": null,
    "summary": {
        "created": 0,
        "killed": 0,
        "pulled": 0,
        "removed": 0,
        "restarted": 0,
        "started": 0,
        "stopped": 1
    }
}
[root@host31 ~]#

停止确认

[root@host31 ~]# ansible host32 -m shell -a "docker images && docker ps"
host32 | SUCCESS | rc=0 >>
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/jenkins   latest              b4974ba62598        2 weeks ago         741 MB
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@host31 ~]#
[root@host31 ~]# ansible host32 -m shell -a "docker ps -a"
host32 | SUCCESS | rc=0 >>
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                            PORTS               NAMES
283789b73a8e        docker.io/jenkins   "/bin/tini -- /usr/lo"   7 minutes ago       Exited (143) About a minute ago                       goofy_spence

[root@host31 ~]#

删除container

实现docker rm的操作

[root@host31 ~]# ansible host32 -m shell -a "docker ps -a"
host32 | SUCCESS | rc=0 >>
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
283789b73a8e        docker.io/jenkins   "/bin/tini -- /usr/lo"   8 minutes ago       Exited (143) 2 minutes ago                       goofy_spence

[root@host31 ~]#
[root@host31 ~]# ansible host32 -m docker -a "image=docker.io/jenkins state=absent"
host32 | SUCCESS => {
    "ansible_facts": {
        "docker_containers": [
            {
                "AppArmorProfile": "",
                "Args": [
                    "--",
                    "/usr/local/bin/jenkins.sh"
                ],
                "Config": {
                    "AttachStderr": false,
                    "AttachStdin": false,
                    "AttachStdout": false,
                    "Cmd": null,
                    "Domainname": "",
                    "Entrypoint": [
                        "/bin/tini",
                        "--",
                        "/usr/local/bin/jenkins.sh"
                    ],
                    "Env": [
                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                        "LANG=C.UTF-8",
                        "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64",
                        "JAVA_VERSION=8u91",
                        "JAVA_DEBIAN_VERSION=8u91-b14-1~bpo8+1",
                        "CA_CERTIFICATES_JAVA_VERSION=20140324",
                        "JENKINS_HOME=/var/jenkins_home",
                        "JENKINS_SLAVE_AGENT_PORT=50000",
                        "TINI_VERSION=0.9.0",
                        "TINI_SHA=fa23d1e20732501c3bb8eeeca423c89ac80ed452",
                        "JENKINS_VERSION=2.7.1",
                        "JENKINS_SHA=12d820574c8f586f7d441986dd53bcfe72b95453",
                        "JENKINS_UC=https://updates.jenkins.io",
                        "COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"
                    ],
                    "ExposedPorts": {
                        "50000/tcp": {},
                        "8080/tcp": {}
                    },
                    "Hostname": "283789b73a8e",
                    "Image": "docker.io/jenkins",
                    "Labels": {},
                    "OnBuild": null,
                    "OpenStdin": false,
                    "StdinOnce": false,
                    "Tty": false,
                    "User": "jenkins",
                    "Volumes": {
                        "/var/jenkins_home": {}
                    },
                    "WorkingDir": ""
                },
                "Created": "2016-07-31T03:03:38.350849615Z",
                "Driver": "devicemapper",
                "ExecIDs": null,
                "GraphDriver": {
                    "Data": {
                        "DeviceId": "25",
                        "DeviceName": "docker-253:0-19943542-b5917ff17a3050352a5cf430fa1449362166da5142d76e931553119acb600654",
                        "DeviceSize": "10737418240"
                    },
                    "Name": "devicemapper"
                },
                "HostConfig": {
                    "Binds": null,
                    "BlkioDeviceReadBps": null,
                    "BlkioDeviceReadIOps": null,
                    "BlkioDeviceWriteBps": null,
                    "BlkioDeviceWriteIOps": null,
                    "BlkioWeight": 0,
                    "BlkioWeightDevice": null,
                    "CapAdd": null,
                    "CapDrop": null,
                    "CgroupParent": "",
                    "ConsoleSize": [
                        0,
                        0
                    ],
                    "ContainerIDFile": "",
                    "CpuPeriod": 0,
                    "CpuQuota": 0,
                    "CpuShares": 0,
                    "CpusetCpus": "",
                    "CpusetMems": "",
                    "Devices": null,
                    "Dns": null,
                    "DnsOptions": null,
                    "DnsSearch": null,
                    "ExtraHosts": null,
                    "GroupAdd": null,
                    "IpcMode": "",
                    "Isolation": "",
                    "KernelMemory": 0,
                    "Links": null,
                    "LogConfig": {
                        "Config": {},
                        "Type": "journald"
                    },
                    "Memory": 0,
                    "MemoryReservation": 0,
                    "MemorySwap": 0,
                    "MemorySwappiness": -1,
                    "NetworkMode": "default",
                    "OomKillDisable": false,
                    "OomScoreAdj": 0,
                    "PidMode": "",
                    "PidsLimit": 0,
                    "PortBindings": {
                        "8080/tcp": [
                            {
                                "HostIp": "0.0.0.0",
                                "HostPort": "8080"
                            }
                        ]
                    },
                    "Privileged": false,
                    "PublishAllPorts": false,
                    "ReadonlyRootfs": false,
                    "RestartPolicy": {
                        "MaximumRetryCount": 0,
                        "Name": ""
                    },
                    "SecurityOpt": null,
                    "ShmSize": 67108864,
                    "UTSMode": "",
                    "Ulimits": null,
                    "VolumeDriver": "",
                    "VolumesFrom": null
                },
                "HostnamePath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hostname",
                "HostsPath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hosts",
                "Id": "283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955",
                "Image": "sha256:b4974ba625983cc1250f3399a262d98398b914ff04d2ba360760b81d1c944983",
                "LogPath": "",
                "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c122,c287",
                "Mounts": [
                    {
                        "Destination": "/var/jenkins_home",
                        "Driver": "local",
                        "Mode": "",
                        "Name": "2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f",
                        "Propagation": "",
                        "RW": true,
                        "Source": "/var/lib/docker/volumes/2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f/_data"
                    }
                ],
                "Name": "/goofy_spence",
                "NetworkSettings": {
                    "Bridge": "",
                    "EndpointID": "",
                    "Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "HairpinMode": false,
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "LinkLocalIPv6Address": "",
                    "LinkLocalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "Networks": {
                        "bridge": {
                            "Aliases": null,
                            "EndpointID": "",
                            "Gateway": "",
                            "GlobalIPv6Address": "",
                            "GlobalIPv6PrefixLen": 0,
                            "IPAMConfig": null,
                            "IPAddress": "",
                            "IPPrefixLen": 0,
                            "IPv6Gateway": "",
                            "Links": null,
                            "MacAddress": "",
                            "NetworkID": "320ec600e4605955d8d83b717a5177b2eaf81c97615af4dc606cba34f3952b29"
                        }
                    },
                    "Ports": null,
                    "SandboxID": "8ebecd9887e411a4294a57e50da61c0e669dddaf193cebc0c2fe0c5a523df0e2",
                    "SandboxKey": "/var/run/docker/netns/8ebecd9887e4",
                    "SecondaryIPAddresses": null,
                    "SecondaryIPv6Addresses": null
                },
                "Path": "/bin/tini",
                "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c122,c287",
                "ResolvConfPath": "/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/resolv.conf",
                "RestartCount": 0,
                "State": {
                    "Dead": false,
                    "Error": "",
                    "ExitCode": 143,
                    "FinishedAt": "2016-07-31T03:10:05.113884817Z",
                    "OOMKilled": false,
                    "Paused": false,
                    "Pid": 0,
                    "Restarting": false,
                    "Running": false,
                    "StartedAt": "2016-07-31T03:03:39.630193596Z",
                    "Status": "exited"
                }
            }
        ]
    },
    "changed": true,
    "msg": "removed 1 container.",
    "reload_reasons": null,
    "summary": {
        "created": 0,
        "killed": 0,
        "pulled": 0,
        "removed": 1,
        "restarted": 0,
        "started": 0,
        "stopped": 0
    }
}
[root@host31 ~]#
[root@host31 ~]# ansible host32 -m shell -a "docker ps -a"
host32 | SUCCESS | rc=0 >>
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@host31 ~]#

你可能感兴趣的:(#,实例学习Ansible系列)