How to reference a !secret username in a jinja template

I am trying to create a rest_command and if I use plaintext for the username and password I get the response I expect, Great!, but not ideal.

rest_command:
  api_login:
    url: "https://X.X.X.X:443/api/auth/login"
    method: POST
    payload: >
      {
        "username": "!secret user",
        "password": "!secret pass"
      }
    headers:
      Content-Type: "application/json"
    verify_ssl: false

I keep reading that I can’t reference a secret within the jinja template?

Does someone have some thoughts on this?

Thanks in advance!

You can’t reference it in a Jinja2 template because !secret is YAML. Only the YAML processor knows how to handle it, not the Jinja2 processor. They’re two different languages with boundaries (i.e. they cannot process each others statements).

The solution is to put the entire payload template in the secret.

    payload: !secret payload_template
1 Like

Could you also put the secret it in a variable and then reference it in the template?