我有一个字符串变量,像这样
我尝试使用with_sequence循环,但只得到索引(1、2、3等)。
我收到了这样的东西:
RCD_APIS=backend,api-alerting,api-tracking,api-versioning
,它包含我的Docker镜像的名称。我需要将其拆分成数组并循环遍历,以便我可以拉取每个Docker镜像。我尝试使用with_sequence循环,但只得到索引(1、2、3等)。
- name: pull images from registry
docker_image:
name: "hostname:5000/{{ RCD_APIS.split(',') }}"
pull: true
state: present
tag: "{{RCD_VERSION_CURRENT}}"
with_sequence: count={{ RCD_APIS|count }}
我也尝试使用with_item循环,但它不起作用,所以我尝试进行调试:
vars:
- container: "{{ RCD_APIS }}"
tasks:
- name: pull images from registry debug
debug: var={{item|basename}}
with_items: container.split(',')
我收到了这样的东西:
(item=container.split(',')) => {
"container.split(',')": [
"backend",
"api-alerting",
"api-tracking",
"api-versioning",
"connecteur-gdfa",
"api-batch",
"ihm"
],
"item": "container.split(',')"
}
那么我如何循环遍历该数组(类似于 foreach),并执行 docker pull backend, docker pull api-alerting
...?