Skip to content

Instantly share code, notes, and snippets.

@ouyi
Created January 26, 2019 16: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 ouyi/a75089a38ad0cd42c088c01cba651e19 to your computer and use it in GitHub Desktop.
Save ouyi/a75089a38ad0cd42c088c01cba651e19 to your computer and use it in GitHub Desktop.
Ansible list hosts from a host group
#!/usr/bin/env bash
if (( $# < 2 )); then
echo "Usage: $0 inventory host_group [other ansible options]"
exit 1
fi
inventory="$1"
host_group="$2"
shift 2
ansible -i "$inventory" "$host_group" --list-hosts $@
# Example
# ansible-list-hosts.sh dev/inventory my_host_group --vault-password-file ~/data/configs/ansible/vault-password-dev.txt
# Ansible ad hoc commands
# ansible -i dev --vault-password-file ~/data/configs/ansible/vault-password-dev.txt my_host_group -a 'echo hello'
# ansible -i dev --vault-password-file ~/data/configs/ansible/vault-password-dev.txt my_host_group -m shell -a 'hostname'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment