-1

i am using the lxd_container module to create some lxd containers. One of these containers should include in its configuration the line security.nesting: "true". I can't template this configuration since it is controlled by the lxc tool. I need something like :

{% 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 }}"

how could i achieve this in one task ?

alixander
  • 426
  • 1
  • 7
  • 18

2 Answers2

0

Would ternary help you?

- set_fact:
    nesting: "{{ (item0 == 'gitlab') | ternary(true, omit) }}"
- debug:
    msg: "{{ nesting|default('NOT SET') }}"
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
-1

Can you just do: security.nesting: "{{item.0 == gitlab}}"

guoqiao
  • 1,309
  • 12
  • 14