我要在使用以下命令创建VM时禁用用户密码:
sudo sed -i -E '/^username/s/^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)(:.*)$/\1:!!:'$(($(date +%s)/86400))':\4:99998\6/' /etc/shadow
在Terraform virtual_machine_extension中。我已经在新创建的VM上测试了该命令,它可以正常工作,但是与Terraform一起使用时出现此错误:
Error: Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'vm-02'. Error message: \"Command returned an error.\n---stdout---\n\n---errout---\nsed: -e expression #1, char 71: unterminated `s' command\n\n\"."
on ../modules/vm.tf line 100, in resource "azurerm_virtual_machine_extension" "disable_pw":
100: resource "azurerm_virtual_machine_extension" "disable_pw" {
我已经尝试使用\
来逃避\\
。使用其他bash命令运行此确切的vm_extension效果很好。
有人有经验吗?
resource "azurerm_virtual_machine_extension" "disable_pw" {
name = "${var.vm_hostname}
location = "${module.global_variables.location}"
resource_group_name = "${module.global_variables.resource_group_name}"
virtual_machine_name = "${azurerm_virtual_machine.vm-linux.name}"
publisher = "Microsoft.OSTCExtensions"
type = "CustomScriptForLinux"
type_handler_version = "1.5"
auto_upgrade_minor_version = false
protected_settings = <<SETTINGS
{
"commandToExecute": "sudo sed -i -E '/^username/s/^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)(:.*)$/\1:!!:'$(($(date +%s)/86400))':\4:99998\6/' /etc/shadow"
}
SETTINGS
settings = <<SETTINGS
{
}
SETTINGS
}
答案 0 :(得分:0)
这将起作用
sed -E '/^username/s/^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)(:.*)$/1:!!:'$(($(date +%s)/86400))':4:999986/g' /etc/shadow
说明: