restart linux after rename
This commit is contained in:
@@ -25,6 +25,7 @@ locals {
|
||||
|
||||
snaploc = (var.location == "westeurope")? "weu" : (var.location == "eastus")? "" : "sea"
|
||||
storage_account_id = "/subscriptions/62ebff8f-c40b-41be-9239-252d6c0c8ad9/resourceGroups/QMI-Machines/providers/Microsoft.Storage/storageAccounts/machinesnapshots${local.snaploc}"
|
||||
restartAfter = (var.restartAfterRename == true)? "YES" : "NO"
|
||||
}
|
||||
|
||||
resource "azurerm_managed_disk" "md-import" {
|
||||
@@ -154,11 +155,11 @@ resource "null_resource" "post-vm-fromsnapshot-linux" {
|
||||
|
||||
inline = [
|
||||
"echo ${var.initial_password} | sudo -S chmod a+x /home/${local.admin_username}/provision-scripts/*.sh",
|
||||
"sudo /home/${local.admin_username}/provision-scripts/rename-machine.sh ${local.virtual_machine_name}",
|
||||
"sudo /home/${local.admin_username}/provision-scripts/setnewpassword.sh ${local.admin_username} ${local.admin_password}",
|
||||
"sudo /home/${local.admin_username}/provision-scripts/rename-machine.sh ${local.virtual_machine_name} ${local.restartAfter}",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Renaming machine to $1"
|
||||
hostnamectl set-hostname $1
|
||||
echo "--- Renaming machine to $1"
|
||||
echo "--- Restart after renamed: $2"
|
||||
hostnamectl set-hostname $1
|
||||
|
||||
if [ "$2" = "YES" ]; then
|
||||
echo "--- Linux machine will restart in 1 minute...."
|
||||
shutdown -r +1
|
||||
else
|
||||
echo "--- No need to restart linux machine."
|
||||
fi;
|
||||
@@ -69,4 +69,8 @@ variable "startupTime"{
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "restartAfterRename" {
|
||||
default = false
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user