-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathansible-ssh
executable file
·41 lines (28 loc) · 1.09 KB
/
ansible-ssh
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
#!/bin/bash
# Copyright 2019 Sven Anders <[email protected]>
ARG=$1
if [ -z "$ARG" ] ; then
echo 'please spezify a hostname' >&2
exit 1
fi
if [ ${ARG:0:10} == "host_vars/" ] ; then
echo Found host_vars-file as argument
ARG=${ARG:10:${#ARG}}
ARG=${ARG:0:${#ARG} - 4}
echo revised argument: $ARG
fi
JQ=$(which jq)
if [ -z "$JQ" ] ; then
echo 'jq not found, please install it with "apt install jq"' >&2
exit 2
fi
JSON=$(ansible-inventory --host=${ARG})
ANSIBLE_HOST=$(echo $JSON |$JQ -r .ansible_host )
ANSIBLE_PORT=$(echo $JSON |$JQ -r '.ansible_port // 22' )
ANSIBLE_USER=$(echo $JSON |$JQ -r '.ansible_user // "root"' )
ANSIBLE_ARGS=$(echo $JSON |$JQ -r '.ansible_ssh_common_args // ""')
echo '= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ='
echo ssh -A -p $ANSIBLE_PORT -l $ANSIBLE_USER $ANSIBLE_ARGS $ANSIBLE_HOST
echo scp -P $ANSIBLE_PORT -l $ANSIBLE_USER $ANSIBLE_ARGS $ANSIBLE_HOST:/some/file myfile
echo '= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ='
eval "ssh -A -p $ANSIBLE_PORT -l $ANSIBLE_USER $ANSIBLE_ARGS $ANSIBLE_HOST"