运行mysql:5.5来自ansible的docker镜像

时间:2015-04-07 00:53:09

标签: mysql docker ansible ansible-playbook

如何从ansible运行mysql:5.5?如果我直接运行它:

docker run -e MYSQL_ROOT_PASSWORD=pass mysql:5.5

它的工作正常。但如果我从ansible运行:

- name: run database
  local_action:
    module: docker
    image: mysql:5.5
    state: running

它开始并立即停止。在案例1中的帖子也是3306 / tcp,但在案例2中没有端口。

1 个答案:

答案 0 :(得分:1)

您需要将mysql root密码指定为容器的环境变量。例如:


- 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"