Saltstack Official OpenSSH Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1KB

  1. {%- set ssh_config = pillar.get('ssh_config', {}) -%}
  2. {#- present in ssh_config and known in actual file options -#}
  3. {%- set processed_options = [] -%}
  4. {#- generic renderer used for ssh matches, known options, -#}
  5. {#- and unknown options -#}
  6. {%- macro render_option(keyword, default, config_dict=ssh_config) -%}
  7. {%- set value = config_dict.get(keyword, default) -%}
  8. {%- if value is sameas true -%}
  9. {{ keyword }} yes
  10. {%- elif value is sameas false -%}
  11. {{ keyword }} no
  12. {%- elif value is string or value is number -%}
  13. {{ keyword }} {{ value }}
  14. {%- else -%}
  15. {%- for single_value in value -%}
  16. {{ keyword }} {{ single_value }}
  17. {% endfor -%}
  18. {%- endif -%}
  19. {%- endmacro -%}
  20. {#- macros for render option according to present -#}
  21. {%- macro option_impl(keyword, default, present) -%}
  22. {%- if present -%}
  23. {%- do processed_options.append(keyword) -%}
  24. {%- set prefix='' -%}
  25. {%- else -%}
  26. {%- set prefix='#' -%}
  27. {%- endif -%}
  28. {#- add prefix to keyword -#}
  29. {%- set keyword = prefix ~ keyword -%}
  30. {{ render_option(keyword, default) }}
  31. {%- endmacro -%}
  32. {#- macros for render option commented by default -#}
  33. {%- macro option(keyword, default, present) -%}
  34. {{ option_impl(keyword, default, keyword in ssh_config) }}
  35. {%- endmacro -%}
  36. {#- macros for render option uncommented by default -#}
  37. {%- macro option_default_uncommented(keyword, default, present) -%}
  38. {{ option_impl(keyword, default, True) }}
  39. {%- endmacro -%}
  40. # Do not edit this file manually!
  41. # It will be overwritten by salt!
  42. {{ option_default_uncommented('Host', '*') }}
  43. {{ option(' ForwardAgent', 'no') }}
  44. {{ option(' ForwardX11', 'no') }}
  45. {{ option(' RhostsRSAAuthentication', 'no') }}
  46. {{ option(' RSAAuthentication', 'yes') }}
  47. {{ option(' PasswordAuthentication', 'yes') }}
  48. {{ option(' HostbasedAuthentication', 'no') }}
  49. {{ option(' GSSAPIAuthentication', 'no') }}
  50. {{ option(' GSSAPIDelegateCredentials', 'no') }}
  51. {{ option(' BatchMode', 'no') }}
  52. {{ option(' CheckHostIP', 'yes') }}
  53. {{ option(' AddressFamily', 'any') }}
  54. {{ option(' ConnectTimeout', 0) }}
  55. {{ option(' StrictHostKeyChecking', 'ask') }}
  56. {{ option(' IdentityFile', '~/.ssh/id_rsa') }}
  57. {{ option(' Port', 22) }}
  58. {{ option(' Protocol', 2) }}
  59. {{ option(' Cipher', '3des') }}
  60. {{ option(' Tunnel', 'no') }}
  61. {{ option(' TunnelDevice', 'any:any') }}
  62. {{ option(' PermitLocalCommand', 'no') }}
  63. {{ option(' VisualHostKey', 'no') }}
  64. {# Handling unknown in salt template options #}
  65. {%- for keyword in ssh_config.keys() %}
  66. {#- Matches have to be at the bottom and should be handled differently -#}
  67. {%- if not keyword in processed_options and keyword != 'matches' -%}
  68. {#- send a blank default as it doesn't matter #}
  69. {{ render_option(keyword, '') }}
  70. {%- endif -%}
  71. {%- endfor %}
  72. {# Handle matches last as they need to go at the bottom #}
  73. {%- if 'matches' in ssh_config %}
  74. {%- for match in ssh_config['matches'].values() %}
  75. Match {{ match['type'].keys()[0] }} {{ match['type'].values()[0] }}
  76. {%- for keyword in match['options'].keys() %}
  77. {{ render_option(keyword, '', config_dict=match['options']) }}
  78. {%- endfor %}
  79. {%- endfor %}
  80. {%- endif %}