This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bash_aliases_ansible
57 lines (53 loc) · 1.9 KB
/
.bash_aliases_ansible
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Aliases for the ansible docker image
#
# What the command is doing:
# gather arguments to the variable
# starting docker run command
# remove container after command complete
# allocate a pseudo-tty, keep STDIN open even if not attached
# mounting current directory as ansible working directory
# mounting ssh configuration of current user to the container, read only
#
# To use these:
#
# 1) Copy this file to somewhere (e.g. ~/.bash_aliases_ansible).
# 2) Add the following line to your .bashrc/.zshrc:
# source ~/.bash_aliases_ansible
#
# or simply type `. .bash_aliases_ansible` for one time using
#
alias ansible-playbook="__pre_configuration && __ansible_docker_run_template ansible-playbook"
alias ansible="__pre_configuration && __ansible_docker_run_template ansible"
alias ansible-galaxy="__pre_configuration && __ansible_docker_run_template ansible-galaxy"
alias ansible-vault="__pre_configuration && __ansible_docker_run_template ansible-vault"
alias ansible-doc="__pre_configuration && __ansible_docker_run_template ansible-doc"
__pre_configuration() {
export ANSIBLE_SSH_ARGS
mkdir -p $HOME/.ansible
mkdir -p $HOME/.ssh
touch $HOME/.ssh/known_hosts
if test -z "$(docker images -q metalguardian/ansible:latest)"; then
docker pull --quiet metalguardian/ansible:latest
fi
}
__ansible_docker_run_template() {
local arguments="$@"
docker run \
--rm \
-ti \
--env TERM \
--env SSH_AUTH_SOCK \
--env ANSIBLE_SSH_ARGS \
--env HOME \
--user=`id -u`:`id -g` \
--init \
--net host \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v ${HOME}/.ansible:${HOME}/.ansible \
-v ${HOME}/.ssh/known_hosts:${HOME}/.ssh/known_hosts:ro \
-v $(pwd):$(pwd) -w $(pwd) \
-v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK \
metalguardian/ansible \
${arguments}
}