start.yml 3.55 KB
Newer Older
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
---

- name: Copy certificates in keycloak x509 conf dir
  remote_user: jboss
  copy:
    src:  "{{ item.local }}"
    dest: "{{ item.remote }}"
    mode: "{{ item.mode}}"
  with_items:
    - local: "{{playbook_dir}}/secrets/CA/issued/{{ inventory_hostname }}.crt"
      remote: /etc/x509/https/tls.crt
      mode: '0644'
    - local: "{{playbook_dir}}/secrets/CA/private/{{ inventory_hostname }}.key"
      remote: /etc/x509/https/tls.key
      mode: '0600'
    - local: "{{playbook_dir}}/secrets/CA/ca.crt"
      remote: /etc/x509/ca/ca.crt
      mode: '0644'
    - local: "{{playbook_dir}}/secrets/CA/cacerts.jks"
      remote: /opt/jboss/keycloak/cacerts.jks
      mode: '0644'

- name: Generate Keycloak secure config
  remote_user: jboss
  command: "/opt/jboss/tools/x509.sh"
  environment:
    X509_CA_BUNDLE: "/etc/x509/ca/ca.crt"

- name: Set admin password
  remote_user: jboss
  command: /opt/jboss/keycloak/bin/add-user-keycloak.sh --user "admin" --password "{{lookup('password', '{{playbook_dir}}/secrets/passwords/keykloak_admin')}}"
  ignore_errors: True

- name: Configure logging format
  remote_user: jboss
  lineinfile: #TODO: Change to community.general.xml
   path: /opt/jboss/keycloak/standalone/configuration/standalone.xml
   regexp: '.*<formatter name="PATTERN">.*'
   line: "<formatter name=\"JSON\"><json-formatter date-format=\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\" pretty-print=\"false\" print-details=\"true\" zone-id=\"UTC\"/></formatter><formatter name=\"PATTERN\">"

- name: Enable event logging
  remote_user: jboss
  lineinfile:
   path: /opt/jboss/keycloak/standalone/configuration/standalone.xml
   regexp: '.*<spi name="eventsStore">.*'
   line: '<spi name="eventsListener"><provider name="jboss-logging" enabled="true"><properties><property name="success-level" value="INFO"/><property name="error-level" value="WARN"/></properties></provider></spi><spi name="eventsStore">'

- name: Specify logging format
  remote_user: jboss
  lineinfile:
   path: /opt/jboss/keycloak/standalone/configuration/standalone.xml
   regexp: ".*<named-formatter name=.*"
   line: '<named-formatter name="JSON"/>'

- name: Configure Keycloak start script
  remote_user: jboss
  template:
    src: "{{item}}.j2"
    dest: "/opt/jboss/tools/{{item}}"
    mode: 0750
  with_items:
    - startkeycloak.sh
    - initkeycloakrealm.sh

- name: Start Keycloak IdP
  remote_user: root
  command: "supervisorctl start keycloak"

- name: Wait for Keycloak
  remote_user: jboss
  wait_for:
    host: "{{groups['keycloakcontainers'][0]}}"
    port: 8443
    state: started
    delay: 5

- name: Initialize Keycloak realm
  remote_user: jboss
  command: /opt/jboss/tools/initkeycloakrealm.sh

- name: Copy secrets from Keycloak
  remote_user: jboss
  fetch:
    src:  "{{ item.remote }}"
    dest: "{{ item.local }}"
    flat: yes
  with_items:
    - remote: "{{ ansible_facts.env['JBOSS_HOME'] }}/nifisecret"
      local:  "{{playbook_dir}}/secrets/tokens/nifisecret"
    - remote: "{{ ansible_facts.env['JBOSS_HOME'] }}/kibanasecret"
      local:  "{{playbook_dir}}/secrets/tokens/kibanasecret"
    - remote: "{{ ansible_facts.env['JBOSS_HOME'] }}/mispsecret"
      local:  "{{playbook_dir}}/secrets/tokens/mispsecret"
Arne Øslebø's avatar
Arne Øslebø committed
94
95
96
97
    - remote: "{{ ansible_facts.env['JBOSS_HOME'] }}/thehivesecret"
      local:  "{{playbook_dir}}/secrets/tokens/thehivesecret"
    - remote: "{{ ansible_facts.env['JBOSS_HOME'] }}/cortexsecret"
      local:  "{{playbook_dir}}/secrets/tokens/cortexsecret"
98
99

- name: Set Autostart for supervisord's services
Arne Øslebø's avatar
Arne Øslebø committed
100
101
102
103
  replace:
    path: /etc/supervisord.conf
    regexp: '^autostart=false$'
    replace: 'autostart=true'