Skip to content

Instantly share code, notes, and snippets.

@William-Yeh
Created August 27, 2015 09:00
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 William-Yeh/61ac7524bd4b5d865241 to your computer and use it in GitHub Desktop.
Save William-Yeh/61ac7524bd4b5d865241 to your computer and use it in GitHub Desktop.
Convenient BASH aliases for Ansible and Vagrant
alias vagrant-destroy='vagrant halt ; vagrant destroy --force'
_ansible_as_sudo_internal() {
local user="$1"
local host_pattern="$2"
shift
shift
ANSIBLE_HOST_KEY_CHECKING=false ansible "$host_pattern" \
-u "$user" -k "$@"
}
_ansible_with_key_internal() {
local key="$1"
local host_pattern="$2"
shift
shift
ANSIBLE_HOST_KEY_CHECKING=false ansible "$host_pattern" \
--private-key "$key" "$@"
}
_ansible_to_vagrant_internal() {
local inv_path="$1"
local host_pattern="$2"
shift
shift
ANSIBLE_HOST_KEY_CHECKING=false \
expect -f - <<-EO_A2V
spawn ansible "$host_pattern" \
-u vagrant --ask-pass \
-i "$inv_path" \
$@ ; \
expect "SSH password:" ; \
send "vagrant\n"; \
expect eof;
EO_A2V
}
alias ansible-as-sudo='_ansible_as_sudo_internal '
alias ansible-with-key='_ansible_with_key_internal . '
alias ansible-to-vagrant='_ansible_to_vagrant_internal .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory '
alias ansible-to-vagrant-inv='_ansible_to_vagrant_internal '
alias ansible-playbook-as-root='ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook -k -u root '
alias ansible-playbook-as-sudo='ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook -k -u '
alias ansible-playbook-with-key='ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook --private-key '
_playbook_to_vagrant_internal() {
local inv_path="$1"
shift
ANSIBLE_HOST_KEY_CHECKING=false \
expect -f - <<-EO_AP2V
spawn ansible-playbook \
-u vagrant --ask-pass \
-i "$inv_path" \
$@ ; \
expect "SSH password:" ; \
send "vagrant\n"; \
expect eof;
EO_AP2V
}
alias playbook-to-vagrant='_playbook_to_vagrant_internal .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory '
alias playbook-to-vagrant-inv='_playbook_to_vagrant_internal '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment