mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
[provisioner-habitat] Detect if hab user exists (#17195)
Currently the provisioner will fail if the `hab` user already exists on the target system. This adds a check to see if we need to create the user before trying to add it. Fixes #17159 Signed-off-by: Nolan Davidson <ndavidson@chef.io>
This commit is contained in:
parent
848375b9a6
commit
f43e592849
@ -594,7 +594,8 @@ func (p *provisioner) startHabSystemd(o terraform.UIOutput, comm communicator.Co
|
||||
}
|
||||
|
||||
func (p *provisioner) createHabUser(o terraform.UIOutput, comm communicator.Communicator) error {
|
||||
// Create the hab user
|
||||
addUser := false
|
||||
// Install busybox to get us the user tools we need
|
||||
command := fmt.Sprintf("env HAB_NONINTERACTIVE=true hab install core/busybox")
|
||||
if p.UseSudo {
|
||||
command = fmt.Sprintf("sudo %s", command)
|
||||
@ -603,11 +604,25 @@ func (p *provisioner) createHabUser(o terraform.UIOutput, comm communicator.Comm
|
||||
return err
|
||||
}
|
||||
|
||||
command = fmt.Sprintf("hab pkg exec core/busybox adduser -D -g \"\" hab")
|
||||
// Check for existing hab user
|
||||
command = fmt.Sprintf("hab pkg exec core/busybox id hab")
|
||||
if p.UseSudo {
|
||||
command = fmt.Sprintf("sudo %s", command)
|
||||
}
|
||||
return p.runCommand(o, comm, command)
|
||||
if err := p.runCommand(o, comm, command); err != nil {
|
||||
o.Output("No existing hab user detected, creating...")
|
||||
addUser = true
|
||||
}
|
||||
|
||||
if addUser {
|
||||
command = fmt.Sprintf("hab pkg exec core/busybox adduser -D -g \"\" hab")
|
||||
if p.UseSudo {
|
||||
command = fmt.Sprintf("sudo %s", command)
|
||||
}
|
||||
return p.runCommand(o, comm, command)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provisioner) startHabService(o terraform.UIOutput, comm communicator.Communicator, service Service) error {
|
||||
|
Loading…
Reference in New Issue
Block a user