Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Last active March 2, 2023 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudnull/9c12c86f1b5b7c14c068a581b094ba3e to your computer and use it in GitHub Desktop.
Save cloudnull/9c12c86f1b5b7c14c068a581b094ba3e to your computer and use it in GitHub Desktop.
Using the ARA CLI Client, return unique hosts where a task is found and in a defined state.
function ara-task-uniq-hosts () {
# Scans across all tasks within 1 million records and returns all of the unique hosts where the task
# meets a certain state. Default state is "ok"
# When looking for the "changed" state the special CLI modifier is used.
TASK_NAME=$1
TASK_STATE=${2:-ok}
if [ ${TASK_STATE} == "changed" ]; then
TASK_MODIFY="--changed"
else
TASK_MODIFY="--status ${TASK_STATE}"
fi
/opt/ara/server/bin/ara task list --name "$TASK_NAME" -f value -c id --limit 1000000 | \
xargs -i /opt/ara/server/bin/ara result list --task {} -f value -c host ${TASK_MODIFY} --limit 1000000 | \
sort -u |
xargs -i /opt/ara/server/bin/ara host show {} -f value -c name |
sort -u
}
function ara-playbook-user-task-uniq-hosts () {
# Scans across all playbooks executed by a partivular user within 1 million records and returns
# all of the unique hosts where the task meets a certain state. Default state is "ok"
# When looking for the "changed" state the special CLI modifier is used.
PLAYBOOK_USER=$1
TASK_NAME=$2
TASK_STATE=${3:-ok}
if [ ${TASK_STATE} == "changed" ]; then
TASK_MODIFY="--changed"
else
TASK_MODIFY="--status ${TASK_STATE}"
fi
/opt/ara/server/bin/ara playbook list --user "${PLAYBOOK_USER}" -f value -c id --limit 1000000 |
xargs -i /opt/ara/server/bin/ara task list --playbook {} --name "${TASK_NAME}" -f value -c id --limit 1000000 | \
xargs -i /opt/ara/server/bin/ara result list --task {} -f value -c host ${TASK_MODIFY} --limit 1000000 | \
sort -u |
xargs -i /opt/ara/server/bin/ara host show {} -f value -c name |
sort -u
}
function ara-playbook-user-host-uniq-hosts () {
# Scans across all playbooks executed by a partivular user within 1 million records and returns
# all of the unique hosts.
PLAYBOOK_USER=$1
/opt/ara/server/bin/ara playbook list --user "${PLAYBOOK_USER}" -f value -c id --limit 1000000 |
xargs -i /opt/ara/server/bin/ara host list --playbook {} -f value -c name --limit 1000000 | \
sort -u
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment