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.

35 line
1.5KB

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