eletrotupi / tcc/ ansible/roles/app/tasks/main.yml1495e32eb83d60fb8dd6a1c539de3fbefa9e19b1
1.9 KB | 72 lines Raw
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 environment example files
45
  ansible.builtin.template:
46
    src: "{{ item }}.j2"
47
    dest: "/srv/app/{{ app_env }}/{{ item }}.example"
48
    owner: "{{ deploy_user }}"
49
    group: "{{ deploy_user }}"
50
    mode: "0640"
51
  loop:
52
    - env
53
    - env.production
54
  tags: [app]
55

56
- name: Check whether the real env files exist on the server
57
  ansible.builtin.stat:
58
    path: "/srv/app/{{ app_env }}/{{ item }}"
59
  loop:
60
    - .env
61
    - .env.production
62
  register: app_env_stat
63
  tags: [app]
64

65
- name: Remind to fill in the env files
66
  ansible.builtin.debug:
67
    msg: >-
68
      {{ item.item }} is missing: copy it from {{ item.item }}.example and fill
69
      it in before the first `docker compose up -d`
70
  loop: "{{ app_env_stat.results }}"
71
  when: not item.stat.exists
72
  tags: [app]