Last active
August 7, 2018 20:32
-
-
Save donpdonp/388764e85540cb14414e1a0c3352e242 to your computer and use it in GitHub Desktop.
terraform state file to ansible inventory, grouped by first tag value.
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
JQ='.modules[0].resources | |
| map(select(.primary.attributes."tags.0") | |
| { tag: .primary.attributes."tags.0", ip: .primary.attributes.ipv4_address, name: .primary.attributes.name }) | |
| group_by(.tag) | |
| map (["["+.[0].tag+"]", (map([.name, "ansible_ssh_host=" + .ip] | join(" ")) | join("\n"))]|join("\n") ) | |
| join("\n\n")' | |
jq -r "$JQ" $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Groups terraform resources by tag value into the ansible inventory format.