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.

39 lines
1.6KB

  1. {#
  2. # vi:syntax=jinja
  3. #}
  4. {%- set target = salt['pillar.get']('openssh:known_hosts:target', '*') -%}
  5. {%- set expr_form = salt['pillar.get']('openssh:known_hosts:expr_form', 'glob') -%}
  6. {%- set keys_function = salt['pillar.get']('openssh:known_hosts:mine_keys_function', 'public_ssh_host_keys') -%}
  7. {%- set hostname_function = salt['pillar.get']('openssh:known_hosts:mine_hostname_function', 'public_ssh_hostname') -%}
  8. {#- Lookup IP of all aliases so that when we have a matching IP, we inject the alias name
  9. in the SSH known_hosts entry -#}
  10. {%- set aliases = salt['pillar.get']('openssh:known_hosts:aliases', []) -%}
  11. {%- set aliases_ips = {} -%}
  12. {%- for alias in aliases -%}
  13. {%- for ip in salt['dig.A'](alias) + salt['dig.AAAA'](alias) -%}
  14. {%- do aliases_ips.setdefault(ip, []).append(alias) -%}
  15. {%- endfor -%}
  16. {%- endfor -%}
  17. {#- Loop over targetted minions -#}
  18. {%- set host_keys = salt['mine.get'](target, keys_function, expr_form=expr_form) -%}
  19. {%- set host_names = salt['mine.get'](target, hostname_function, expr_form=expr_form) -%}
  20. {%- for host, keys in host_keys|dictsort -%}
  21. {%- set ip4 = salt['dig.A'](host) -%}
  22. {%- set ip6 = salt['dig.AAAA'](host) -%}
  23. {%- set names = [host_names.get(host, host)] -%}
  24. {%- for ip in ip4 + ip6 -%}
  25. {%- do names.append(ip) -%}
  26. {%- for alias in aliases_ips.get(ip, []) -%}
  27. {%- if alias not in names -%}
  28. {%- do names.append(alias) -%}
  29. {%- endif -%}
  30. {%- endfor -%}
  31. {%- endfor -%}
  32. {%- for line in keys.split('\n') -%}
  33. {%- if line -%}
  34. {{ ','.join(names) }} {{ line }}
  35. {% endif -%}
  36. {%- endfor -%}
  37. {%- endfor -%}