在Ansible playbook中选择一行

在Ansible playbook中选择一行,ansible,f5,Ansible,F5,我已经建立了一个剧本,以建立一个虚拟服务器在F5。我想让一行只在有人输入变量时执行。在本例中,默认的_persistence_profile:line有一个变量“{{persistenceProfile}}”。有时开发人员不希望将持久性应用于他们的应用程序,但有时他们确实希望。我发现,当我在运行任务中使变量成为可选变量,并且没有选择持久性配置文件时,任务错误就会消失。见下面的剧本: - name: Build the Virtual Server bigip_virtual_

我已经建立了一个剧本,以建立一个虚拟服务器在F5。我想让一行只在有人输入变量时执行。在本例中,默认的_persistence_profile:line有一个变量“{{persistenceProfile}}”。有时开发人员不希望将持久性应用于他们的应用程序,但有时他们确实希望。我发现,当我在运行任务中使变量成为可选变量,并且没有选择持久性配置文件时,任务错误就会消失。见下面的剧本:

    - name: Build the Virtual Server
      bigip_virtual_server:
        state: present
        partition: Common
        name: "{{ vsName  }}" 
        destination: "{{ vsIpAddress }}"
        port: "{{ vsPort }}"
        pool: "{{ poolName }}"
        default_persistence_profile: "{{ persistenceProfile }}"
        ip_protocol: tcp 
        snat: automap
        description: "{{ vsDescription }}"
        profiles:
           - tcp
           - http
           - name: "{{ clientsslName }}" 
             context: client-side
           - name: default-server-ssl
             context: server-side

Ansible有一种使用
默认值
过滤器的机制,如下所示:

    - name: Build the Virtual Server
      bigip_virtual_server:
        state: present
        partition: Common
        name: "{{ vsName  }}" 
        destination: "{{ vsIpAddress }}"
        port: "{{ vsPort }}"
        pool: "{{ poolName }}"
        default_persistence_profile: "{{ persistenceProfile|default(omit) }}"
        ip_protocol: tcp 
        snat: automap
        description: "{{ vsDescription }}"
        profiles:
           - tcp
           - http
           - name: "{{ clientsslName }}" 
             context: client-side
           - name: default-server-ssl
             context: server-side

如果未设置
persistenceProfile
,则不应将
default\u persistence\u profile
参数传递给
bigip\u virtual\u server
模块。

Ansible具有使用
default
过滤器的机制,如下所示:

    - name: Build the Virtual Server
      bigip_virtual_server:
        state: present
        partition: Common
        name: "{{ vsName  }}" 
        destination: "{{ vsIpAddress }}"
        port: "{{ vsPort }}"
        pool: "{{ poolName }}"
        default_persistence_profile: "{{ persistenceProfile|default(omit) }}"
        ip_protocol: tcp 
        snat: automap
        description: "{{ vsDescription }}"
        profiles:
           - tcp
           - http
           - name: "{{ clientsslName }}" 
             context: client-side
           - name: default-server-ssl
             context: server-side
如果未设置
persistenceProfile
,则不应将
default\u persistence\u profile
参数传递给
bigip\u virtual\u server
模块