When creating a scheduled task with the password logon_type and specifying username using the ".\username" format for a local Windows user account, task creation fails with the following error:
FAILED! => {"changed": true, "msg": "failed to modify scheduled task: (22,8):UserId:"}
Digging further, it appears that tasks are created in two steps, with the task shell being created first and then the task details being updated later. Because the username and password fields are not specified during the "shell" creation, the job is created but without the correct properties.
Additional Info:
When creating the task using the interactive_token logon_type (instead of password logon_type) and specifying the username using the ".\username" format for a local Windows user account, task is created successfully. In this scenario, only the account SID is required and the Convert-ToSID cmdlet properly handles the ".\username" format when resolving the SID.
However, when using the password logon_type and specifying the username using the ".\username" format, the ".\username" is passed directly to the RegisterTaskDefinition method of the Schedule.Service COM object. It appears that this is where the failure originates.
Workaround: Can workaround the issue bay specifying the "computername\username" format for the username. However, the ".\" reference for specifying a local Windows user should be supported and is supported in other functions. Using the ".\username" format via the Task Scheduler UI works as expected.
Use win_scheduled_task to create a scheduled task using the password logon_type and specifying the username with the ".\username" format to specify a local Windows user.
SUMMARY
When creating a scheduled task with the password logon_type and specifying username using the ".\username" format for a local Windows user account, task creation fails with the following error:
FAILED! => {"changed": true, "msg": "failed to modify scheduled task: (22,8):UserId:"}
Digging further, it appears that tasks are created in two steps, with the task shell being created first and then the task details being updated later. Because the username and password fields are not specified during the "shell" creation, the job is created but without the correct properties.
Additional Info: When creating the task using the interactive_token logon_type (instead of password logon_type) and specifying the username using the ".\username" format for a local Windows user account, task is created successfully. In this scenario, only the account SID is required and the Convert-ToSID cmdlet properly handles the ".\username" format when resolving the SID.
However, when using the password logon_type and specifying the username using the ".\username" format, the ".\username" is passed directly to the RegisterTaskDefinition method of the Schedule.Service COM object. It appears that this is where the failure originates.
Workaround: Can workaround the issue bay specifying the "computername\username" format for the username. However, the ".\" reference for specifying a local Windows user should be supported and is supported in other functions. Using the ".\username" format via the Task Scheduler UI works as expected.
ISSUE TYPE
COMPONENT NAME
win_scheduled_task.ps1
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Target host is running Windows Server 2019.
STEPS TO REPRODUCE
Use win_scheduled_task to create a scheduled task using the password logon_type and specifying the username with the ".\username" format to specify a local Windows user.
EXPECTED RESULTS
Task is created successfully.
ACTUAL RESULTS
Task creation fails with generic error below. Note: Extra verbosity provides no additional information regarding the command/error.