Apply string-or-list processing to ssh_config

Now ssh_config also accepts string-or-list options, for serveral
keywords.
This commit is contained in:
Pandu E Poluan 2017-01-24 01:34:24 +07:00
parent 30648d115e
commit 773d9ae092

View File

@ -2,6 +2,7 @@
{%- set ssh_config = salt['pillar.get']('ssh_config', default=default_settings.ssh_config, merge=True) -%}
{#- present in ssh_config and known in actual file options -#}
{%- set processed_options = [] -%}
{%- set string_or_list_options = ['KexAlgorithms', 'Ciphers', 'MACs'] -%}
{%- macro render_raw_option(keyword, value) -%}
{%- if value is sameas true -%}
@ -47,8 +48,31 @@
{{ option_impl(keyword, default, True) }}
{%- endmacro -%}
{#- macro for collapsing a list into a string -#}
{%- macro option_collapselist(keyword, sep) -%}
{%- do processed_options.append(keyword) -%}
{{keyword}} {{ssh_config.get(keyword)|join(sep)}}
{%- endmacro -%}
{#- macro for handling an option that can be specified as a list or a string -#}
{%- macro option_string_or_list(keyword, default, default_commented, sep=',') -%}
{%- if ssh_config.get(keyword, '') is string -%}
{%- if default_commented -%}
{{ option(keyword, default) }}
{%- else -%}
{{ option_default_uncommented(keyword, default) }}
{%- endif -%}
{%- else -%}
{{ option_collapselist(keyword, sep) }}
{%- endif -%}
{%- endmacro -%}
{%- if ssh_config.get('ConfigBanner', False) -%}
{{ ssh_config['ConfigBanner'] }}
{%- else -%}
# Do not edit this file manually!
# It will be overwritten by salt!
{%- endif %}
{%- if 'Hosts' in ssh_config %}
{%- do processed_options.append('Hosts') %}
@ -64,8 +88,13 @@ Host {{ host }}
{%- for keyword in ssh_config.keys() %}
{#- Matches have to be at the bottom and should be handled differently -#}
{%- if not keyword in processed_options and keyword != 'matches' -%}
{%- if not keyword in string_or_list_options -%}
{#- send a blank default as it doesn't matter #}
{{ render_option(keyword, '') }}
{%- else -%}
{#- same as above #}
{{ option_string_or_list(keyword, '', True) }}
{%- endif -%}
{%- endif -%}
{%- endfor %}
@ -78,3 +107,6 @@ Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }}
{%- endfor %}
{%- endfor %}
{%- endif %}
{#- vim: set ft=jinja : #}