Просмотр исходного кода

ssh_config: properly render host options (#149)

* ssh_config: properly render host options (fixes #145)

* ssh_config: whitespace optimization (fixes #145)
tags/v0.41.0
alxwr 6 лет назад
Родитель
Сommit
3f9876fc40
1 измененных файлов: 24 добавлений и 7 удалений
  1. +24
    -7
      openssh/files/ssh_config

+ 24
- 7
openssh/files/ssh_config Просмотреть файл

{%- endif -%} {%- endif -%}
{%- endmacro -%} {%- endmacro -%}


{%- macro render_host_option(keyword, value) -%}
{%- if value is sameas true %}
{{ keyword }} yes
{%- elif value is sameas false %}
{{ keyword }} no
{%- elif value is string or value is number %}
{{ keyword }} {{ value }}
{%- else -%}
{%- if keyword in string_or_list_options %}
{{ keyword }} {{ value|join(',') }}
{%- else %}
{%- for single_value in value -%}
{{ keyword }} {{ single_value }}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

{#- generic renderer used for ssh matches, known options, -#} {#- generic renderer used for ssh matches, known options, -#}
{#- and unknown options -#} {#- and unknown options -#}
{%- macro render_option(keyword, default, config_dict=ssh_config) -%} {%- macro render_option(keyword, default, config_dict=ssh_config) -%}
{%- do processed_options.append('Hosts') %} {%- do processed_options.append('Hosts') %}
{% for host, conf in ssh_config['Hosts'].items() %} {% for host, conf in ssh_config['Hosts'].items() %}
Host {{ host }} Host {{ host }}
{%- for key, val in conf.items() %}
{{ render_raw_option(key, val) }}
{%- for key, val in conf.items() -%}
{{ render_host_option(key, val) }}
{%- endfor %} {%- endfor %}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}


{# Handling unknown in salt template options #} {# Handling unknown in salt template options #}
{%- for keyword in ssh_config.keys() %}
{% for keyword in ssh_config.keys() -%}
{#- Matches have to be at the bottom and should be handled differently -#} {#- 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 processed_options and keyword != 'matches' -%}
{%- if not keyword in string_or_list_options -%} {%- if not keyword in string_or_list_options -%}
{{ option_string_or_list(keyword, '', True) }} {{ option_string_or_list(keyword, '', True) }}
{%- endif -%} {%- endif -%}
{%- endif -%} {%- endif -%}
{%- endfor %}
{%- endfor -%}


{# Handle matches last as they need to go at the bottom #} {# Handle matches last as they need to go at the bottom #}
{%- if 'matches' in ssh_config %}
{% if 'matches' in ssh_config -%}
{%- for match in ssh_config['matches'].values() %} {%- for match in ssh_config['matches'].values() %}
Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }} Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }}
{%- for keyword in match['options'].keys() %} {%- for keyword in match['options'].keys() %}
{{ render_option(keyword, '', config_dict=match['options']) }} {{ render_option(keyword, '', config_dict=match['options']) }}
{%- endfor %} {%- endfor %}
{%- endfor %} {%- endfor %}
{%- endif %}
{%- endif -%}


{#- vim: set ft=jinja : #} {#- vim: set ft=jinja : #}


Загрузка…
Отмена
Сохранить