Skip to main content
August 23, 2022
Question

How to load content from file using yaml template?

  • August 23, 2022
  • 2 replies
  • 538 views

So, I've been trying to work around based on https://developer.1password.com/docs/cli/secrets-config-files#step-1-create-secret-references link.

My idea is to have a file on 1Password like:

yaml
db:
username: blabla
password: iamasecret
api:
whatever: whenever

And then, load to a yaml template file using op inject. However, when I try to do such a thing I get:

shell
item <vault id>/<item id> does not have a field db.username

Which makes sense when I discover the file running `op item get --format json. I wonder if it is possible to achieve such a thing because my secrets are very customized and doesn't fit any of the pre sets 1Password provides (login, api credential, etc).

Btw, I'm using the CLI 2.0.0


1Password Version: 8.9.4
Extension Version: Not Provided
OS Version: 12.5
Browser:_ Not Provided

2 replies

August 23, 2022

For now I ended up creating an empty note and adding fields to it. It would be so cool to be able to create a secret with no pre-defined fields

1Password Employee
September 1, 2022

Hi @matheushent, thanks for reaching out. If I understood your question correctly, the CLI allows for creation of items from a template file using either piping or passing a file path to the command's --template flag, under the condition that the file has json format (so yaml is not currently supported for creation - nor editing for that matter). To achieve this, use: op item create --template myFile. To get a sense of how myFile should look like, use op item template get Login, for instance. The piped version of this command should then go like this op item template get Login | op item create --vault Private -. If you need a way to replicate nested fields like in yaml, you could make use of an item's section/field structure. If you need more than 2 nested fields this would no longer suit your needs, and what I would do is straight up attach a yaml file to my item or create a document type item with a yaml file.

Let me know if this answers your question.
Best,
Andi