本帖最后由 louis_lee 于 2020-11-21 00:46 编辑
我前几天也在研究开/关exsi 虚拟机的办法,就是用ssh连上就行,分享一下我的配置文件,供参考~
注:最后有个VM_ID占位符,这个是虚拟机ID,需要替换成你的虚拟机ID。通过ssh登录exsi,输入 vim-cmd vmsvc/getall可以得到所有虚机对应的ID
switch:
- platform: command_line
switches:
centos:
command_on: "sshpass -p '${PASSWORD}' ssh -o stricthostkeychecking=no -p22 root@${IP} 'vim-cmd vmsvc/power.on ${VIM_ID}'"
command_off: "sshpass -p '${PASSWORD}' ssh -o stricthostkeychecking=no -p22 root@${IP} 'vim-cmd vmsvc/power.off ${VM_ID}'"
command_state: "sshpass -p '${PASSWORD}' ssh -o stricthostkeychecking=no -p22 root@${IP} 'vim-cmd vmsvc/power.getstate ${VM_ID}|grep on|wc -l'"
value_template: '{{ value == "1" }}'
friendly_name: centos switch
|