ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
206 stars 161 forks source link

Win_scheuled_task: Username parameter is unable to find domain when logon type is password #444

Closed ashorie-clgx closed 2 years ago

ashorie-clgx commented 2 years ago
SUMMARY

Username parameter is unable to find domain when logon type is password

ISSUE TYPE
COMPONENT NAME

Win_scheduled_task

ANSIBLE VERSION

2.9


##### COLLECTION VERSION
1.11.0 
```paste below
CONFIGURATION

ansible-v2.9


##### OS / ENVIRONMENT
Windows server 2016

##### STEPS TO REPRODUCE
logon_type should be "password" and tried username(with DOMAIN/User and also FQDN) and password and I get below error everytime mentioned in actual results
```- name: Create scheduled task to run batch file RMBS 2.0 v4 
  win_scheduled_task:
    name: "{{ RMBS_scheduled_task_name }}"
    description: Run batch file for RMBS data collection
    actions:
    - path: "{{ RMBS_task_folder }}\\pj_rmbs_v4.bat"
    triggers:
    - type: weekly
      start_boundary: '2022-09-26T17:15:00'
      days_of_week:
        - monday 
        - tuesday
        - wednesday
        - thursday
        - friday
    logon_type: password
## both ways Username does not acccept domain with and without quotes
    username: isc\ashorie@corelogic.com
#   username: isc\ashorie 
    password: "{{ domain-service-account-password }}"
    run_level: highest
    state: present
    enabled: yes
    allow_demand_start: yes
EXPECTED RESULTS
ACTUAL RESULTS

"msg": "The task includes an option with an undefined variable. The error was: 'domain' is undefined\n\nThe error appears to be in '/home/jenkins/agent/workspace/minal-server_terminal-server-dev/terminal-server/ansible/roles/terminal-server/tasks/misc.yml': line 181, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create scheduled task to run batch file RMBS 2.0 v4\n ^ here\n"

mwtrigg commented 2 years ago

The error message is pointing to your problem domain is undefined -- you'll notice its not saying domain-service-account-password is undefined, because dashes are illegal characters in variable names (see here for more details: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#creating-valid-variable-names).

Change your variable name, or replace the dashes with underscores in the variable name and you should be fine.

isc\ashorie should be the correct format

ashorie-clgx commented 2 years ago

@mwtrigg Thanks. It worked for me. I have another issue. I am running a batch job for this scheduler and apparently it requires to put path in "start in" as well. For that I wrote the actions parameter as below and it gives me error:

========================================================

Please let me know correct way to do it in parameters for actions.

ashorie-clgx commented 2 years ago

I am getting below error:

20:15:59 fatal: [edguw1gesects01]: FAILED! => { 20:15:59 "changed": false, 20:15:59 "msg": "failed to register new task definition: The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)"

mwtrigg commented 2 years ago

General usage questions, assistance and similar are best suited for the IRC (#ansible-windows on irc.libera.chat) or the mailing list (https://groups.google.com/forum/#!forum/ansible-project), or another question forum of your choice.

This GitHub Issue tracker should be reserved for bugs or problems with the collection itself, not general troubleshooting.

I am unable to reproduce your issue; though you're running ansible 2.9 (and I'm on 2.13); though I cant be certain that I am imitating your playbook directly because you haven't put your task into a code block.

ashorie-clgx commented 2 years ago

I got the issue, accidently put the task name variable in single quotes with double quotes. Works fine for me now after removing the single quotes. Thanks for you assistance and apologies for taking so much of your time. Issue can be closed now.