I’m having trouble with the following CI config for an Ansible project. I’m trying to set it up so that if I pass just the PLAY variable during the pipeline job, then only the Multiple Targets job will run, but if I pass both the PLAY and the TARGET variables, the job will only run on the Single Target job.
What’s happening is both jobs are running when I only pass the PLAY variable. My understanding was that if the variable exists or doesn’t exist, this should work but I guess I’m misunderstanding how it’s supposed to work.
Run Playbook on Multiple Targets:
stage: play
script:
- docker build --build-arg SSH_KEY="$SSH_KEY" --build-arg SSH_USER="$SSH_USER" -t $IMAGE .
- docker run --rm $IMAGE -v ./playbooks/$PLAY.yml | sed 's/\\n/\n/g'
- docker rmi $IMAGE
only:
variables:
- $PLAY
except:
variables:
- $TARGET
Run Playbook on Single Target:
stage: play
script:
- docker build --build-arg SSH_KEY="$SSH_KEY" --build-arg SSH_USER="$SSH_USER" -t $IMAGE .
- docker run --rm $IMAGE -v ./playbooks/$PLAY.yml -e working_host=$TARGET | sed 's/\\n/\n/g'
- docker rmi $IMAGE
only:
variables:
- $PLAY
- $TARGET