Currently I use gitlab-ci.yml, gitlab runners to execute some various actions with ansible. I dynamically create an inventory file with a python script in a docker image, take the artifact and send to a downstream project that runs a docker image with ansible and executes a playbook on that inventory.

The inventory file has grown a bit too large and I want to break this up, then for each smaller inventory file launch docker image and ansible playbook in parallel.

I thought there should be something like foreach in gitlab-ci.yml but have not found anything like that in the documentation.

init_demo:
  image: ${ARTIFACTORY_URL}/${IMAGE_PATH}/${IMAGE_NAME}:${IMAGE_VERSION}
  stage: init-stage
  tags:
    - docker
    - shared
  script: 
    - python3 /scripts/createinventory.py 
  artifacts:
    paths:
      - inventory.yml
    expire_in: 30 days
  rules:
    - if: $CI_ENV_TRIGGERED == "ALL" && $CI_LOB == "ALL"
configure_a_thing_with_ansible:
  stage: configure-stage
  trigger:
    project: configure-something
    branch: main
    strategy: depend
  only:
    - schedules

then downstream:

stages:
  - configure
configure_a_thing:
  image: ${ARTIFACTORY_URL}/${IMAGE_PATH}/${ANSIBLE_IMAGE}:${ANSIBLE_IMAGE_VERSION}
  stage: configure
  tags:
    - docker
    - shared
  script:
    - ansible-playbook -i ./inventory.yml ./ansible-playbook.yml 
  needs:
    - project: create_inventory_project
      job: init_demo
      ref: main
      artifacts: true
  only:
    variables: 
      - $CI_PIPELINE_SOURCE == "pipeline"