aboutsummaryrefslogtreecommitdiffstats
path: root/tasks/jail_homepage.yml
blob: 6751ad54c493eddede9dd0ed5df3f066917e6792 (plain)
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
- name: Install packages inside jail
  loop:
    - { jail: homepage, package: nginx }
    - { jail: homepage, package: rsync }
    - { jail: homepage, package: bash }
  include_tasks: pkg_jail_install.yml

- name: Create /var/www
  file:
    path: /usr/local/jails/containers/homepage/var/www
    state: directory
    owner: www
    group: www
    mode: "0755"

# It's important to run this after generating certs, because nginx.conf refers to files
# generated by certbot. Certbot will fail validation if nginx.conf is configured too early.
- name: Configure nginx.conf
  template:
    src: homepage/usr_local_etc_nginx_nginx.conf.j2
    dest: /usr/local/jails/containers/homepage/usr/local/etc/nginx/nginx.conf
    owner: root
    group: wheel
    mode: "0644"
  register: homepage_nginx_conf

- name: Check if nginx is enabled
  shell: service -j homepage nginx status
  changed_when: false
  failed_when: false
  register: homepage_nginx_enabled

- name: Enable and start nginx
  shell: |
    service -j ingress nginx enable
    service -j ingress nginx restart
  when: homepage_nginx_enabled.rc != 0 or homepage_nginx_conf.changed

- name: Set up crontab
  template:
    src: homepage/etc_crontab.j2
    dest: /usr/local/jails/containers/homepage/etc/crontab
    owner: root
    group: wheel
    mode: "0644"
  register: jail_homepage_etc_crontab

- name: Restart cron
  service:
    name: cron
    state: restarted
  when: jail_homepage_etc_crontab.changed