summaryrefslogtreecommitdiff
path: root/roles/greenbone/server/tasks/main.yml
blob: e66d04183f5ede6f48110ceb8958d1869e02b69d (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
---
- name: create base directory
  file:
    path: "/var/lib/greenbone/{{ greenbone_server_hostname }}"
    state: directory

- name: copy docker compose file
  template:
    src: "docker-compose-{{ greenbone_server_version }}.yml.j2"
    dest: "/var/lib/greenbone/{{ greenbone_server_hostname }}/docker-compose.yml"

## TODO: replace this with proper ansible modules once the v2 modules get released
- name: get list of running compose projects
  check_mode: no
  command: "docker compose ls --format json --filter 'name=^{{ greenbone_server_hostname }}$'"
  changed_when: False
  register: greenbone_server_compose_list

- name: initial compose setup
  when: (greenbone_server_compose_list.stdout | from_json | length) == 0
  block:
  - name: pull greenbone images
    command: docker compose -f "/var/lib/greenbone/{{ greenbone_server_hostname }}/docker-compose.yml" -p "{{ greenbone_server_hostname | replace('.', '_') }}" pull

  - name: start greenbone
    command: docker compose -f "/var/lib/greenbone/{{ greenbone_server_hostname }}/docker-compose.yml" -p "{{ greenbone_server_hostname | replace('.', '_') }}" up -d

  - name: set admin password
    command: docker compose -f "/var/lib/greenbone/{{ greenbone_server_hostname }}/docker-compose.yml" -p "{{ greenbone_server_hostname | replace('.', '_') }}" exec -u gvmd gvmd gvmd --user=admin --new-password="{{ greenbone_server_admin_password }}"
    register: greenbone_server_set_admin_password
    until: "greenbone_server_set_admin_password is not failed"
    retries: 15
    delay: 5

- name: compute nginx vhost config
  vars:
    greenbone_server_vhost_base:
      name: greenbone
      mode: "0600"
      template: generic
      hostnames:
      - "{{ greenbone_server_hostname }}"
      locations:
        '/':
          proxy_pass: "http://127.0.0.1:9392"
    greenbone_server_vhost_override__yaml: |
      {% if greenbone_server_tls is defined %}
      tls:
        {{ greenbone_server_tls | to_nice_yaml(indent=2) | indent(2) }}
      {% endif %}
  set_fact:
    greenbone_server_vhost: "{{ greenbone_server_vhost_base | combine(greenbone_server_vhost_override__yaml | from_yaml, recursive=True) }}"

- name: configure nginx vhost
  vars:
    nginx_vhost:
      "{{ greenbone_server_vhost }}"
  include_role:
    name: nginx/vhost