Refactor cloud-init element

There is no need in pipe and sudo for changing /etc/cloud/cloud.cfg

TrivialFix

Change-Id: I905e8d3964f1322ec3ccc2eb09c517a02ef88044
Signed-off-by: Maksim Malchuk <maksim.malchuk@gmail.com>
This commit is contained in:
Maksim Malchuk 2023-09-15 17:40:36 +03:00
parent c2853c6f2c
commit bccea6d5f0

View File

@ -9,9 +9,9 @@ set -o pipefail
# Set cloud-init to allow password authentication # Set cloud-init to allow password authentication
if [ -n "${DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH:-}" ]; then if [ -n "${DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH:-}" ]; then
if [ -f "/etc/cloud/cloud.cfg" ]; then if [ -f "/etc/cloud/cloud.cfg" ]; then
if [ -z "$(cat /etc/cloud/cloud.cfg | grep ssh_pwauth)" ]; then if [ -z "$(grep ssh_pwauth /etc/cloud/cloud.cfg)" ]; then
echo "ssh_pwauth not exist. append to EOF" echo "ssh_pwauth not exist. append to EOF"
sudo sh -c 'echo "ssh_pwauth: 1" >> /etc/cloud/cloud.cfg' echo "ssh_pwauth: 1" >> /etc/cloud/cloud.cfg
else else
echo "ssh_pwauth exist. make sure ssh_pwauth enabled" echo "ssh_pwauth exist. make sure ssh_pwauth enabled"
sed -i -e 's/ssh_pwauth: *0/ssh_pwauth: 1/g' /etc/cloud/cloud.cfg sed -i -e 's/ssh_pwauth: *0/ssh_pwauth: 1/g' /etc/cloud/cloud.cfg