Skip to content

Instantly share code, notes, and snippets.

@crpb
Created May 21, 2022 04:44
Show Gist options
  • Save crpb/0061b2b5272c64b23db3e95ced44fa31 to your computer and use it in GitHub Desktop.
Save crpb/0061b2b5272c64b23db3e95ced44fa31 to your computer and use it in GitHub Desktop.
ansible hosts.yaml generated from ssh_config files
#!/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