Skip to content

Instantly share code, notes, and snippets.

@aspen-roller
Created January 6, 2021 01:22
Show Gist options
  • Save aspen-roller/a293d9c45fa835d1307a2c0fc923617c to your computer and use it in GitHub Desktop.
Save aspen-roller/a293d9c45fa835d1307a2c0fc923617c to your computer and use it in GitHub Desktop.
query node.js version #ansible #util
# ensure JSON output with ANSIBLE_STDOUT_CALLBACK
# remove all lines before the first '{'
# remove all lines after the last '}'
# use jq to query the stdout value from the command
# ASSUMPTION
# there is a group "services" that identifies machines with node.js installed
ANSIBLE_STDOUT_CALLBACK=json ansible services -i inventories/dev -m command -a 'node --version' -v | sed '1,/^[^{]/d' | sed '/^}/q' | jq -r '.plays[].tasks[].hosts | keys[] as $k | "\($k): \(.[$k] | .stdout)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment