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

66 lines
2.4 KiB
YAML

- name: Formatting jail.conf options for {{ vars['jail_' + jail_name + '_newest_id'] }}
set_fact:
_iter_config_opts: >-
{{
jail_default_config_opts | combine(
vars["jail_" + jail_name + "_config_opts"] |default({})
)
}}
_iter_config_lines: []
- name: Converting config dict into config lines
set_fact:
_iter_config_lines: >-
{{ _iter_config_lines }} + {{
['%s = %s;'|format(
item.key,
'"%s"'|format(item.value) if item.value is string else
item.value|ternary('"true"', '"false"') if item.value.__class__.__name__ == 'bool' else item.value
)]
}}
with_dict: '{{ _iter_config_opts }}'
- name: Flattening config into one variable
set_fact:
_iter_flattened_config: "{{ _iter_config_lines|sort|join('\n ') }}"
- name: Writing config block for {{ vars['jail_' + jail_name + '_newest_id'] }} into /etc/jail.conf (IPv4)
blockinfile:
create: yes
state: present
dest: '/etc/jail.conf'
insertbefore: '^# vim: syn=conf$'
marker: '# {mark} ANSIBLE MANAGED BLOCK: {{ vars["jail_" + jail_name + "_newest_id"] }}'
block: |
{{ vars['jail_' + jail_name + '_newest_id'] }} {
path="{{ vars['jail_' + jail_name + '_new_path']|quote }}";
host.hostname="{{ vars['jail_' + jail_name + '_newest_id'] }}";
ip4.addr="lo0|{{ vars['jail_' + jail_name + '_new_ip4'] }}"/32;
{{ _iter_flattened_config }}
}
when: not jail_THIS_with_ip6
- name: Writing config block for {{ vars['jail_' + jail_name + '_newest_id'] }} into /etc/jail.conf (IPv4+6)
blockinfile:
create: yes
state: present
dest: '/etc/jail.conf'
insertbefore: '^# vim: syn=conf$'
marker: '# {mark} ANSIBLE MANAGED BLOCK: {{ vars["jail_" + jail_name + "_newest_id"] }}'
block: |
{{ vars['jail_' + jail_name + '_newest_id'] }} {
path="{{ vars['jail_' + jail_name + '_new_path']|quote }}";
host.hostname="{{ vars['jail_' + jail_name + '_newest_id'] }}";
ip4.addr="lo0|{{ vars['jail_' + jail_name + '_new_ip4'] }}/32";
ip6.addr="bridge0|{{ vars['jail_' + jail_name + '_ip6'] }}/128";
{{ _iter_flattened_config }}
}
when: 'jail_THIS_with_ip6 != False'
- name: Starting jail when no IPv6 present
command:
jail -c
{{
vars['jail_' + jail_name + '_newest_id']
}}
when: not jail_THIS_with_ip6