我正在尝试使用vmware_vm_shell模块更改Windows Server 2012R2 vmware来宾计算机的IP。到目前为止,我已经能够使用vsphere_guest模块从模板中克隆VM而没有问题,但是当我尝试以下任务来更改IP时:
network.host: 0.0.0.0 (to accept all the IPs)
http.port: 9200
Ansible的回复是- name: Configure IP address
local_action:
module: vmware_vm_shell
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
cluster: "{{ Cluster }}"
vm_id: "{{ machine }}"
vm_username: "{{ machineUser }}"
vm_password: "{{ ansible_windows_password }}"
vm_shell: "C:\\Windows\\System32\\WindowsPowershell\\1.0\\powershell.exe"
vm_shell_args: " -command (Get-NetAdapter -Name Ethernet |New-NetIPAddress -InterfaceAlias Ethernet -AddressFamily IPv4 -IPAddress {{ new_machine_ip }} -PrefixLength {{ new_machine_mask_bits }} -DefaultGateway {{ new_machine_gateway }} )-and (Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses {{ new_machine_dns }})"
vm_shell_cwd: "C:\\Windows\\Temp"
validate_certs: False
。
当我尝试从pyvmomi-community-samples运行"msg": "File <unspecified filename> was not found"
脚本时出现同样的错误:execute_program_in_vm.py
我拥有的vmware用户设置了所有Caught vmodl fault : File <unspecified filename> was not found
权限。我在这里错过了什么?
PS:我跟着this guide。
答案 0 :(得分:0)
我完成这项任务再试一次。此模块有时会解析powershell命令。至少那是我的经历。我不确切地知道为什么我的命令在起作用而你的命令不起作用。 我替换了“vm_shell_args”中的命令。
您只需要替换方括号中的值。
修改强>
也可以再次尝试使用剧本,但使用不带空格的变量(例如"{{vcenter_hostname}}"
而不是"{{ vcenter_hostname }}"
- name: change IP
local_action:
module: vmware_vm_shell
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
cluster: "{{ Cluster }}"
vm_id: "{{ machine }}"
vm_username: "{{ machineUser }}"
vm_password: "{{ ansible_windows_password }}"
vm_shell: 'C:\Windows\System32\WindowsPowershell\1.0\powershell.exe'
vm_shell_args: 'netsh interface ip set address [Interface name] static [New IP] [Subnetmask] [Gateway]'