0

I could use some help.

I was tasked to install check-mk (Nagios) through Docker through ansible. I managed to install docker but I can't make it install check-mk through ansible...

The command to install check-mk is:

docker container run -dit -p 8080:5000 --ulimit nofile=1024 --tmpfs /opt/omd/sites/cmk/tmp:uid=1000,gid=1000 -v monitoring:/omd/sites --name monitoring -v /etc/localtime:/etc/localtime:ro --restart always checkmk/check-mk-raw:1.6.0-latest

My code so far looks like this:

    - name: Install docker on a Centos 7 machine
      hosts: localhost
      vars:
        create_containers: 1
        default_container_name: docker
        default_container_image: centos
        default_container_command: sleep 1d
        
    tasks:
        - name: Add Docker CE repo
          get_url_
           url: https://download.docker.com/linux/centos/docker-ce.repo
           dest: /etc/yum.repos.d/docker-ce.repo
         
        - name: Install Docker
          yum: name=docker state=latest
          
        - name: Start and enable the Docker daemon
          service: name=docker state=started enabled=yes
          
        - name: Install Docker Module for Python
          pip:
            name: docker
            
        - name: Create a default container
          docker_container:
             name: "{{ default_container_name }}{{ item }}"
             image: "{{ default_container_image }}"
             command: "{{ default_container_command }}"
             state: present
          with_sequence: count={{ create_containers }}
          
          - name: Start a container with a command
            docker_container:
                name: docker1
                image: centos
                command: ["docker container run -dit -p 8080:5000 --ulimit nofile=1024 --tmpfs /opt/omd/sites/cmk/tmp:uid=1000,gid=1000 -v monitoring:/omd/sites --name monitoring -v /etc/localtime:/etc/localtime:ro --restart always checkmk/check-mk-raw:1.6.0-latest"]

But it is throwing an error while starting my docker container:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error starting container fd44b8066dd4d205a1b2883...: 404 Client Error for http+docker://localhost/v1.26/containers fd44b8066dd4d.../start: Not found ("oci runtime error: container_linux.go:235: starting container process caused "exec: \"/bin/docker\": stat /bin/docker: no such file or directory"\n")"}

Can anyone tell me what I'm doing wrong?

  • 1
    Please do not provide code, output and/or error messages in images: in most cases it is not readable, it impairs search engines ability to index the content, it prevents people trying to help you to copy/paste content if needed, it uses (in best cases...) 1000 times more data volume (e.g. disk space to store, data transfers....) than the equivalent text in code/citation block... and above all, it is specifically listed as a bad practice in How to ask. Thanks – Zeitounator Mar 02 '21 at 17:39
  • 1
    Sorry, didn't know. I updated it with actual text. Thank you for the heads up. – Mariana Dias Mar 02 '21 at 18:21
  • 1
    You cannot run `/bin/docker` inside a docker container unless you are using `docker:dind` or similar trickery; it seems you would benefit from reading the docker getting started guide in order to understand why that construct didn't work – mdaniel Mar 02 '21 at 22:02
  • Thank you mdaniel, you are right. I fixed my code and it is working now. I replaced - name: Start a container with a command docker_container: name: docker1 image: centos command: ["docker container..."] with: - name: Install Check_MK through Docker ansible.builtin.command: cmd: "docker container run ..." – Mariana Dias Mar 04 '21 at 16:19

0 Answers0