-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinventory-ansible.pkgx
executable file
·56 lines (50 loc) · 1.69 KB
/
inventory-ansible.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
55
56
#!/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": {
"hosts": ["${REMOTE_FQDN:-UNSET}"],
"vars": {
"ansible_host": "${REMOTE_FQDN:-UNSET}",
"ansible_user": "${REMOTE_USER:-UNSET}",
"hub_persistent_volume_path": "${HUB_PERSISTENT_VOLUME_PATH:-UNSET}",
"fileserver_export_path": "${FILESERVER_EXPORT_PATH:-UNSET}",
"jupyterhub_fqdn": "${JUPYTERHUB_FQDN:-UNSET}"
}
}
}
EOF
cat "${inventory_file_path}"
}
main