run mysql:5.5 docker image from ansible

How to run mysql: 5.5 from ansible? If I run it directly:

docker run -e MYSQL_ROOT_PASSWORD=pass mysql:5.5

it’s work ok. But if I run from ansible:

  • Ansible-container setup errors
  • How to test Ansible playbook using Docker
  • Ansible and docker-py
  • Behaviour of Ansible hosts: setting on Vagrant or Docker
  • Udeploy not projecting the data
  • problems using Ansible to run docker tasks on OS X
  • - name: run database
      local_action:
        module: docker
        image: mysql:5.5
        state: running
    

    it’s start and immediately stop. Also post in case 1 is 3306/tcp, but in case 2 there is no port.

  • Docker build failed because of “port 443: Connection timed out”
  • “nginx-proxy” docker image socket volume not mounted
  • Docker, php and python
  • Login docker container get return info:cannot set user id: Resource temporarily unavailable
  • How to prevent binding to docker0 bridge in overlay mode
  • Does Alpine Linux handle certs differently than Busybox?
  • One Solution collect form web for “run mysql:5.5 docker image from ansible”

    You need to specify mysql root password as environment variable for container. For example:


    - hosts: ansible_host
      gather_facts: False
      sudo: yes
      pre_tasks:
        - name: install pip pkg.
          yum:
            name: python-pip
            state: present
    
        - name: install boto pkg.
          pip:
            name: docker-py
            state: present
    
        - name: docker
          docker:
            image: "mysql:5.5"
            state: running
            env: "MYSQL_ROOT_PASSWORD=my-secret-pw"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.