aboutsummaryrefslogtreecommitdiffstats
path: root/tasks/jails.yml
blob: fe94126e8c38f118fd155ea83d4ed013db979d96 (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
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
- name: Ensure jails directory exists
  file:
    path: /usr/local/jails
    state: directory
    owner: root
    group: wheel
    mode: "0755"

- name: Create ZFS datasets
  loop:
    - { name: "zroot/jails", mountpoint: "/usr/local/jails" }
    - { name: "zroot/jails/media" }
    - { name: "zroot/jails/templates" }
    - { name: "zroot/jails/templates/{{ jail_userland_version }}" }
    - { name: "zroot/jails/containers" }
  loop_control:
    loop_var: dataset
  include_tasks: jails_dataset.yml

- name: Check if userland snapshot already exists
  shell: zfs list -t snapshot -o name | grep -Fxq "zroot/jails/templates/{{ jail_userland_version }}@base"
  failed_when: false
  changed_when: false
  register: zfs_userland_check

- name: Set up userland
  when: zfs_userland_check.rc != 0
  block:
    - name: Download userland
      get_url:
        url: https://download.freebsd.org/ftp/releases/amd64/amd64/{{ jail_userland_version }}/base.txz
        dest: /usr/local/jails/media/{{ jail_userland_version }}-base.txz
        owner: root
        group: wheel
        mode: "0644"

    - name: Unarchive userland
      shell: tar -xzf /usr/local/jails/media/{{ jail_userland_version }}-base.txz -C /usr/local/jails/templates/{{ jail_userland_version }}

    - name: Copy localtime to jail userland
      copy:
        remote_src: true
        src: /etc/localtime
        dest: /usr/local/jails/templates/{{ jail_userland_version }}/etc/localtime

    - name: Copy resolv.conf to jail userland
      shell: |
        cat /etc/resolv.conf > /usr/local/jails/templates/{{ jail_userland_version }}/etc/resolv.conf
        chmod 644 /usr/local/jails/templates/{{ jail_userland_version }}/etc/resolv.conf

    - name: Update userland to latest patch level
      shell: freebsd-update -b /usr/local/jails/templates/{{ jail_userland_version }}/ fetch install

    - name: Disable syslogd in the template
      shell: echo 'syslogd_enable="NO"' >> /usr/local/jails/templates/{{ jail_userland_version }}/etc/rc.conf

    - name: Create userland ZFS snapshot
      shell: zfs snapshot zroot/jails/templates/{{ jail_userland_version }}@base

- name: Configure jails
  block:
    - name: Configure jail.conf
      template:
        src: etc_jail.conf.j2
        dest: /etc/jail.conf
        owner: root
        group: wheel
        mode: "0644"

    - name: Configure devfs.rules
      template:
        src: etc_devfs.rules.j2
        dest: /etc/devfs.rules
        owner: root
        group: wheel
        mode: "0644"

    - name: Configure individual jails
      loop: "{{ jails }}"
      loop_control:
        loop_var: jail
      include_tasks: jails_single.yml