只是花了点时间给你看看我能不能弄明白。下面的剧本是我为你准备的,很有用。虽然它与您的原始代码有点不同。但我只是想和你分享一下,看看这对你是否有帮助。
- hosts: test_nodes
vars:
_docker_version: 17.12.0
tasks:
- group:
name: docker
state: present
become: true
- name: Setting HOME Directory Path
set_fact:
_home: "{{ ansible_env['HOME'] }}"
- name: Fetch docker version
shell: docker version 2>&1 | grep Version | awk '{print $2}'
register: docker_version
- name: Check if docker is installed, download binary otherwise
get_url:
url: "https://download.docker.com/linux/static/stable/x86_64/docker-{{ _docker_version }}-ce.tgz"
dest: "{{ _home }}"
when: docker_version.stdout == ''
- name: Extract binary
unarchive:
src: "{{ _home }}/docker-{{ _docker_version }}-ce.tgz"
dest: "{{ _home }}/"
remote_src: yes
creates: "{{ _home }}/docker/dockerd"
when: docker_version.stdout == ''
- name: Copy Docker Binaries to /usr/bin
shell: cp {{ _home }}/docker/docker* /usr/bin/
args:
creates: /usr/bin/docker
become: true
- name: start docker
shell: dockerd &
become: true
args:
creates: /var/run/docker.pid
register: tmp
- name: Debug
debug:
var: tmp
其结果如下:
TASK [start docker] ************************************************************************************************************************************************************
Sunday 18 February 2018 01:25:17 -0500 (0:00:00.492) 0:00:09.419 *******
changed: [node0]
TASK [Debug] *******************************************************************************************************************************************************************
Sunday 18 February 2018 01:25:19 -0500 (0:00:01.357) 0:00:10.776 *******
ok: [node0] => {
"tmp": {
"changed": true,
"cmd": "dockerd &",
"delta": "0:00:01.135519",
"end": "2018-02-18 01:25:19.879137",
"failed": false,
"rc": 0,
"start": "2018-02-18 01:25:18.743618",
"stderr": "time=\"2018-02-18T01:25:18.758962434-05:00\" level=info msg=\"libcontainerd: started new docker-containerd process\" pid=20346\ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"starting containerd\" module=containerd revision=89623f28b87a6004d4b785663257362d1658a729 version=v1.0.0 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"setting subreaper...\" module=containerd \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"changing OOM score to -500\" module=containerd \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.content.v1.content\"...\" module=containerd type=io.containerd.content.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.snapshotter.v1.btrfs\"...\" module=containerd type=io.containerd.snapshotter.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=warning msg=\"failed to load plugin io.containerd.snapshotter.v1.btrfs\" error=\"path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter\" module=containerd \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.snapshotter.v1.overlayfs\"...\" module=containerd type=io.containerd.snapshotter.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.metadata.v1.bolt\"...\" module=containerd type=io.containerd.metadata.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=warning msg=\"could not use snapshotter btrfs in metadata plugin\" error=\"path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter\" module=\"containerd/io.containerd.metadata.v1.bolt\" \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.differ.v1.walking\"...\" module=containerd type=io.containerd.differ.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.gc.v1.scheduler\"...\" module=containerd type=io.containerd.gc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.containers\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.content\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.diff\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.events\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.healthcheck\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.images\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.leases\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.namespaces\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.snapshots\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.monitor.v1.cgroups\"...\" module=containerd type=io.containerd.monitor.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.runtime.v1.linux\"...\" module=containerd type=io.containerd.runtime.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.tasks\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.version\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.introspection\"...\" module=containerd type=io.containerd.grpc.v1 \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=serving... address=\"/var/run/docker/containerd/docker-containerd-debug.sock\" module=\"containerd/debug\" \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=serving... address=\"/var/run/docker/containerd/docker-containerd.sock\" module=\"containerd/grpc\" \ntime=\"2018-02-18T01:25:18-05:00\" level=info msg=\"containerd successfully booted in 0.002771s\" module=containerd \ntime=\"2018-02-18T01:25:18.775686433-05:00\" level=info msg=\"[graphdriver] using prior storage driver: overlay2\"\ntime=\"2018-02-18T01:25:18.780002053-05:00\" level=info msg=\"Graph migration to content-addressability took 0.00 seconds\"\ntime=\"2018-02-18T01:25:18.780501640-05:00\" level=info msg=\"Loading containers: start.\"\ntime=\"2018-02-18T01:25:18.840608687-05:00\" level=info msg=\"Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address\"\ntime=\"2018-02-18T01:25:18.859447845-05:00\" level=info msg=\"Loading containers: done.\"\ntime=\"2018-02-18T01:25:18.863941249-05:00\" level=info msg=\"Docker daemon\" commit=c97c6d6 graphdriver(s)=overlay2 version=17.12.0-ce\ntime=\"2018-02-18T01:25:18.863990869-05:00\" level=info msg=\"Daemon has completed initialization\"\ntime=\"2018-02-18T01:25:18.877109649-05:00\" level=info msg=\"API listen on /var/run/docker.sock\"",
"stderr_lines": [
"time=\"2018-02-18T01:25:18.758962434-05:00\" level=info msg=\"libcontainerd: started new docker-containerd process\" pid=20346",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"starting containerd\" module=containerd revision=89623f28b87a6004d4b785663257362d1658a729 version=v1.0.0 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"setting subreaper...\" module=containerd ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"changing OOM score to -500\" module=containerd ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.content.v1.content\"...\" module=containerd type=io.containerd.content.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.snapshotter.v1.btrfs\"...\" module=containerd type=io.containerd.snapshotter.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=warning msg=\"failed to load plugin io.containerd.snapshotter.v1.btrfs\" error=\"path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter\" module=containerd ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.snapshotter.v1.overlayfs\"...\" module=containerd type=io.containerd.snapshotter.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.metadata.v1.bolt\"...\" module=containerd type=io.containerd.metadata.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=warning msg=\"could not use snapshotter btrfs in metadata plugin\" error=\"path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter\" module=\"containerd/io.containerd.metadata.v1.bolt\" ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.differ.v1.walking\"...\" module=containerd type=io.containerd.differ.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.gc.v1.scheduler\"...\" module=containerd type=io.containerd.gc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.containers\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.content\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.diff\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.events\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.healthcheck\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.images\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.leases\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.namespaces\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.snapshots\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.monitor.v1.cgroups\"...\" module=containerd type=io.containerd.monitor.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.runtime.v1.linux\"...\" module=containerd type=io.containerd.runtime.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.tasks\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.version\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"loading plugin \"io.containerd.grpc.v1.introspection\"...\" module=containerd type=io.containerd.grpc.v1 ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=serving... address=\"/var/run/docker/containerd/docker-containerd-debug.sock\" module=\"containerd/debug\" ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=serving... address=\"/var/run/docker/containerd/docker-containerd.sock\" module=\"containerd/grpc\" ",
"time=\"2018-02-18T01:25:18-05:00\" level=info msg=\"containerd successfully booted in 0.002771s\" module=containerd ",
"time=\"2018-02-18T01:25:18.775686433-05:00\" level=info msg=\"[graphdriver] using prior storage driver: overlay2\"",
"time=\"2018-02-18T01:25:18.780002053-05:00\" level=info msg=\"Graph migration to content-addressability took 0.00 seconds\"",
"time=\"2018-02-18T01:25:18.780501640-05:00\" level=info msg=\"Loading containers: start.\"",
"time=\"2018-02-18T01:25:18.840608687-05:00\" level=info msg=\"Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address\"",
"time=\"2018-02-18T01:25:18.859447845-05:00\" level=info msg=\"Loading containers: done.\"",
"time=\"2018-02-18T01:25:18.863941249-05:00\" level=info msg=\"Docker daemon\" commit=c97c6d6 graphdriver(s)=overlay2 version=17.12.0-ce",
"time=\"2018-02-18T01:25:18.863990869-05:00\" level=info msg=\"Daemon has completed initialization\"",
"time=\"2018-02-18T01:25:18.877109649-05:00\" level=info msg=\"API listen on /var/run/docker.sock\""
],
"stdout": "",
"stdout_lines": []
}
}
PLAY RECAP *********************************************************************************************************************************************************************
node0 : ok=10 changed=5 unreachable=0 failed=0