Last active
April 17, 2023 20:51
-
-
Save sbz/752e8475d035ee50f598f8dc21f80997 to your computer and use it in GitHub Desktop.
Get FreeBSD ansible facts using jq script function to pick selected facts
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
$ cat <<EOF > reduce.jq | |
def pick($paths): | |
. as $root | reduce $paths[] as $path ({}; . + { ($path): $root[$path] }); | |
.ansible_facts | pick(["ansible_kernel", "ansible_distribution", "ansible_kernel_version"]) | |
EOF | |
$ ansible -m setup localhost | sed '1 s/^.*|.*=>.*$/{/g' | jq -f reduce.jq | |
{ | |
"ansible_kernel": "13.1-RELEASE-p3", | |
"ansible_distribution": "FreeBSD", | |
"ansible_kernel_version": "FreeBSD 13.1-RELEASE-p3 GENERIC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment