我正在使用 lxd_container 模块创建一些lxd容器。这些容器之一应在其配置中包含行 security.nesting:“ true” 。我无法将此配置模板化,因为它是由lxc工具控制的。 我需要类似的东西:
{%如果item.0 ==“ gitlab”%}安全性。嵌套: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 }}"
我如何在一项任务中实现这一目标?
答案 0 :(得分:0)
ternary能为您提供帮助吗?
- set_fact:
nesting: "{{ (item0 == 'gitlab') | ternary(true, omit) }}"
- debug:
msg: "{{ nesting|default('NOT SET') }}"
答案 1 :(得分:-1)
您可以这样做:
security.nesting: "{{item.0 == gitlab}}"