<@ULVA73B9P> how do I get my prefect.yaml file to ...
# ask-marvin
m
@Marvin how do I get my prefect.yaml file to render a true or false value so that my schedule is only enabled on prod? - name: scheduler entrypoint: scheduler.py:schedule schedules: - cron: "0 1 * * *" slug: "london-schedule" timezone: "Europe/London" active: {{ $PREFECT_DEPLOY_ENV != 'dev' }}
m
thought for 195.2 seconds
n
the important thing is that $PREFECT_DEPLOY_ENV is evaluated at the time of running
prefect deploy
i'm also not sure you can put expressions like
foo != bar
in the templates like that
m
Great question. Assuming you’re on Prefect 3.x: the
prefect.yaml
templating system does not support expressions, so
{{ $PREFECT_DEPLOY_ENV != 'dev' }}
won’t work. Only simple placeholder substitution is supported. What you can do instead: Option 1: Drive it with a boolean environment variable - Set an env var to a boolean-like value per environment (e.g.,
true
in prod,
false
in dev). - Use the env var directly for
active
(don’t quote it so it’s treated as a boolean). prefect.yaml:
Copy code
deployments:
  - name: scheduler
    entrypoint: scheduler.py:schedule
    schedules:
      - cron: "0 1 * * *"
        slug: "london-schedule"
        timezone: "Europe/London"
        active: {{ $SCHEDULE_ACTIVE }}
Then in your deploy environment: - Prod:
export SCHEDULE_ACTIVE=true
- Dev:
export SCHEDULE_ACTIVE=false
Notes: - Acceptable values: `true`/`false`, `1`/`0` (strings are fine; they’ll be coerced to booleans). - Avoid quotes around the template so it’s not turned into a string. Option 2: Use a Prefect Variable - Reference a Prefect variable and set it differently per environment/workspace. prefect.yaml:
Copy code
deployments:
  - name: scheduler
    entrypoint: scheduler.py:schedule
    schedules:
      - cron: "0 1 * * *"
        slug: "london-schedule"
        timezone: "Europe/London"
        active: {{ prefect.variables.schedule_active }}
Set the variable:
Copy code
prefect variable set --name schedule_active --value true   # prod
prefect variable set --name schedule_active --value false  # dev
Option 3: Separate deployments per env - Define two deployments in the same file and set
active
statically, then deploy the one you need:
Copy code
deployments:
  - name: scheduler-dev
    entrypoint: scheduler.py:schedule
    schedules:
      - cron: "0 1 * * *"
        slug: "london-schedule"
        timezone: "Europe/London"
        active: false

  - name: scheduler-prod
    entrypoint: scheduler.py:schedule
    schedules:
      - cron: "0 1 * * *"
        slug: "london-schedule"
        timezone: "Europe/London"
        active: true
Then deploy the one you want:
Copy code
prefect deploy --name scheduler-prod
If you share how you’re running
prefect deploy
(local/CI, single or multiple workspaces), I can suggest the cleanest option for your setup.