I am trying execute an ansible playbook inside a Flask Python project using ansible runner but upon execution, I get the following error: The command was not found or was not executable: ansible-playbook.
The app runs in a docker container inside directory /app
.
Code:
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)
This is the project tree:
.
├── 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"]
The ansible_runner Python package is just an interface to the ansible executable. You need to install Ansible itself within your Docker container. Add RUN apt-get update && apt-get install -y ansible
to your 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"]