| 1 | ---
|
| 2 | # roles/app/tasks/main.yml
|
| 3 | # Places the production app config in /srv/app/<env>/
|
| 4 | # Secrets are NOT created here: the .example files are dropped in and you fill
|
| 5 | # them in by hand (that part is deliberately manual, so get ready to SSH and copy it)
|
| 6 |
|
| 7 | - name: Ensure /srv/app exists
|
| 8 | ansible.builtin.file:
|
| 9 | path: /srv/app
|
| 10 | state: directory
|
| 11 | owner: "{{ deploy_user }}"
|
| 12 | group: "{{ deploy_user }}"
|
| 13 | mode: "0750"
|
| 14 | tags: [app]
|
| 15 |
|
| 16 | - name: Ensure the per-environment app directories exist
|
| 17 | ansible.builtin.file:
|
| 18 | path: "/srv/app/{{ item }}"
|
| 19 | state: directory
|
| 20 | owner: "{{ deploy_user }}"
|
| 21 | group: "{{ deploy_user }}"
|
| 22 | mode: "0750"
|
| 23 | loop: "{{ app_environments }}"
|
| 24 | tags: [app]
|
| 25 |
|
| 26 | - name: Install the production compose file
|
| 27 | ansible.builtin.copy:
|
| 28 | src: docker-compose.production.yml
|
| 29 | dest: "/srv/app/{{ app_env }}/docker-compose.yml"
|
| 30 | owner: "{{ deploy_user }}"
|
| 31 | group: "{{ deploy_user }}"
|
| 32 | mode: "0640"
|
| 33 | tags: [app]
|
| 34 |
|
| 35 | - name: Install the valkey configuration
|
| 36 | ansible.builtin.copy:
|
| 37 | src: valkey.conf
|
| 38 | dest: "/srv/app/{{ app_env }}/valkey.conf"
|
| 39 | owner: "{{ deploy_user }}"
|
| 40 | group: "{{ deploy_user }}"
|
| 41 | mode: "0640"
|
| 42 | tags: [app]
|
| 43 |
|
| 44 | - name: Install the Vector configuration
|
| 45 | ansible.builtin.copy:
|
| 46 | src: vector.yaml
|
| 47 | dest: "/srv/app/{{ app_env }}/vector.yaml"
|
| 48 | owner: "{{ deploy_user }}"
|
| 49 | group: "{{ deploy_user }}"
|
| 50 | mode: "0640"
|
| 51 | tags: [app]
|
| 52 |
|
| 53 | - name: Install the environment example files
|
| 54 | ansible.builtin.template:
|
| 55 | src: "{{ item }}.j2"
|
| 56 | dest: "/srv/app/{{ app_env }}/{{ item }}.example"
|
| 57 | owner: "{{ deploy_user }}"
|
| 58 | group: "{{ deploy_user }}"
|
| 59 | mode: "0640"
|
| 60 | loop:
|
| 61 | - env
|
| 62 | - env.production
|
| 63 | tags: [app]
|
| 64 |
|
| 65 | - name: Check whether the real env files exist on the server
|
| 66 | ansible.builtin.stat:
|
| 67 | path: "/srv/app/{{ app_env }}/{{ item }}"
|
| 68 | loop:
|
| 69 | - .env
|
| 70 | - .env.production
|
| 71 | register: app_env_stat
|
| 72 | tags: [app]
|
| 73 |
|
| 74 | - name: Remind to fill in the env files
|
| 75 | ansible.builtin.debug:
|
| 76 | msg: >-
|
| 77 | {{ item.item }} is missing: copy it from {{ item.item }}.example and fill
|
| 78 | it in before the first `docker compose up -d`
|
| 79 | loop: "{{ app_env_stat.results }}"
|
| 80 | when: not item.stat.exists
|
| 81 | tags: [app]
|