双引号的ansible剧本变量

时间:2019-08-30 07:04:24

标签: ansible

如何在变量之间添加双引号?
例如:“变量”

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  

1 个答案:

答案 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