Created
January 14, 2015 00:02
-
-
Save aabouzaid/abf6f95bfb0fa1196dbe to your computer and use it in GitHub Desktop.
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 | |
#10 minutes Ansible module to list groups in inventory (AWK version) :D | |
#You can see outupt of script like "JSON Pretty Print" outside Ansible by using: | |
#./listgroups | python -m json.tool | |
awk 'BEGIN {ORS=" ";}; | |
/^\[/{gsub("[\[\]]",""); groups_number++; groups_array[groups_number]=$0}; | |
END { | |
print "{\"Inventory Groups\": ["; | |
for (group_in_array = 1; group_in_array <= groups_number-1; group_in_array++) printf "\"%s\", ",groups_array[group_in_array]; | |
printf "\"%s\"",groups_array[groups_number]; | |
print "]}" | |
}' /etc/ansible/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment