three hyphen in YAML file

Hi,

My understanding of "---" yaml file hyphens is, multiple documents within a single stream are separated by three hyphens

But I have seen in many example just in the beginning of the YAML file only they use three hyphens

If the same file use another document it, then they don't start with --- hyphens

example below

test.yaml
---
user::user_list:

name1:
id: 123
name2:
id: 456

occupation::emp_id
job:
designation: programer


So in this file we use two different thing one is for emp id detiais and the another is for job details,then why we didn't use "---" in between these, two like below

test.yaml
---
user::user_list:

name1:
id: 123
name2:
id: 456
---
occupation::emp_id
job:
designation: programer


Please correct me if my understanding is wrong

edit retag close merge delete

Sort by » oldest newest most voted

YAML spec says:
YAML uses three dashes (---) to separate directives from document content. This also serves to signal the start of a document if no directives are present.

But you do hiera lookups on user::user_list and occupation::emp_id, so you can leave the second --- out. As long as --- is at the top of the document the system knows it is a yaml document. so this test.yaml:

---
user::user_list:
name1:
id: 123
name2:
id: 456
occupation::emp_id
job:
designation: programmer


Should do the same as this test.yaml:

---
user::user_list:
name1:
id: 123
name2:
id: 456
---
occupation::emp_id
job:
designation: programmer

more

Only put the three dashes at the top of the file. There is no need to have it anywhere else.

more