how to split string to array and loop over it?

I have a string variable like this RCD_APIS=backend,api-alerting,api-tracking,api-versioning that contains the name of my docker images. I need to split it into an array and loop over it so I can pull each docker image

I have tried the with_sequence loop but i get just the index (1,2,3,..)

  • How to write an Ansible playbook with Docker-compose
  • How to use wait_for in a two node cluster docker container deployment?
  • Host to container volume mapping using Ansible not working
  • Ansible 1.9.0.1 docker module picks random port by default
  • Run 'docker volume create' with Ansible?
  • Minor change in ansible playbook does not get updated in target host
  • - 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 }}
    

    I also tried with_item loop but it doesn’t work so i tried to debug :

     vars:
        - container: "{{ RCD_APIS }}"
     tasks:
        - name: pull images from registry debug
          debug: var={{item|basename}}
          with_items: container.split(',')
    

    i get something like:

    (item=container.split(',')) => {
             "container.split(',')": [
             "backend", 
             "api-alerting", 
             "api-tracking", 
             "api-versioning", 
             "connecteur-gdfa", 
             "api-batch", 
             "ihm"
         ], 
         "item": "container.split(',')"
    }
    

    so how can i loop over that array (like a foreach) and do the docker pull backend, docker pull api-alerting… ?

  • How to enable Redmines 'adding of issues' when using Docker?
  • docker run with cd command fails with executable file not found in $PATH
  • Unable to connect to MySQL in Docker from local host (Docker for Mac beta)
  • meet Call to undefined function Xinax\LaravelGettext\bindtextdomain() error in LaravelProject
  • Why isn't my Dockerfile's ARG expanded?
  • docker hub images tags are not showing using automated build from github organisation repo
  • One Solution collect form web for “how to split string to array and loop over it?”

    Here you go:

    - name: pull images from registry
      docker_image:
        name: hostname:5000/{{ item }}
        pull: true
        state: present
        tag: "{{RCD_VERSION_CURRENT}}"
      with_items: "{{ RCD_APIS.split(',') }}"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.