【问题标题】:ansible playbook syntax error when I using variable当我使用变量时,ansible playbook 语法错误
【发布时间】:2019-08-27 09:21:27
【问题描述】:

我在运行 playbook 时遇到语法错误。

错误!加载 YAML 时出现语法错误。没有找到预期的'-' 指示器 错误似乎在 '/var/lib/awx/projects/_39__common/Hyper-V_Shutdown_VM.yml':第 8 行, 第 5 列,但可能在文件中的其他位置,具体取决于确切的 语法问题。

违规行似乎是:

   - win_shell: |  
    $a = Get-ClusterGroup | Where-Object {$_.Name -like "{{ vm }}" -and $_.State -eq 'Online'}  
    ^ here  

我们可能是错的,但这个看起来可能是一个问题
缺少引号。总是引用模板表达式括号
开始一个值。例如:

    with_items:  
      - {{ foo }}  
Should be written as:  
    with_items:  
      - "{{ foo }}"   

我的编码........

---
- name: Hyper-V shutdown VM
  hosts: all
  gather_facts: no

  tasks:

      win_shell: |
        $a = Get-ClusterGroup | Where-Object {$_.Name -like "{{ vm }}" -and $_.State -eq 'Online'}
        $b = $a.OwnerNode
        Stop-VM -Name "{{ vm }}" -ComputerName $b

【问题讨论】:

    标签: ansible


    【解决方案1】:
    ---
    - hosts: all
      gather_facts: no
      tasks:
      - name: Hyper-V shutdown VM
        win_shell: |
            $a = Get-ClusterGroup | Where-Object {$_.Name -like "{{ vm }}" -and $_.State -eq 'Online'}
            $b = $a.OwnerNode
            Stop-VM -Name "{{ vm }}" -ComputerName $b
    

    【讨论】:

      【解决方案2】:

      模块名称前面缺少破折号“-”。正确的语法如下

        tasks:
          - win_shell:
      

      这是错误的原因

      没有找到预期的“-”指示符

      【讨论】:

      • 对不起。我又犯了一个错误。找不到预期的“:”
      猜你喜欢
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多