小编Ber*_*rak的帖子

在ansible中合并字典

我目前正在构建一个使用ansible安装PHP的角色,我在合并字典方面遇到了一些困难.我已经尝试了几种方法,但我不能像我想要的那样让它工作:

# A vars file:
my_default_values:
  key = value

my_values:
  my_key = my_value


# In a playbook, I create a task to attempt merging the
# two dictionaries (which doesn't work):

- debug: msg="{{ item.key }} = {{ item.value }}"
  with_dict: my_default_values + my_values

# I have also tried:

- debug: msg="{{ item.key }} = {{ item.value }}"
  with_dict: my_default_values|union(my_values)

# I have /some/ success with using j2's update,
# but you can't use j2 syntax in "with_dict", it appears. …
Run Code Online (Sandbox Code Playgroud)

python merge dictionary ansible

41
推荐指数
4
解决办法
4万
查看次数

标签 统计

ansible ×1

dictionary ×1

merge ×1

python ×1