ansible-freebsd-jailhost-tools/tasks/jail/create.yml

76 lines
2.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_ip: '{{ available_jail_ip }}'
- 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"] }}'
mountpoint: '{{ vars["jail_" + jail_name + "_new_path"] }}'
state: present
- name: Copy rc.conf over to the new jail
copy:
src: rc.conf
dest: '{{ vars["jail_" + jail_name + "_new_path"] }}/etc'
- name: Copy resolv.conf over to the new jail
copy:
src: /etc/resolv.conf
dest: '{{ vars["jail_" + jail_name + "_new_path"] }}/etc'
- name: Setup timezone in jail
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|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|changed
- name: Updating jails.ini
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_ip'] }}