Last active
July 15, 2021 06:17
-
-
Save KeyboardInterrupt/a885efe64824a070670a6f71db2038ab to your computer and use it in GitHub Desktop.
I made these Snippets for Inventory to SSH configuration conversion. USE WITH CAUTION the default `StrictHostKeyChecking no` is weakening security by ignoring Host ssh key changes!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cat ~/.ssh/config.d/* | |
echo "#################################################" | |
echo "# This will be your new ssh config, is this ok? #" | |
echo "#################################################" | |
read -p "Build Config! (y/n)?" choice | |
case "$choice" in | |
y|Y ) echo "yes" && cat ~/.ssh/config.d/* > ~/.ssh/config ;; | |
n|N ) echo "no";; | |
* ) echo "invalid";; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
gather_facts: False | |
vars: | |
ssh_config_path: ~/.ssh/config.d/ | |
vars_prompt: | |
- name: "config_name" | |
prompt: "Name your config file!" | |
default: "tmp" | |
private: False | |
tasks: | |
- name: generate SSH Config for [all] Hosts | |
local_action: | |
module: copy | |
content: | | |
## {{ config_name }} ## | |
{% for host in groups['all'] %} | |
Host {{ hostvars[host].inventory_hostname }} | |
StrictHostKeyChecking no | |
User {{ ansible_user | default(ansible_ssh_user) | default(lookup('env','USER')) }} | |
ServerAliveInterval 60 | |
ServerAliveCountMax 2 | |
HostName {{ hostvars[host]['ansible_host'] | default( hostvars[host]['ansible_ssh_host'] ) | default("NO_ADDRESS_GIVEN") }} | |
{% if hostvars[host]['ansible_ssh_common_args'] is defined %}{{ hostvars[host]['ansible_ssh_common_args'].strip('"') | regex_replace('^-o ','') | regex_replace('="',' ') }}{% endif %} | |
{% endfor %} | |
dest: "{{ ssh_config_path }}{{ config_name }}" | |
run_once: True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment