如何在变量之间添加双引号?
例如:“变量”
Powershell命令:
$a = Get-ClusterGroup | Where-Object {$_.Name -eq "hosts" -and $_.State -eq 'Online'}
$b = $a.OwnerNode
Start-VM -Name "hosts" -ComputerName $b
我的编码:
---
- hosts: all
gather_facts: no
tasks:
- name: hyper-v shutdown vm
win_shell: |
$a = Get-ClusterGroup | Where-Object {$_.Name -eq "{{ hosts }}" -and $_.State -eq 'Online'}
$b = $a.OwnerNode
Start-VM -Name "{{ hosts }}" -ComputerName $b
答案 0 :(得分:0)
这应该有效:
- hosts: all
gather_facts: no
tasks:
- name: hyper-v shutdown vm
win_shell: |
$a = Get-ClusterGroup | Where-Object {$_.Name -eq "\"{{ hosts }}\"" -and $_.State -eq 'Online'}
$b = $a.OwnerNode
Start-VM -Name "\"{{ hosts }}\"" -ComputerName $b