diff options
Diffstat (limited to 'ansible')
| -rw-r--r-- | ansible/project/create_jail.yaml | 52 | ||||
| -rw-r--r-- | ansible/project/delete_jail.yaml | 21 | ||||
| -rw-r--r-- | ansible/project/setup_jail.yaml | 15 | ||||
| -rw-r--r-- | ansible/project/templates/jail.conf.j2 | 19 |
4 files changed, 107 insertions, 0 deletions
diff --git a/ansible/project/create_jail.yaml b/ansible/project/create_jail.yaml new file mode 100644 index 0000000..77db9a8 --- /dev/null +++ b/ansible/project/create_jail.yaml @@ -0,0 +1,52 @@ +- hosts: "bsd_servers" + tasks: + - name: init jail + become: true + when: inventory_hostname == jail_host + block: + - name: wipe jail directory + ansible.builtin.file: + path: "{{ containers_path }}/{{ jail_name }}" + state: absent + + - name: Create directory for jail + ansible.builtin.file: + path: "{{ containers_path }}/{{ jail_name }}" + state: directory + owner: root + group: wheel + mode: 0750 + + - name: extract base files to jail + ansible.builtin.unarchive: + src: "{{ media_path }}/14.0-RELEASE-base.txz" + dest: "{{ containers_path }}/{{ jail_name }}/" + remote_src: yes + extra_opts: + - "--unlink" + + - name: copy resolv.conf to jail + ansible.builtin.copy: + remote_src: yes + src: /etc/resolv.conf + dest: "{{ containers_path }}/{{ jail_name }}/etc/resolv.conf" + + - name: copy localtime to jail + ansible.builtin.copy: + remote_src: yes + src: /etc/localtime + dest: "{{ containers_path }}/{{ jail_name }}/etc/localtime" + + - name: update to latest patch version + ansible.builtin.shell: freebsd-update -b {{ containers_path }}/{{ jail_name }}/ fetch install + + - name: Create config file for jail + ansible.builtin.template: + src: templates/jail.conf.j2 + dest: "/etc/jail.conf.d/{{ jail_name }}.conf" + owner: root + group: wheel + mode: 0644 + + - name: start jail + ansible.builtin.shell: service jail start {{ jail_name }} diff --git a/ansible/project/delete_jail.yaml b/ansible/project/delete_jail.yaml new file mode 100644 index 0000000..1a976c5 --- /dev/null +++ b/ansible/project/delete_jail.yaml @@ -0,0 +1,21 @@ +- hosts: bsd_servers + tasks: + - name: delete jail + become: true + when: inventory_hostname == jail_host + block: + - name: stop jail + shell: service jail stop {{ jail_name }} + + - name: delete jail config file + ansible.builtin.file: + path: "/etc/jail.conf.d/{{ jail_name }}.conf" + state: absent + + - name: Remove all chflags from jail files + shell: chflags -R 0 {{ containers_path }}/{{ jail_name }} + + - name: Remove jail directory + ansible.builtin.file: + path: "{{ containers_path }}/{{ jail_name }}" + state: absent diff --git a/ansible/project/setup_jail.yaml b/ansible/project/setup_jail.yaml new file mode 100644 index 0000000..58a3c99 --- /dev/null +++ b/ansible/project/setup_jail.yaml @@ -0,0 +1,15 @@ +- hosts: bsd_servers + tasks: + - name: setup jail + become: true + when: inventory_hostname == jail_host + block: + - name: install packages inside jail + community.general.pkgng: + name: "{{ jail_packages }}" + state: present + jail: "{{ jail_name }}" + + - name: run commands inside jail + ansible.builtin.shell: "jexec -u root {{ jail_name }} {{ item }}" + with_items: "{{ jail_commands }}" diff --git a/ansible/project/templates/jail.conf.j2 b/ansible/project/templates/jail.conf.j2 new file mode 100644 index 0000000..c5063d7 --- /dev/null +++ b/ansible/project/templates/jail.conf.j2 @@ -0,0 +1,19 @@ +{{ jail_name }} { + # STARTUP/LOGGING + exec.start = "/bin/sh /etc/rc"; + exec.stop = "/bin/sh /etc/rc.shutdown"; + exec.consolelog = "/var/log/jail_console_${name}.log"; + + # PERMISSIONS + allow.raw_sockets; + exec.clean; + mount.devfs; + + # HOSTNAME/PATH + host.hostname = "${name}"; + path = "/usr/local/jails/containers/${name}"; + + # NETWORK + ip6.addr = {{ jail_ipv6 }}; + interface = vtnet0; +}
\ No newline at end of file |
