ansible molecule docker service does not start

1.6k views Asked by At

I have ansible playbook working, however while trying to test it with molecule, I cannot get docker service started.

Here is what I have in molecule.yml

platforms:
- name: instance
  image: oraclelinux:7
  command: /usr/sbin/init
  tmpfs:
   - /run
   - /run/lock
   - /tmp
 capabilities:
   - SYS_ADMIN
 volumes:
   - /sys/fs/cgroup:/sys/fs/cgroup:ro
 port_bindings:
   2424: 2424,
   2480: 2480
 pre_build_image: true

When I run my ansible playbook, I use below command to create docker container:

docker run -it --name=testing -d --rm --privileged --cap-add=SYS_ADMIN --tmpfs /run --tmpfs /run/lock --tmpfs /tmp -p 2424:2424 -p 2480:2480 -v /sys/fs/cgroup:/sys/fs/cgroup:ro  oraclelinux:7  /usr/sbin/init

Error while testing with molecule:

    TASK [docker-role : Start docker] ******************************************
    fatal: [instance]: FAILED! => {"changed": true, "cmd": "sudo systemctl start docker", 
"delta": "0:00:00.613116", "end": "2020-10-21 03:24:47.268335", "msg": "non-zero return code", 
"rc": 1, "start": "2020-10-21 03:24:46.655219", "stderr": "Job for docker.service failed because 
the control process exited with error code. See \"systemctl status docker.service\" and 
\"journalctl -xe\" for details.", "stderr_lines": ["Job for docker.service failed because the 
control process exited with error code. See \"systemctl status docker.service\" and \"journalctl 
-xe\" for details."], "stdout": "", "stdout_lines": []}

How do I figure out whats the issue with molecule test ?

Update:

    [root@instance /]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Wed 2020-10-21 07:05:55 UTC; 2min 22s ago
     Docs: https://docs.docker.com
  Process: 17373 ExecStart=/usr/bin/dockerd -g /tmp (code=exited, status=1/FAILURE)
 Main PID: 17373 (code=exited, status=1/FAILURE)

Oct 21 07:05:55 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:05:55 instance systemd[1]: Failed to start Docker Application Container Engine.
Oct 21 07:05:55 instance systemd[1]: Unit docker.service entered failed state.
Oct 21 07:05:55 instance systemd[1]: docker.service failed.
Oct 21 07:06:13 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:06:13 instance systemd[1]: Failed to start Docker Application Container Engine.
Oct 21 07:06:13 instance systemd[1]: docker.service failed.
Oct 21 07:06:34 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:06:34 instance systemd[1]: Failed to start Docker Application Container Engine.
Oct 21 07:06:34 instance systemd[1]: docker.service failed.


[root@instance /]# docker info
Client:
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at 
unix:///var/run/docker.sock. Is the docker daemon running?

    # journalctl -xe
-- 
-- Unit docker.socket has finished shutting down.
Oct 21 07:09:13 instance systemd[1]: Stopping Docker Socket for the API.
-- Subject: Unit docker.socket has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.socket has begun shutting down.
Oct 21 07:09:13 instance systemd[1]: Starting Docker Socket for the API.
-- Subject: Unit docker.socket has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.socket has begun starting up.
Oct 21 07:09:13 instance systemd[1]: Listening on Docker Socket for the API.
-- Subject: Unit docker.socket has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.socket has finished starting up.
-- 
-- The start-up result is done.
Oct 21 07:09:13 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:09:13 instance systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.service has failed.

My understanding is that it needed to be run in docker container where docker was installed and its service needs to be started.

1

There are 1 answers

0
Moises Barba Perez On

Maybe I don't understand well the question, but with molecule you don't need to run the container, molecule do it for you.

You can try this:

molecule create # This would create the instance
molecule list # This would show you the molecule scenario status
molecule converge # This would run you molecule playbook that would run the role

Actually molecule test command will run all these steps:

    --> Test matrix

└── default
    ├── lint
    ├── destroy
    ├── dependency
    ├── syntax
    ├── create
    ├── prepare
    ├── converge
    ├── idempotence
    ├── side_effect
    ├── verify
    └── destroy

To have the container available with the role applied you need to run converge command.

Once converged you can get into the container through molecule as well:

molecule login --host instance