107 lines
3.5 KiB
YAML
107 lines
3.5 KiB
YAML
- name: Setting new {{ jail_name }} jail name
|
|
set_fact:
|
|
jail_{{ jail_name }}_newest_id: "\
|
|
{{ jail_prefix }}\
|
|
{{ ansible_date_time.year }}\
|
|
{{ ansible_date_time.month }}\
|
|
{{ ansible_date_time.day }}-\
|
|
{{ ansible_date_time.hour }}\
|
|
{{ ansible_date_time.minute }}\
|
|
{{ ansible_date_time.second }}"
|
|
|
|
- name: Set other variables for the create
|
|
set_fact:
|
|
jail_THIS_is_new_created: true
|
|
jail_{{ jail_name }}_new_dataset_name:
|
|
'{{ dynamic_jails_dataset_name }}/{{ vars["jail_" + jail_name + "_newest_id"] }}'
|
|
jail_{{ jail_name }}_new_path:
|
|
'{{ dynamic_jails_path }}/{{ vars["jail_" + jail_name + "_newest_id"] }}'
|
|
jail_{{ jail_name }}_new_ip4: '{{ available_jail_ip4 }}'
|
|
|
|
- name: Clone a new ZFS filesystem for the jail
|
|
zfs:
|
|
origin: '{{ template_dataset_root_name }}@{{ latest_snapshot }}'
|
|
name: '{{ vars["jail_" + jail_name + "_new_dataset_name"] }}'
|
|
state: present
|
|
extra_zfs_properties:
|
|
mountpoint: '{{ vars["jail_" + jail_name + "_new_path"] }}'
|
|
|
|
- name: Copy rc.conf over to the new jail
|
|
copy:
|
|
src: rc.conf
|
|
dest: '{{ vars["jail_" + jail_name + "_new_path"] }}/etc'
|
|
|
|
- name: Templating resolv.conf for jail
|
|
template:
|
|
src: resolv.conf.j2
|
|
dest: '{{ vars["jail_" + jail_name + "_new_path"] }}/etc/resolv.conf'
|
|
register: template_resolv
|
|
ignore_errors: yes
|
|
|
|
- name: Copy local resolv.conf over to the new jail
|
|
copy:
|
|
src: resolv.conf
|
|
dest: '{{ vars["jail_" + jail_name + "_new_path"] }}/etc'
|
|
register: local_resolv
|
|
ignore_errors: yes
|
|
when: template_resolv is failed
|
|
|
|
- name: Copy resolv.conf over to the new jail
|
|
copy:
|
|
src: /etc/resolv.conf
|
|
dest: '{{ vars["jail_" + jail_name + "_new_path"] }}/etc'
|
|
when: local_resolv is failed
|
|
|
|
- name: Setup timezone in jail
|
|
ansible.builtin.command:
|
|
/usr/sbin/tzsetup
|
|
-C {{ vars['jail_' + jail_name + '_new_path'] }}
|
|
{{ vars['jail_' + jail_name + '_timezone'|default(vars['default_timezone'])] }}
|
|
|
|
- name: Create config dir for jail
|
|
file:
|
|
path: '{{ dynamic_jails_path }}/configs/{{ vars["jail_" + jail_name + "_newest_id"] }}'
|
|
state: directory
|
|
|
|
- name: Templating fstab for jail
|
|
template:
|
|
src: fstab.j2
|
|
dest: '{{ dynamic_jails_path }}/configs/{{ vars["jail_" + jail_name + "_newest_id"] }}/fstab'
|
|
register: fstab_init_result
|
|
failed_when: false
|
|
ignore_errors: yes
|
|
changed_when: fstab_init_result is succeeded
|
|
|
|
- name: Adding fstab to jail startup
|
|
set_fact:
|
|
'jail_{{ jail_name }}_config_opts': >-
|
|
{{ vars["jail_" + jail_name + "_config_opts"]|default({})|combine(
|
|
{'mount.fstab':
|
|
dynamic_jails_path + '/configs/' + vars['jail_' + jail_name + '_newest_id'] + '/fstab'}
|
|
)}}
|
|
when: fstab_init_result is changed
|
|
|
|
- name: Updating jails.ini (IPv4)
|
|
blockinfile:
|
|
create: yes
|
|
dest: '{{ dynamic_jails_path }}/configs/jails.ini'
|
|
marker: '# {mark} ANSIBLE MANAGED BLOCK: {{ jail_name }}'
|
|
block: |
|
|
[{{ jail_name }}]
|
|
name = {{ vars['jail_' + jail_name + '_newest_id'] }}
|
|
ip4_addr = {{ vars['jail_' + jail_name + '_new_ip4'] }}
|
|
when: not jail_THIS_with_ip6
|
|
|
|
- name: Updating jails.ini (IPv6+4)
|
|
blockinfile:
|
|
create: yes
|
|
dest: '{{ dynamic_jails_path }}/configs/jails.ini'
|
|
marker: '# {mark} ANSIBLE MANAGED BLOCK: {{ jail_name }}'
|
|
block: |
|
|
[{{ jail_name }}]
|
|
name = {{ vars['jail_' + jail_name + '_newest_id'] }}
|
|
ip4_addr = {{ vars['jail_' + jail_name + '_new_ip4'] }}
|
|
ip6_addr = {{ jail_THIS_with_ip6 }}
|
|
when: 'jail_THIS_with_ip6 != False'
|
|
|
|
# vim: sw=2
|