Hey Dick,

Changed the localhost for the domain task to the host itself. No help, 
still getting the same error:

fatal: [localhost -> ans-dv4-test1]: FAILED! => {
    "changed": false,
    "module_stderr": "\u001b[91mParserError: 
\u001b[0m/home/administrator/.ansible/tmp/ansible-tmp-1634325122.8927026-35811-261246352817343/AnsiballZ_win_domain_membership.ps1:151\n\u001b[96mLine
 
|\n\u001b[96m 151 | \u001b[0m 
\u001b[96m\u0000\u001b[0m\u0000\u0000\u0000{\"module_entry\": 
\"IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTc …\n\u001b[96m     | 
\u001b[91m ~\n\u001b[91m\u001b[96m     | \u001b[91munexpected token 
'\u0000', expected 'begin', 'process', 'end', or\n\u001b[96m     | 
\u001b[91m'dynamicparam'.\n\u001b[0m\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP 
******************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    
failed=1    skipped=0    rescued=0    ignored=0



Here is the playbook again:

---
- hosts: localhost
  gather_facts: False
  connection: local
  user: remote

##Variables


  vars_files:
    - /etc/ansible/vars/hosts_vars.yml


##TASKS

  tasks:
  - name: Clone the template
    vmware_guest:
      hostname: "{{ vcenter_server }}"
      username: "{{ vcenter_user }}"
      password: "{{ vcenter_pass }}"
      validate_certs: False
      name: "{{ fqdn_new_win_machine }}"
      state: powered-on
      notes: "{{ vars_notes }}"
      template: WinServer2019-Golden-Oct21
      datacenter: "{{ datacenter_name }}"
      folder: New-Deployments
      cluster: "{{ cluster_name }}"
      disk:
        - size_gb: "{{ disk_size | default(60) }}"
          type: thin
          datastore: "HQ_Unity1_Datastore-06"
      networks:
        - name: VM Network
          type: dhcp
          allow_guest_control: True
          wait_for_ip_address: True

      hardware:
          memory_mb: "{{ vm_memory | default(4096) }}"
          num_cpus: "2"
    delegate_to: localhost


##Conncecting to Domain

  - name: Join to Domain
    ansible.windows.win_domain_membership:
      dns_domain_name: "{{ dxu_domain }}"
      hostname: "{{ fqdn_new_win_machine }}"
      domain_admin_user: "{{ vcenter_user }}"
      domain_admin_password: "{{vcenter_pass }}"
      domain_ou_path: "{{ ou_path }}"
      state: domain
    register: domain_state
    delegate_to: "{{ fqdn_new_win_machine }}"

##Reboot the machine after joining to Domain

  - name: Reboot after Domain Join
    ansible.windows.win_reboot:
    when: domain_state.reboot_required




Do you think I should break this playbook into 2 different playbooks? One 
for VM configuration and other for domain join?

Thanks!
On Friday, October 15, 2021 at 1:44:15 AM UTC-7 [email protected] wrote:

> The VMware task should run local and the domain task should run against 
> the host. 
>
> On Fri, 15 Oct 2021 at 06:33, Abhijot Singh Kathuria <[email protected]> 
> wrote:
>
>> Hey Dick,
>>
>> Here is the playbook:
>>
>> [image: image.png]
>>
>>
>>
>>
>> On Thu, Oct 14, 2021 at 9:29 PM Dick Visser <[email protected]> wrote:
>>
>>> The advice given should work. 
>>> Please share your exact playbook once again. 
>>>  
>>>
>>> On Fri, 15 Oct 2021 at 01:22, Abhijot Singh Kathuria <[email protected]> 
>>> wrote:
>>>
>>>> Hey Jorge,
>>>>
>>>> Thanks for your reply.
>>>>
>>>> I tried making the inventory to all and adding delegate_to: localhost. 
>>>> No luck here.
>>>>
>>>> Still getting the same error message.
>>>>
>>>>
>>>> *Regards,*
>>>> *Abhijot Singh*
>>>>
>>>> *Graduate Student, CIS*
>>>> *Talent Ambassador, Talent Gateway*
>>>> *Community Organizer, Civic Leadership Board*
>>>>
>>>> * <https://www.linkedin.com/in/abhi-jot-0303/> *
>>>>
>>>>
>>>> On Thu, Oct 14, 2021 at 4:11 PM Jorge Rúa <[email protected]> wrote:
>>>>
>>>>> Obviously, you would need to run the join domain task against the 
>>>>> newly created VM. To do that you should use delegate_to. 
>>>>>
>>>>> I would change your inventory to all, and then on the vmware related 
>>>>> tasks use delegate_to: localhost since what is happening behind the 
>>>>> scenes 
>>>>> are just soap/rest api calls against vcenter.
>>>>>
>>>>> You should also pay attention to the conection plugin. 
>>>>>
>>>>> Hope that helps
>>>>>
>>>>> On Fri, Oct 15, 2021, 00:01 Abhijot Singh Kathuria <[email protected]> 
>>>>> wrote:
>>>>>
>>>>>> Hey Guys,
>>>>>>
>>>>>> I need some assistance on the below error. I've tried everything but 
>>>>>> I'm not able to resolve the same.
>>>>>>
>>>>>> TASK [Join to Domain] 
>>>>>> **************************************************************************************************************
>>>>>> task path: /etc/ansible/playbooks/DeployVM/Server2019_Vsphere.yml:46
>>>>>> <localhost> ESTABLISH LOCAL CONNECTION FOR USER: administrator
>>>>>> <localhost> EXEC /bin/sh -c 'echo ~administrator && sleep 0'
>>>>>> <localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo 
>>>>>> /home/administrator/.ansible/tmp `"&& mkdir "` echo 
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149
>>>>>>  
>>>>>> `" && echo ansible-tmp-1634251564.5118623-32501-66747911642149="` echo 
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149
>>>>>>  
>>>>>> `" ) && sleep 0'
>>>>>> Using module file 
>>>>>> /home/administrator/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_domain_membership.ps1
>>>>>> <localhost> PUT 
>>>>>> /home/administrator/.ansible/tmp/ansible-local-324573ec1oxrx/tmp_rkwbrs9 
>>>>>> TO 
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149/AnsiballZ_win_domain_membership.ps1
>>>>>> <localhost> EXEC /bin/sh -c 'chmod u+x 
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149/
>>>>>>  
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149/AnsiballZ_win_domain_membership.ps1
>>>>>>  
>>>>>> && sleep 0'
>>>>>> <localhost> EXEC /bin/sh -c 'powershell 
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149/AnsiballZ_win_domain_membership.ps1
>>>>>>  
>>>>>> && sleep 0'
>>>>>> <localhost> EXEC /bin/sh -c 'rm -f -r 
>>>>>> /home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149/
>>>>>>  
>>>>>> > /dev/null 2>&1 && sleep 0'
>>>>>> fatal: [localhost]: FAILED! => {
>>>>>>     "changed": false,
>>>>>>     "module_stderr": "\u001b[91mParserError: 
>>>>>> \u001b[0m/home/administrator/.ansible/tmp/ansible-tmp-1634251564.5118623-32501-66747911642149/AnsiballZ_win_domain_membership.ps1:151\n\u001b[96mLine
>>>>>>  
>>>>>> |\n\u001b[96m 151 | \u001b[0m 
>>>>>> \u001b[96m\u0000\u001b[0m\u0000\u0000\u0000{\"module_entry\": 
>>>>>> \"IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTc …\n\u001b[96m     | 
>>>>>> \u001b[91m ~\n\u001b[91m\u001b[96m     | \u001b[91munexpected token 
>>>>>> '\u0000', expected 'begin', 'process', 'end', or\n\u001b[96m     | 
>>>>>> \u001b[91m'dynamicparam'.\n\u001b[0m\n",
>>>>>>     "module_stdout": "",
>>>>>>     "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
>>>>>>     "rc": 1
>>>>>> }
>>>>>>
>>>>>> PLAY RECAP 
>>>>>> *************************************************************************************************************************
>>>>>> localhost                  : ok=1    changed=1    unreachable=0    
>>>>>> failed=1    skipped=0    rescued=0    ignored=0
>>>>>>
>>>>>>
>>>>>>
>>>>>> So technically I'm trying to spin a VM in vSphere and connect that Vm 
>>>>>> to domain using Ansible and below is what my playbook looks like:
>>>>>>
>>>>>> ---
>>>>>> - hosts: localhost
>>>>>>   gather_facts: False
>>>>>>   connection: local
>>>>>>   user: remote
>>>>>>
>>>>>> ##Variables
>>>>>>
>>>>>>
>>>>>>   vars_files:
>>>>>>     - /etc/ansible/vars/hosts_vars.yml
>>>>>>
>>>>>>
>>>>>> ##TASKS
>>>>>>
>>>>>>   tasks:
>>>>>>   - name: Clone the template
>>>>>>     vmware_guest:
>>>>>>       hostname: "{{ vcenter_server }}"
>>>>>>       username: "{{ vcenter_user }}"
>>>>>>       password: "{{ vcenter_pass }}"
>>>>>>       validate_certs: False
>>>>>>       name: ans-dv4-test1
>>>>>>       state: powered-on
>>>>>>       notes: "{{ vars_notes }}"
>>>>>>       template: WinServer2019-Golden-Oct21
>>>>>>       datacenter: "{{ datacenter_name }}"
>>>>>>       folder: New-Deployments
>>>>>>       cluster: "{{ cluster_name }}"
>>>>>>       disk:
>>>>>>         - size_gb: "{{ disk_size | default(60) }}"
>>>>>>           type: thin
>>>>>>           datastore: "HQ_Unity1_Datastore-06"
>>>>>>       networks:
>>>>>>         - name: VM Network
>>>>>>           type: dhcp
>>>>>>           allow_guest_control: True
>>>>>>           wait_for_ip_address: True
>>>>>>
>>>>>>       hardware:
>>>>>>           memory_mb: "{{ vm_memory | default(4096) }}"
>>>>>>           num_cpus: "2"
>>>>>>
>>>>>> ##Conncecting to Domain
>>>>>>
>>>>>>   - name: Join to Domain
>>>>>>     ansible.windows.win_domain_membership:
>>>>>>       dns_domain_name: "{{ dxu_domain }}"
>>>>>>       hostname: ans-dv4-test1
>>>>>>       domain_admin_user: "{{ vcenter_user }}"
>>>>>>       domain_admin_password: "{{vcenter_pass }}"
>>>>>>       domain_ou_path: "{{ ou_path }}"
>>>>>>       state: domain
>>>>>>     register: domain_state
>>>>>>
>>>>>> ##Reboot the machine after joining to Domain
>>>>>>
>>>>>>   - name: Reboot after Domain Join
>>>>>>     ansible.windows.win_reboot:
>>>>>>     when: domain_state.reboot_required
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> The inventory file just has "localhost" defined in it.
>>>>>>
>>>>>> Can someone please advise!
>>>>>>
>>>>>>
>>>>>>  
>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Ansible Project" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/ansible-project/b85f424e-9808-482e-853f-40e95b6d687cn%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/ansible-project/b85f424e-9808-482e-853f-40e95b6d687cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>> -- 
>>>>>
>>>> You received this message because you are subscribed to a topic in the 
>>>>> Google Groups "Ansible Project" group.
>>>>> To unsubscribe from this topic, visit 
>>>>> https://groups.google.com/d/topic/ansible-project/OmZpCybs9WQ/unsubscribe
>>>>> .
>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>> [email protected].
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/ansible-project/CAFtje5MG_Jz8wYAu%2BfaipFcGW4Hn_59vwFGvw-KSN_g3fdwrkg%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/ansible-project/CAFtje5MG_Jz8wYAu%2BfaipFcGW4Hn_59vwFGvw-KSN_g3fdwrkg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Ansible Project" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/ansible-project/CABHtS3O4zyGhC%2BOSq%3DUiV4nj70puSOLWQTdj_pE6ybN0UNO-Rw%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/CABHtS3O4zyGhC%2BOSq%3DUiV4nj70puSOLWQTdj_pE6ybN0UNO-Rw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> -- 
>>> Sent from a mobile device - please excuse the brevity, spelling and 
>>> punctuation.
>>>
>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Ansible Project" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/ansible-project/OmZpCybs9WQ/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected].
>>>
>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/CAL8fbwMgT4-mL99Znt76ymt9QgkZi-8jhXqVPNKMHeUCthd2og%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwMgT4-mL99Znt76ymt9QgkZi-8jhXqVPNKMHeUCthd2og%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/CABHtS3PVkkVKH42V%2BC%3DcDzbBuPP6GNN9XU%2BQ2-S%2Bt4rEiN8_fQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/CABHtS3PVkkVKH42V%2BC%3DcDzbBuPP6GNN9XU%2BQ2-S%2Bt4rEiN8_fQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> -- 
> Sent from a mobile device - please excuse the brevity, spelling and 
> punctuation.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ecf351fd-aac1-4047-919f-6a54487d3901n%40googlegroups.com.

Reply via email to