代码之家  ›  专栏  ›  技术社区  ›  Bidyut

Ansible多重条件不工作

  •  0
  • Bidyut  · 技术社区  · 7 年前

    主机文件:

    [master] 54.65.104.4 [slaves] 52.69.71.248

     - name: Checking if the node is already having spark master installed (master)
       stat:
         path: /etc/init.d/spark-master
         register: spark-master
       when: inventory_hostname in groups['master']
     - name: Checking if the node is already having spark worker installed
       stat:
         path: /etc/init.d/spark-slave
         register: spark-slave
       when: inventory_hostname in groups['slaves']
    
      # Downloading to the master
     - include: download.yaml
       when: (inventory_hostname in groups['master']) and ( spark-master.stat.exists == false)
    
     # Downloading to the slaves
     - include: download.yaml
       when: (inventory_hostname in groups['slaves']) and ( spark-slave.stat.exists == False )
    

    但当我执行脚本时,我收到以下错误:

     fatal: [52.69.71.248]: FAILED! => {"failed": true, "msg": "The conditional check '(inventory_hostname in groups['slaves']) and ( spark-slave.stat.exists == False )' failed. The error was: error while evaluating conditional ((inventory_hostname in groups['slaves']) and ( spark-slave.stat.exists == False )): 'slave' is undefined\n\nThe error appears to have been in '/opt/ansible-role-spark/tasks/download.yaml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Download Spark\n  ^ here\n"}
    

    谁能帮我找出我犯的错误吗。

    2 回复  |  直到 7 年前
        1
  •  3
  •   techraf    7 年前

    要么引用条件,例如:

    when: "(inventory_hostname in groups['master']) and ( spark-master.stat.exists == false)"
    

    或者不要使用括号。

        2
  •  1
  •   Konstantin Suvorov    7 年前

    变量名应该是字母、数字和下划线。

    看见 docs

    但你的剧本中还有其他设计缺陷,这是毫无疑问的。