0

Im using ansible 2.9.2 and i want to run a script that creates user on my windows machine, The script works if i run in my powershell localy like this :

powershell.exe -ExecutionPolicy Bypass -File create_user.ps1 -pass "{{ pass }}" -user "{{ user }}" -gr "{{ gr }}"

Playbook:

  tasks:
    - name: "Createing windows user"
      local_action:
        module: vmware_vm_shell
        cluster: "{{ cluster }}"
        datacenter: "{{ datacenter }}"
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user  }}"
        password: "{{ vcenter_pass }}"
        vm_id: "{{vm_name}}"
        vm_username: "{{ vm_username }}"
        vm_password: "{{ vm_password }}"
        vm_shell: 'C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe'
        vm_shell_args: powershell.exe -ExecutionPolicy Bypass -File create_user.ps1 -pass "{{ pass }}" -user "{{ user }}" -gr "{{ gr }}"
        vm_shell_cwd: 'C:\Users\myuser\Desktop'
        wait_for_process: yes
        validate_certs: no
      register: info
    - debug:
            msg: "{{ info }}"

From playbook i dont get any error but user is not being created, manually with same command all works. is it because i use powershell as admin localy ? is there a way to do it here?

here is the output:

ok: [localhost] => {
    "msg": {
        "changed": true,
        "cmd_line": "\"C:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe\" powershell.exe -ExecutionPolicy Bypass -File create_user.ps1 -pass \"********7\" -user \"Tomy\" -gr \"Localgroup\"",
        "end_time": "2020-01-14T13:44:32+00:00",
        "exit_code": 0,
        "failed": false,
        "name": "powershell.exe",
        "owner": "myuser",
        "start_time": "2020-01-14T13:44:31+00:00",
        "uuid": "4256795-43ec-87c2-fd4bf-5dffv6f2a4"
    }
}
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

1 Answer 1

1

After upgrading from vmtools version:10346 to version:11265 All works!

And i have made this changes in my playbook:

  tasks:
  - name: Get all tags
    vmware_vm_shell:
      cluster: "{{ cluster }}"
      datacenter: "{{ datacenter }}"
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      folder: "{{ folder }}"
      vm_id: "{{ name }}"
      vm_username: "{{ vm_username }}"
      vm_password: "{{ vm_password }}"
      vm_shell: 'C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe'
      vm_shell_args: -ExecutionPolicy Bypass -File create_user.ps1 -pass "{{ pass_word }}" -user "{{ user }}" -gr "{{ gr }}"
      vm_shell_cwd: 'C:\Users\Administrator\Desktop'
      wait_for_process: yes
      validate_certs: no
    delegate_to: localhost
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.