eletrotupi / tcc/ ansible/roles/app/tasks/main.yml32b1e688c7e7c65b735c7e23ba3c4aeb89c33a3d
1.9 KB | 67 lines Raw
1
---
2
# roles/app/tasks/main.yml
3
# Places the production app config in /srv/app/<env>/
4
# The env files are rendered from group_vars (secrets come from the encrypted
5
# vault.yml), so there is nothing to fill in by hand anymore
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
# The valkey image drops to its own unprivileged user, so this file has to be
36
# readable by it. valkey.conf holds no secrets (no password), so 0644 is fine
37
- name: Install the valkey configuration
38
  ansible.builtin.copy:
39
    src: valkey.conf
40
    dest: "/srv/app/{{ app_env }}/valkey.conf"
41
    owner: "{{ deploy_user }}"
42
    group: "{{ deploy_user }}"
43
    mode: "0644"
44
  tags: [app]
45

46
- name: Install the Vector configuration
47
  ansible.builtin.copy:
48
    src: vector.yaml
49
    dest: "/srv/app/{{ app_env }}/vector.yaml"
50
    owner: "{{ deploy_user }}"
51
    group: "{{ deploy_user }}"
52
    mode: "0640"
53
  tags: [app]
54

55
- name: Install the environment files
56
  ansible.builtin.template:
57
    src: "{{ item.src }}"
58
    dest: "/srv/app/{{ app_env }}/{{ item.dest }}"
59
    owner: "{{ deploy_user }}"
60
    group: "{{ deploy_user }}"
61
    mode: "0600"
62
  loop:
63
    - { src: env.j2, dest: .env }
64
    - { src: env.production.j2, dest: .env.production }
65
  loop_control:
66
    label: "{{ item.dest }}"
67
  tags: [app]