getting error

Posted on

02/12/2024:
Hello,

I fixed a lot in that playbook, and only last part is not working:

This is the playbook:

name: To Create VMs on Hyper-v
hosts: localhost
gather_facts: False

vars_files: ~/hyper-v/playbooks/Hyper-v--vars.yml

tasks:
- name: Create a file from a Jinja2 template
template:
src: ~/hyper-v/playbooks/Hyper-v-VMs-VARs.ps1.j2
dest: ~/hyper-v/playbooks/Hyper-v-VMs-VARs.ps1

  • name: Copying Files to Windows Server
    shell: scp ~/hyper-v/playbooks/Hyper-v-VMs-VARs.ps1 10.3.2.25:C:/001-Scripts/

  • name: To Create VMs on Hyper-v
    ansible.windows.win_shell: powershell.exe -ExecutionPolicy ByPass -File 10.3.2.25:C:\001-Scripts\Hyper-v-VMs-VARs.ps1
    this part in the script where I got the error:

name: To Create VMs on Hyper-v
ansible.windows.win_shell: powershell.exe -ExecutionPolicy ByPass -File 10.3.2.25:C:\001-Scripts\Hyper-v-VMs-VARs.ps1
error:
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "/bin/sh: powershell: command not found\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 127}

can somebody please let me know how it can be fixed

Hello,

I am getting the error running playbook:

fatal: [xx.xx.xx.xx]: FAILED! => {"msg": "failed to transfer file to /var/tmp/ansible-local-102824pytpkxa/tmpc8tre972/Hyper-v-VMs-VARs.ps1.j2 /C:/Users/ansible/AppData/Local/Temp/ansible-tmp-1707676424.4412508-10289-256360601058976/source:\n\ndd : The term 'dd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the \r\nspelling of the name, or if a path was included, verify that the path is correct and try again.\r\nAt line:1 char:1\r\n+ dd of=/C:/Users/ansible/AppData/Local/Temp/ansible-tmp-1707676424.441 ...\r\n+ ~~\r\n + CategoryInfo : ObjectNotFound: (dd:String) [], CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n "}

I am running ansible version =
ansible [core 2.11.12]
config file = /home/ansible/.ansible.cfg

python version = 3.6.15 (default, Sep 23 2021, 15:41:43) [GCC]
jinja version = 2.8
libyaml = False

below is the simple playbook:

name: To Create VMs on Hyper-v
hosts: all
gather_facts: False
vars_files: ~/hyper-v/playbooks/Hyper-v--vars.yml
tasks:
- name: Create a file from a Jinja2 template
ansible.windows.win_template:
src: ~/hyper-v/playbooks/Hyper-v-VMs-VARs.ps1.j2
dest: C:\001-Scripts\Hyper-v-VMs-VARs.ps1

  • name: To Create VMs on Hyper-v
    win_command: powershell.exe -ExecutionPolicy ByPass -File C:/001-Scripts/Hyper-v-VMs-VARs.ps1
    can you please help me to avoid this error above ?

Responses