Created
January 26, 2019 16:51
-
-
Save ouyi/a75089a38ad0cd42c088c01cba651e19 to your computer and use it in GitHub Desktop.
Ansible list hosts from a host group
This file contains 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
#!/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