-
Notifications
You must be signed in to change notification settings - Fork 1
/
inventory-jetp.pkgx
executable file
·54 lines (48 loc) · 1.52 KB
/
inventory-jetp.pkgx
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
#!/usr/bin/env -S pkgx --silent +gnu.org/bash^5 bash
function get_ssh_key_path {
if [[ -z ${CONSTRUCTOR_SSH_KEY_PATH} || ! -v CONSTRUCTOR_SSH_KEY_PATH ]]; then
printf -v CONSTRUCTOR_SSH_KEY_PATH \
'%s' \
"$(task -s --taskfile ${parent_script_dir_path}/Taskfile.yml constructor:get_ssh_key_path)"
fi
}
function get_remote_fqdn {
if [[ -z ${REMOTE_FQDN} || ! -v REMOTE_FQDN ]]; then
printf -v REMOTE_FQDN \
'%s' \
"$(task -s --taskfile ${parent_script_dir_path}/Taskfile.yml constructor:get_remote_fqdn)"
fi
}
function get_remote_user {
if [[ -z ${REMOTE_USER} || ! -v REMOTE_USER ]]; then
printf -v REMOTE_USER \
'%s' \
"$(task -s --taskfile ${parent_script_dir_path}/Taskfile.yml constructor:get_remote_user)"
fi
}
function main {
local -r script_path="$(realpath "${BASH_SOURCE[0]}")"
local -r script_dir_path="$(dirname "${script_path}")"
local -r parent_script_dir_path="$(dirname "${script_dir_path}")"
local -r temp_dir_path="${script_dir_path}/temp"
local -r inventory_file_name='inventory.json'
local -r inventory_file_path="${temp_dir_path}/${inventory_file_name}"
mkdir -p "${temp_dir_path}"
get_remote_fqdn
get_remote_user
get_ssh_key_path
cat <<EOF > "${inventory_file_path}"
{
"targets": {
"hostvars": {
"${REMOTE_FQDN:-UNSET}": {
"jet_ssh_user": "${REMOTE_USER:-UNSET}",
"jet_ssh_key_comment": "${CONSTRUCTOR_SSH_KEY_PATH:-UNSET}"
}
}
}
}
EOF
cat "${inventory_file_path}"
}
main