Handle explicit task-level become override
This commit is contained in:
parent
7013183629
commit
992230a1fe
1 changed files with 8 additions and 4 deletions
12
modules.go
12
modules.go
|
|
@ -13,14 +13,18 @@ import (
|
|||
func (e *Executor) executeModule(ctx context.Context, host string, client *SSHClient, task *Task, play *Play) (*TaskResult, error) {
|
||||
module := NormalizeModule(task.Module)
|
||||
|
||||
// Apply task-level become
|
||||
if task.Become != nil && *task.Become {
|
||||
// Save old state to restore
|
||||
// Apply task-level become override.
|
||||
if task.Become != nil {
|
||||
// Save old state to restore.
|
||||
oldBecome := client.become
|
||||
oldUser := client.becomeUser
|
||||
oldPass := client.becomePass
|
||||
|
||||
client.SetBecome(true, task.BecomeUser, "")
|
||||
if *task.Become {
|
||||
client.SetBecome(true, task.BecomeUser, "")
|
||||
} else {
|
||||
client.SetBecome(false, "", "")
|
||||
}
|
||||
|
||||
defer client.SetBecome(oldBecome, oldUser, oldPass)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue