-1

我正在使用lxd_container模块来创建一些 lxd 容器。这些容器之一应在其配置中包含行security.nesting: "true"。我不能模板化这个配置,因为它是由 lxc 工具控制的。我需要类似的东西:

{% if item.0 == "gitlab" %} security.nesting: true {% endif %}

- name: Creating  containers
  lxd_container:
    name: "{{item.0}}"
    state: started
    source:
      type: image
      mode: pull
      server: https://cloud-images.ubuntu.com/releases
      protocol: simplestreams
      alias: 18.04/amd64
    profiles: ["default"]
    config:
      security.nesting: true // only if item.0 == gitlab
      user.network-config: |-
        version: 1
        config:
          - type: physical
            name: eth0
            subnets:
              - type: static
                ipv4: true
                address: "{{ item.1 }}"
                netmask: 255.255.255.0
                gateway: "{{ CONT_GATEWAY }}"
                control: auto
    timeout: 7000
  with_together: 
  - "{{ CONT_NAME }}"
  - "{{ CONT_IP_ADRESS }}"

我怎么能在一项任务中做到这一点?

4

2 回答 2

0

三元对你有帮助吗?

- set_fact:
    nesting: "{{ (item0 == 'gitlab') | ternary(true, omit) }}"
- debug:
    msg: "{{ nesting|default('NOT SET') }}"
于 2018-10-15T13:30:01.160 回答
-1

你能做到吗: security.nesting: "{{item.0 == gitlab}}"

于 2018-10-16T10:10:59.240 回答