Ansible Runner 无法执行剧本
Ansible Runner can't execute playbook
我正在尝试使用 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 DockerFile:
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 包只是 ansible 可执行文件的接口。您需要在 Docker 容器中安装 Ansible 本身。将 RUN apt-get update && apt-get install -y ansible
添加到您的 Docker 文件
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"]
我正在尝试使用 ansible runner 在 Flask Python 项目中执行一个 ansible 剧本,但在执行时,我收到以下错误:The command was not found or was not executable: ansible-playbook.
该应用程序在目录 /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
Flask DockerFile:
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 包只是 ansible 可执行文件的接口。您需要在 Docker 容器中安装 Ansible 本身。将 RUN apt-get update && apt-get install -y ansible
添加到您的 Docker 文件
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"]