- 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 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_ip'] }}"; {{ _iter_flattened_config }} } - name: Starting jail command: jail -c {{ vars['jail_' + jail_name + '_newest_id'] }}