add create ssh config script

This commit is contained in:
2026-02-03 18:49:15 -06:00
parent 7046191ef1
commit 332f7bf983
3 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
## From https://github.com/russStarr/ssh_config_from_inventory
## License: Apache 2.0 (yes, that is all that was included in the original)
{% for host in groups['all'] %}
{% if keepgroupnames is defined and keepgroupnames == "True" %}
Host {{ hostvars[host]['inventory_hostname_short'] }}{% for group in hostvars[host]['group_names'] %} {{ group }}.{{ hostvars[host]['inventory_hostname_short'] }}{% endfor %}
{% else %}
Host {{ hostvars[host]['inventory_hostname_short'] }}
{% endif %}
{% if hostvars[host]['ansible_host'] is defined %}
HostName {{ hostvars[host]['ansible_host'] }}
{% elif hostvars[host]['ansible_ssh_host'] is defined %}
HostName {{ hostvars[host]['ansible_ssh_host'] }}
{% else %}
HostName {{ host }}
{% endif %}
{% if hostvars[host]['ansible_port'] is defined %}
Port {{ hostvars[host]['ansible_port'] }}
{% elif hostvars[host]['ansible_ssh_port'] is defined %}
Port {{ hostvars[host]['ansible_ssh_port'] }}
{% endif %}
{% if hostvars[host]['ansible_user'] is defined %}
User {{ hostvars[host]['ansible_user'] }}
{% elif hostvars[host]['ansible_ssh_user'] is defined %}
User {{ hostvars[host]['ansible_ssh_user'] }}
{% endif %}
{% if hostvars[host]['ansible_ssh_private_key_file'] is defined %}
IdentityFile {{ hostvars[host]['ansible_ssh_private_key_file'] }}
{% endif %}
{% if hostvars[host]['ansible_ssh_common_args'] is defined %}
ProxyCommand {{ hostvars[host]['ansible_ssh_common_args'] | regex_replace('^.*ProxyCommand=\'(.*?)\'.*', '\\1') }}
{% endif %}
{% endfor %}