Foreach artifact file execute

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.

There isn’t anything like for-each. The script sections in CI configs are just Bash commands. So, you can put a Bash loop in there if you like, with a multi-line statement. However, it’s probably neater just to write a Bash script in a separate file and execute it from your .gitlab-ci.yml file.

ok, but how would i use the base script to kick off the jobs downstream like I do now?

Can you show me a rough outline of the YAML you have now?

init_demo:
  image: ${ARTIFACTORY_URL}/${IMAGE_PATH}/${IMAGE_NAME}:${IMAGE_VERSION}
  stage: init-stage
  tags:
    - docker
    - shared
    - us
  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
    - us
  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"