ansible2.4 can not run dockerd(binary) in backgroud

ANSIBLE VERSION
2.4.1.0
OS / ENVIRONMENT

centos 7 in vagrant

SUMMARY

install docker script

function docker_install() {
echo "docker install"
if [ ${sysOS} == "Linux" ]
then

if [ ! -f /tmp/install_docker_flag ]; then

rm -f /var/run/docker.sock

tar zxvf ${DOCKER_ENGINE_DIR}/${DOCKER_FILE}.tar.gz
mv ${DOCKER_FILE}/* /usr/local/bin

tar zxvf ${DOCKER_ENGINE_DIR}/${DOCKER_COMPOSE_FILE}.tar.gz
mv ${DOCKER_COMPOSE_FILE}/* /usr/local/bin/docker-compose

# echo '{"insecure-registries":["'${PRIVATE_REGISTRY}'"]}' > /etc/docker/daemon.json
mkdir -p /etc/docker
echo '{"registry-mirrors": ["http://'${PRIVATE_REGISTRY}'"], "insecure-registries" : [ "'${PRIVATE_REGISTRY}'"] }' > /etc/docker/daemon.json

rm -fr ${DOCKER_FILE}
rm -fr ${DOCKER_COMPOSE_FILE}

echo 'success' > /tmp/install_docker_flag
else
echo 'already installed docker'
fi

else
echo "this is "${sysOS}
exit 1
fi

}

This just copy dockerd binary to /usr/local/bin

start docker

- name: start docker
shell: /usr/local/bin/dockerd >/dev/null 2>&1 &
# command: sh {{ start_docker_script }}

logs

  1. But script docker load < ${DOCKER_IMAGES_DIR}/${packages['registry']} in TASK [registry : Install registry] , complain docker not found.
  2. After ansible failed, I enter that vm, confirmed dockerd was not running.
  3. I also tried to start dockerd by a script , nether work.
  4. I enter vagrant and have confirmed all files copied successful .
  5. In vagrant vm, directly run /usr/local/bin/dockerd >/dev/null 2>&1 & is working
TASK [common : Install docker] ********************************************************************************
changed: [host02]
changed: [host01]

TASK [common : start docker] **********************************************************************************
changed: [host02]
changed: [host01]

PLAY [registry] ***********************************************************************************************

TASK [Gathering Facts] ****************************************************************************************
ok: [host01]

TASK [registry : Install registry] ****************************************************************************
fatal: [host01]: FAILED! => {
"changed": true,
"cmd": [
"sh",
"/data/bidspy-yychen/dist/scripts/install_registry.sh"
],
"delta": "0:00:00.045283",
"end": "2017-11-10 03:28:33.555247",
"failed": true,
"rc": 125,
"start": "2017-11-10 03:28:33.509964"
}

STDOUT:

/data/bidspy-yychen/dist/scripts
/data/bidspy-yychen/dist

STDERR:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

MSG:

non-zero return code

Your deamon doesn't start, but you're redirecting everything to
/dev/null, which masks any issues.
Try redirecting everything to a log file and examine that.

Dick

log only shows

time="2017-11-13T06:28:03.485879714+01:00" level=warning msg="could not change group /var/run/docker.sock to docker
: group docker not found"
time="2017-11-13T06:28:03.488257938+01:00" level=info msg="libcontainerd: new containerd process, pid: 8426"

I also tried install dockerd as service


- template:
src: templates/dockerd.service.j2
dest: /etc/systemd/system/dockerd.service
owner: root
mode: 0644

- systemd:
name: dockerd
state: started
enabled: True

But still same error , need restart dockerd

  • systemd:
    name: dockerd
    state: restarted

before run command docker run -d xxx