Created
May 21, 2022 04:44
-
-
Save crpb/0061b2b5272c64b23db3e95ced44fa31 to your computer and use it in GitHub Desktop.
ansible hosts.yaml generated from ssh_config files
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
#!/usr/bin/env bash | |
# Generate hosts.yaml from ssh_config-Includes | |
# Filename-Pattern "NNN_customer.ssh" | |
SRC="$HOME/git/ssh_config/*.ssh" | |
printf "all:\n children:\n" | |
for CONF in ${SRC}; do | |
BASE=$(basename "${CONF}") | |
GROUP=${BASE:4:-4} | |
HOSTS=$(awk '/^Host / {print $2}' "${CONF}"|sort|uniq) | |
printf ' %s:\n hosts:\n' "${GROUP}" | |
for NAME in $HOSTS; do | |
printf ' %s:\n' "${NAME}" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment