Ask Your Question
0

three hyphen in YAML file

asked 2015-02-26 10:54:36 -0500

Chutki gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2015-02-27 06:57:55 -0500

PorkCharSui gravatar image

updated 2015-02-27 12:41:59 -0500

Stefan gravatar image

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
edit flag offensive delete link more
0

answered 2015-02-27 09:48:11 -0500

gh gravatar image

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-02-26 10:54:36 -0500

Seen: 2,465 times

Last updated: Feb 27 '15