Scalar works in script but not when stored as variable

I have a YAML that will be imported by several of our microservices that use MongoDB. The scalar to add the users (below is snipped of it) works when it is in the script.

variables:
  MONGODB_USERS: |
    mongo --host wp-mongodb --eval '
      db = db.getSiblingDB("wp-library");
      db.createUser({ user: "wp-library", pwd: "xyz", roles: [ { role: "readWrite", db: "wp-library" } ], mechanisms:[ "SCRAM-SHA-1" ] });
    '

before_script:
  - echo "Installing MongoDB database tools"
  - echo $MONGODB_USERS
  - apt-get update
  - apt-get install -y gnupg
  - wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
  - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list
  - apt-get update
  - apt-get install -y mongodb-org=4.4.8 mongodb-org-server=4.4.8 mongodb-org-shell=4.4.8 mongodb-org-mongos=4.4.8 mongodb-org-tools=4.4.8
  - mongo --version
  - |
    mongo --host wp-mongodb --eval '
      db = db.getSiblingDB("wp-library");
      db.createUser({ user: "wp-library", pwd: "xyz", roles: [ { role: "readWrite", db: "wp-library" } ], mechanisms:[ "SCRAM-SHA-1" ] });
    '

If I change the script piece to use this it fails.

before_script:
  - echo "Installing MongoDB database tools"
  - echo $MONGODB_USERS
  ...
  - mongo --version
  - $MONGODB_USERS

It fails with the error

MongoDB server version: 4.4.10
uncaught exception: SyntaxError: "" literal not terminated before end of script :
@(shell eval):1:1
exiting with code -4

Here is what the echo shows for the variable.
mongo --host wp-mongodb --eval ' db = db.getSiblingDB("wp-library"); db.createUser({ user: "wp-library", pwd: "xyz", roles: [ { role: "readWrite", db: "wp-library" } ], mechanisms:[ "SCRAM-SHA-1" ] }); '

Now I’ve spent all morning trying all kinds of combinations for the variable and $MONGODB_USERS in the before_script. Any ideas on how to pull this off so I can use a variable when importing this config?