Ansible Runner 无法执行剧本



我正试图使用ansible runner在Flask Python项目中执行一个ansible剧本,但在执行时,我得到了以下错误:The command was not found or was not executable: ansible-playbook.

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

代码:

        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

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

ansible_runner Python包只是可执行程序的接口。您需要在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"]

最新更新