Ansible-和#x27;何时';不是游戏的有效属性

Ansible-和#x27;何时';不是游戏的有效属性,ansible,ansible-2.x,Ansible,Ansible 2.x,我试图找出如何通过修复根本原因“删除”警告消息[warning]:无法匹配提供的主机模式,忽略:ps_节点。对我来说,根本原因是,当我们创建Linux机器时,ps_节点主机将为空。因此,我试图添加块:+when:(os_type | capitalize)==“Windows”,以确保仅在os_type是Windows创建时才执行Play 我怎样才能做到这一点?因为,我尝试的是使用when条件,但看起来不可能,我不确定再搜索什么 代码示例: - name: "Start handling

我试图找出如何通过修复根本原因“删除”警告消息
[warning]:无法匹配提供的主机模式,忽略:ps_节点
。对我来说,根本原因是,当我们创建Linux机器时,ps_节点主机将为空。因此,我试图添加
块:
+
when:(os_type | capitalize)==“Windows”
,以确保仅在os_type是Windows创建时才执行Play

我怎样才能做到这一点?因为,我尝试的是使用when条件,但看起来不可能,我不确定再搜索什么

代码示例:

    - name: "Start handling of vm specific delete scripts for Windows machines"
      block:
        hosts: ps_nodes
        any_errors_fatal: false
        gather_facts: false
        vars:
          private_ip_1: "{{ hostvars['localhost']['_private_ip_1']|default('') }}"
          scripts: "{{ hostvars['localhost']['scripts'] }}"
          sh_script_dir: "{{ hostvars['localhost']['sh_script_dir'] }}"
          cred_base_hst: "{{ hostvars['localhost']['cred_base_hst'] }}"
          cred_base_gst: "{{ hostvars['localhost']['cred_base_gst'] }}"
          newline: "\n"

        tasks:
        - import_tasks: roles/script/tasks/callWindowsScripts.yml
          when: action == 'delete'
      when: (os_type|capitalize) == "Windows"
在播放时使用“when”时出错:

ERROR! 'when' is not a valid attribute for a Play

The error appears to be in '/opt/projectX/playbooks/create_vm.yml': line 265, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

##############################################################################
- name: \"Start handling of vm specific delete scripts for Windows machines\"
  ^ here

我认为问题在于压痕。使用“和”:

  - name: "Start handling of vm specific delete scripts for Windows machines"
      block:
        hosts: ps_nodes
        any_errors_fatal: false
        gather_facts: false
        vars:
          private_ip_1: "{{ hostvars['localhost']['_private_ip_1']|default('') }}"
          scripts: "{{ hostvars['localhost']['scripts'] }}"
          sh_script_dir: "{{ hostvars['localhost']['sh_script_dir'] }}"
          cred_base_hst: "{{ hostvars['localhost']['cred_base_hst'] }}"
          cred_base_gst: "{{ hostvars['localhost']['cred_base_gst'] }}"
          newline: "\n"

        tasks:
        - import_tasks: roles/script/tasks/callWindowsScripts.yml
          when: action == 'delete' and (os_type|capitalize) == "Windows"
明白了

如果使用存在的主机(如localhost),请检查ps_节点中的主机数量并将_委托给它们,会怎么样

大概是这样的:

hosts: localhost
vars:
tasks:
 - import_tasks: roles/script/tasks/callWindowsScripts.yml
   delegate_to: ps_nodes
   when: {{ ps_nodes | length > 0}}
同一问题通过“缩进”解决:

-主机:测试
角色:
-角色:测试
变量:
k:1
当:“'dbg'在ansible_run_标记中”

我不想检查任务,我真的想检查充分发挥,这就是为什么在下面的行中有when,因为我没有将其应用于任务,但为了充分发挥,如果我在任务中加入when条件,我将不会删除“[警告]:无法匹配提供的主机模式,忽略:ps\u节点”您有一个组,
ps_nodes
,其中包含具有不同操作系统类型的主机,例如RHEL和Windoze?