Last active
August 29, 2015 14:18
-
-
Save aabouzaid/33f4233d71d44bb31a0b to your computer and use it in GitHub Desktop.
Simple snippet to reformat hosts in ssh conf file to Ansible inventory file format.
This file contains hidden or 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 | |
#This snippet assume each "Host", "Hostname", "Port", "User" in separated line, and valid ssh config file. | |
ssh_conf_to_ansible () { | |
awk 'BEGIN{IGNORECASE=1} | |
{gsub(/\s+/," "); | |
gsub("Host ",""); | |
gsub("Hostname ","ansible_ssh_host="); | |
gsub("Port ","ansible_ssh_port="); | |
gsub("User ","ansible_ssh_user=")}; | |
NR%4{printf $0" "; | |
next; | |
}1' | |
} | |
egrep -i "^(Host|Hostname|Port|User)" ~/.ssh/config | ssh_conf_to_ansible |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment