迭代列表并创建单个变量(字符串)

Iterate a list and create a single variable(string)

我有一个包含多个环境的列表。我想迭代它并使用迭代值创建单个变量。

例如:

{{ environment }} = [local, dev, prod]

使用循环我应该能够创建单个变量

{{ new_varible}} =>
This is local environment,This is dev environment,This is prod environment

我是 Ansible 的新手。我无法为此找到一种解决方案。

将每个带有mapjoin的元素修改成字符串:

set_fact:
  new_var: "{{ environment | map('regex_replace', '(.*)','This is \1 environment') | list | join(', ') }}"