1

我正在尝试使用 ansible runner 在 Flask Python 项目中执行 ansible playbook,但在执行时,我收到以下错误:The command was not found or was not executable: ansible-playbook.

该应用程序在目录内的 docker 容器中运行/app

代码:

        r = ansible_runner.run(private_data_dir='/app/flask/ansible', playbook='project/playbook.yml')
        app.logger.info("{}: {}".format(r.status, r.rc))
        # successful: 0
        for each_host_event in r.events:
            app.logger.info(each_host_event['event'])
        app.logger.info("Final status:")
        app.logger.info(r.stats)

这是项目树:

.
├── README.md
├── ansible.cfg
├── docker-compose.yml
├── flask
│   ├── Dockerfile
│   ├── ansible
│   │   ├── env
│   │   │   ├── cmdline
│   │   │   ├── envvars
│   │   │   ├── extravars
│   │   │   ├── passwords
│   │   │   ├── settings
│   │   │   └── ssh-key
│   │   ├── inventory
│   │   │   └── hosts
│   │   └── project
│   │       └── playbook.yml
│   ├── app.ini
│   ├── main.py
│   ├── run.py
│   ├── static
│   │   ├── app.js
│   │   ├── bulma.min.css
│   │   ├── highlight.min.css
│   │   ├── highlight.min.js
│   │   └── styles.css
│   └── templates
│       ├── 404.html
│       ├── base.html
│       ├── create_user.html
│       └── login.html
├── nginx
│   ├── Dockerfile
│   └── nginx.conf

烧瓶 Docker 文件:

FROM python:3.7.2-stretch
WORKDIR /app
ADD . /app
RUN pip install --upgrade pip && pip install flask uwsgi requests ansible_runner
CMD ["uwsgi","app.ini"]
4

1 回答 1

0

ansible_runner Python 包只是 ansible 可执行文件的接口。您需要在 Docker 容器中安装 Ansible 本身。添加RUN apt-get update && apt-get install -y ansible到您的 Dockerfile

FROM python:3.7.2-stretch

RUN apt-get update && \
    apt-get install -y ansible && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app
ADD . /app
RUN pip install --upgrade pip && pip install flask uwsgi requests ansible_runner
CMD ["uwsgi","app.ini"]
于 2020-10-27T14:24:25.020 回答