ansible-role-easy-rsa/templates/server-host-certificate.sh.j2

53 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2020-09-10 16:50:33 +02:00
#!/bin/bash
2022-01-19 18:52:58 +01:00
_retval=
2020-09-10 16:50:33 +02:00
host_arg=
if [ $# -ne 1 ] ; then
echo "You need to pass just one argument: the full hostname for wich the certificate is required"
exit 1
else
host_arg="$1"
fi
easy_rsa_base_dir={{ easy_rsa_pki_basedir }}
easy_rsa_issued_dir="${easy_rsa_base_dir}/pki/issued"
easy_rsa_keys_dir="${easy_rsa_base_dir}/pki/private"
2022-01-19 18:52:58 +01:00
easy_rsa_reqs_dir="${easy_rsa_base_dir}/pki/reqs"
2020-09-10 16:50:33 +02:00
easy_vars_file="${easy_rsa_base_dir}/vars"
if [ -f "${easy_vars_file}.tmpl" ] ; then
echo "There's a template file ${easy_vars_file}.tmpl present. Check that nothing wrong happened, then remove it before proceeding."
exit 1
fi
2022-01-19 18:52:58 +01:00
if [ -f "${easy_rsa_issued_dir}/${host_arg}.crt" ] ; then
echo ""
2023-01-27 13:13:14 +01:00
echo "A certificate already exists."
echo "If you want to renew it, then use the command renew-server-host-certificate"
2022-01-19 18:52:58 +01:00
echo ""
exit 1
fi
2020-09-10 16:50:33 +02:00
echo ""
echo "Starting the creation of a server host certificate."
echo ""
cd "$easy_rsa_base_dir"
./easyrsa build-server-full "$host_arg" nopass
2022-01-19 18:52:58 +01:00
retval=$?
2020-09-10 16:50:33 +02:00
2022-01-19 18:52:58 +01:00
if [ $retval -eq 0 ] ; then
echo ""
echo "Done."
echo "The certificate file is ${easy_rsa_issued_dir}/${host_arg}.crt"
echo "The private key file is ${easy_rsa_keys_dir}/${host_arg}.key"
echo ""
echo "Remember that the key of the host certificates do not passphrase protected"
else
echo ""
echo "Something went wrong, the certificate creation failed"
echo ""
fi
2020-09-10 16:50:33 +02:00
exit 0