Skip to content

Instantly share code, notes, and snippets.

@sbz
Last active April 17, 2023 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbz/752e8475d035ee50f598f8dc21f80997 to your computer and use it in GitHub Desktop.
Save sbz/752e8475d035ee50f598f8dc21f80997 to your computer and use it in GitHub Desktop.
Get FreeBSD ansible facts using jq script function to pick selected facts
$ 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