aboutsummaryrefslogtreecommitdiffstats
path: root/roles/obsd_httpd/tasks/main.yml
blob: 36ff9fb9cb72eabe0f519665b7eb59f8aa51b7db (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
- name: Create httpd conf include directory
  ansible.builtin.file:
    path: "{{ httpd_conf_d }}"
    state: directory
    owner: root
    group: wheel
    mode: "0755"

- name: Deploy httpd.conf
  ansible.builtin.template:
    src: httpd.conf.j2
    dest: /etc/httpd.conf
    owner: root
    group: wheel
    mode: "0600"
  notify: restart httpd

- name: Ensure all registered httpd fragment files exist
  # If they don't exist, httpd validate will fail. So we want to create them,
  # even if empty for now.
  ansible.builtin.copy:
    content: ""
    dest: "{{ httpd_conf_d }}/{{ item }}"
    force: false # If it already exists, don't overwrite it.
    owner: root
    group: wheel
    mode: "0644"
  loop: "{{ httpd_fragments }}"

- name: Validate httpd config
  ansible.builtin.command: httpd -n
  changed_when: false

- name: Enable httpd and slowcgi
  ansible.builtin.command: "rcctl enable {{ item }}"
  args:
    creates: "/etc/rc.conf.d/{{ item }}"
  loop:
    - httpd
    - slowcgi
  changed_when: true

- name: Check service status
  ansible.builtin.command: rcctl check {{ item }}
  register: httpd_check
  changed_when: false
  failed_when: false # rc 1 exit code means "not running"
  loop:
    - httpd
    - slowcgi

- name: Start services that are not running
  ansible.builtin.command: rcctl start {{ item.item }}
  loop: "{{ httpd_check.results }}"
  when: item.rc != 0