Report this

What is the reason for this report?

App deployment fails as my ansible template copy is not performed

Posted on July 26, 2022

Hello,

I am running through a weird behaviour when deploying my Dockerfile on App platform.

I use ansible to deploy my App, I have 2 roles that perform template copy. One is for gunicorn the other is for a settings file. The gunicorn file is well copied, while the settings is simply not copied.

Here are some logs with some debugging session I’ve performed:

  • Ansible display of settings file:
[2022-07-26 12:45:56]     "cmd": [
[2022-07-26 12:45:56]         "cat",
[2022-07-26 12:45:56]         "/crm-pilates/settings.ini"
[2022-07-26 12:45:56]     ],
...
[2022-07-26 12:45:56]     "stdout_lines": [
[2022-07-26 12:45:56]         "[DEFAULT]",
[2022-07-26 12:45:56]         "EVENT_STORE_PATH= PATH",
[2022-07-26 12:45:56]         "",
[2022-07-26 12:45:56]         "[CORS]",
[2022-07-26 12:45:56]         "CORS_ALLOW_ORIGINS= CORS",
[2022-07-26 12:45:56]         "",
[2022-07-26 12:45:56]         "[DATABASE]",
[2022-07-26 12:45:56]         "DATABASE_URL= "
[2022-07-26 12:45:56]     ]

There are no ansible errors at the end of the playbook run.

  • Python logs displaying directory files:
[2022-07-26 12:48:38] WARNING:root:Current main path /crm-pilates/crm_pilates/main.py
[2022-07-26 12:48:38] WARNING:root:Current working dir /crm-pilates
[2022-07-26 12:48:38] WARNING:root:Root dir: .dockerignore, .venv, Dockerfile, LICENSE, Makefile, README.md, crm_pilates, docker-compose.yml, local.persistent, log-config.json, poetry.lock, pyproject.toml, run.sh, scripts
[2022-07-26 12:48:38] WARNING:root:Module dir: __init__.py, __pycache__, api.py, command, domain, event, gunicorn.py, infrastructure, main.py, settings.py, web

you can see the gunicorn.py in the module dir but there are no settings.ini in the root dir where it should be.

Below are some logs from a local docker container (using the same deployment method):

WARNING:root:Current main path /crm-pilates/crm_pilates/main.py
WARNING:root:Current working dir /crm-pilates
WARNING:root:Root dir: crm_pilates, local.persistent, settings.ini, .venv, log-config.json, README.md, Makefile, pyproject.toml, scripts, docker-compose.yml, LICENSE, run.sh, poetry.lock, __pycache__, .dockerignore, Dockerfile
WARNING:root:Module dir: __init__.py, settings.py, api.py, main.py, command, event, infrastructure, domain, __pycache__, web, gunicorn.py

As you may see the settings.ini is present and the app is running fine on local docker.

Here is the ansible playbook command: $(virtualenv_path)/bin/ansible-playbook scripts/ansible/playbook.yml --inventory scripts/ansible/deploy.yml --diff -vvvv

the settings role:

- name: copy settings
  template:
    src: settings.ini
    dest: "{{ root_dir }}/settings.ini"

the server role (that copy gunicorn file):

- name: copy gunicorn configuration
  template:
    src: gunicorn.py
    dest: "{{ root_dir }}/crm_pilates/gunicorn.py"

and the playbook:

- name: Configure settings
  hosts: all
  roles:
    - role: settings
    - role: display_settings
    - role: print_settings

- name: Deploy
  hosts:
    deploy
    docker-local
  roles:
    - role: server

I really don’t get why it is working on a local container and not on digital ocean App container.

If anyone has an idea and see what I don’t see.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

It’s possible this happens because App Platform builds your Docker image in an isolated environment. If your Ansible playbook generates or copies files only at runtime, those changes won’t persist in the final container unless they’re included in the Docker build context and copied in the Dockerfile.

I’m not completely sure without seeing how your build step runs inside App Platform, but in most cases, files created by Ansible after the image build phase aren’t included in the deployed app. You may want to generate or copy settings.ini earlier in your build process or handle it directly in the Dockerfile instead.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.