Docker容器中Ansible Playbook执行跳过任务完成

时间:2018-12-03 16:53:17

标签: docker ansible

我正在尝试对运行MySQL转储的ansible剧本进行Docker化。

---
- name: MySQL Dump
  hosts: lh
  connection: local
  vars_files:
    - ./vars/sql-credentials.yml
    - ./vars/aws-credentials.yml

  tasks:
    - name: Create Folder To Store
      file:
        state: directory
        path: ./backups

    - name: Get Dump from MySQL DB
      mysql_db:
        name: "{{ db_name }}"
        config_file: .my.cnf
        login_host: "{{ db_login_host }}"
        login_user: "{{ db_login_user }}"
        login_password: "{{ db_login_password }}"
        state: dump
        target: "backups/z-{{ ansible_date_time.date }}.sql.gz"

在容器外部执行剧本,我得到了我期望的sql转储文件(转储文件大约为80mb)。当剧本在容器中运行时,它会尽早完成剧本(几乎在列出任务后立即完成)而没有任何错误,文件的输出为20kb

FROM ubuntu:bionic

RUN apt-get update && \
  apt-get dist-upgrade -y && \
  apt-get install -y software-properties-common systemd && \
  rm -rf /var/lib/apt/lists/*

RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
    git \
    ansible \
    mysql-client \
    python-pip \ 
    python-dev \ 
    build-essential \
 && rm -rf /var/lib/apt/lists/*

COPY . .

RUN pip install -r requirements.txt

RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts

CMD [ "ansible-playbook", "-i", "inventory", "playbook.yml", "-vvvv" ]

我尝试在容器内以详细模式运行它,而我完全没有任何错误。

之所以要在容器中运行,是因为我希望Travis CI在CRON中执行此转储,然后将其部署到S3存储桶中。

0 个答案:

没有答案