summaryrefslogtreecommitdiff
path: root/roles/apps/whawty/auth/instance/tasks/main.yml
blob: a5872839b8554c0581a62f61c4f524318b35c30a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
## TODO: add storage handling!
- set_fact:
    whawty_auth_instance_basepath: "/srv/whawty/{{ whawty_auth_instance }}"
##

## TODO: custom user

- name: create instance config directory
  file:
    path: "{{ whawty_auth_instance_basepath }}/config"
    state: directory

- name: create instance store directory
  file:
    path: "{{ whawty_auth_instance_basepath }}/store"
    state: directory
    owner: app
    mode: 0700

- name: generate store config
  template:
    src: store.yml.j2
    dest: "{{ whawty_auth_instance_basepath }}/config/store.yml"
    mode: 0400
    owner: app

- name: set up tls config
  when: "'tls' in whawty_auth_instances[whawty_auth_instance]"
  block:
  - name: create tls directory
    file:
      path: "{{ whawty_auth_instance_basepath }}/config/tls"
      state: directory
      mode: 0500
      owner: app

  - name: generate/install/fetch TLS certificate
    vars:
      x509_certificate_name: "whawty-auth-{{ whawty_auth_instance }}"
      x509_certificate_hostnames: "{{ whawty_auth_instances[whawty_auth_instance].hostnames }}"
      x509_certificate_renewal:
        install:
        - dest: "{{ whawty_auth_instance_basepath }}/config/tls/cert.pem"
          src:
          - fullchain
          mode: "0400"
          owner: app
        - dest: "{{ whawty_auth_instance_basepath }}/config/tls/key.pem"
          src:
          - key
          mode: "0400"
          owner: app
        reload: |
          pod_id=$(crictl pods -q --state ready --name "^whawty-auth-{{ whawty_auth_instance }}-{{ ansible_nodename }}$")
          [ -n "$pod_id" ] || exit 0
          container_id=$(crictl ps -q --name '^app$' -p "$pod_id")
          [ -n "$container_id" ] || exit 0
          crictl stop "$container_id"
    include_role:
      name: "x509/{{ whawty_auth_instances[whawty_auth_instance].tls.certificate_provider }}/cert"

  - name: generate app web config
    template:
      src: web.yml.j2
      dest: "{{ whawty_auth_instance_basepath }}/config/web.yml"
      mode: 0400
      owner: app

- name: set up sync config
  when: "'sync' in whawty_auth_instances[whawty_auth_instance]"
  block:
  - name: create sync directory
    file:
      path: "{{ whawty_auth_instance_basepath }}/sync"
      state: directory

  - name: generate sync config files
    loop:
    - group
    - passwd
    - rsyncd.conf
    - sshd_config
    template:
      src: "sync-{{ item }}.j2"
      dest: "{{ whawty_auth_instance_basepath }}/sync/{{ item }}"

  - name: generate authorized_keys for sync
    copy:
      content: "{{ whawty_auth_instances[whawty_auth_instance].sync.authorized_keys | join('\n') }}\n"
      dest: "{{ whawty_auth_instance_basepath }}/sync/authorized_keys"

  - name: generate ssh host key for sync
    command: "ssh-keygen -q -t ed25519 -f '{{ whawty_auth_instance_basepath }}/sync/ssh_host_ed25519_key' -C '' -N ''"
    args:
      creates: "{{ whawty_auth_instance_basepath }}/sync/ssh_host_ed25519_key"

  - name: fix permissions for ssh host keys
    file:
      path: "{{ whawty_auth_instance_basepath }}/sync/ssh_host_ed25519_key"
      owner: app

- name: install pod manifest
  vars:
    whawty_auth_instance_config_hash_items__yaml: |
      - path: "{{ whawty_auth_instance_basepath }}/config/store.yml"
      {% if 'tls' in whawty_auth_instances[whawty_auth_instance] %}
      - path: "{{ whawty_auth_instance_basepath }}/config/web.yml"
      {% endif %}
      {% if 'sync' in whawty_auth_instances[whawty_auth_instance] %}
      - path: "{{ whawty_auth_instance_basepath }}/sync/authorized_keys"
      - path: "{{ whawty_auth_instance_basepath }}/sync/group"
      - path: "{{ whawty_auth_instance_basepath }}/sync/passwd"
      - path: "{{ whawty_auth_instance_basepath }}/sync/rsyncd.conf"
      - path: "{{ whawty_auth_instance_basepath }}/sync/ssh_host_ed25519_key"
      - path: "{{ whawty_auth_instance_basepath }}/sync/sshd_config"
      {% endif %}
    kubernetes_standalone_pod:
      name: "whawty-auth-{{ whawty_auth_instance }}"
      spec: "{{ lookup('template', 'pod-spec.yml.j2') }}"
      config_hash_items: "{{ whawty_auth_instance_config_hash_items__yaml | from_yaml }}"
  include_role:
    name: kubernetes/standalone/pod