Devops

YAML ๋ฌธ๋ฒ•

YAML

  • .yaml, .yml ํ™•์žฅ์ž
  • UTF-8 or UTF-16๊ณผ ๊ฐ™์ด ์ถœ๋ ฅ ๊ฐ€๋Šฅํ•œ ์œ ๋‹ˆ์ฝ”๋“œ ๋ฌธ์ž์ง‘ํ•ฉ์„ ์ด์šฉ
  • XML, JSON, YAML ๋ชจ๋‘ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ํ˜•์‹์œผ๋กœ ํ˜•ํƒœ์™€ ๋ฌธ๋ฒ•์ด ๋‹ค๋ฆ„
    • XML : HTML๊ณผ ๋น„์Šทํ•˜๋ฉฐ ๊บฝ์‡ (<>)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ์ด๋ฃจ๊ณ  ์žˆ์Œ
    • JSON : REST API์— ์‚ฌ์šฉ๋˜๋ฉฐ ์ตœ๊ทผ XML๋ณด๋‹ค ๋งŽ์ด ์‚ฌ์šฉ๊ณ  ์žˆ์Œ, ์ฃผ์„์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค๋Š” ํŠน์ง•์ด ์žˆ์œผ๋ฉฐ ๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉ
    • YAML : ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ํ‘œํ˜„ํ•˜์˜€์œผ๋ฉฐ ๊ณต๋ฐฑ ์œ„์ฃผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ๋ถ„
  • YAML ๊ณต์‹ : https://yaml.org/
  • JSON to YAML : https://www.json2yaml.com/
  • YAML ๋ฌธ๋ฒ• ์ฒดํฌ : http://www.yamllint.com/

 

์ฃผ์„(commnet)

  • # ๋กœ ํ‘œ์‹œ
  • ํ•œ ์ค„์ด ๋๋‚ ๋•Œ๊นŒ์ง€ ์œ ์ง€
#์ด๊ฑด ์ฃผ์„

 

๋“ค์—ฌ์“ฐ๊ธฐ(indent)

  • ์ผ๋ฐ˜์ ์œผ๋กœ 2์นธ ์‚ฌ์šฉ
  • 2์นธ or 4์นธ
  • ํƒญ X
  • ๊ฐ™์€ ๋ถ€๋ชจ ๋…ธ๋“œ๋ฅผ ๊ฐ€์ง€๋Š” ์ž์‹ ๋…ธ๋“œ๋ผ๋ฆฌ๋Š” ๋“ค์—ฌ์“ฐ๊ธฐ๊ฐ€ ์ผ์น˜ ํ•„์ˆ˜!
user:
  name: eunhye
  like:
    - coffee
    - dessert

 

๋ฐ์ดํ„ฐ ์ •์˜(mapping)

  • hash or dictionary
  • key: value ํ˜•์‹
  • { } ๋กœ๋„ ๊ฐ€๋Šฅ
  • ์ฝœ๋ก (:) ๋’ค์— ๊ณต๋ฐฑ์€ ํ•„์ˆ˜!
user:
  name: eunhye
  like:
    - coffee
    - dessert
user: {
  name: eunhye,
  like: [
    coffee, dessert
  ]
}

 

์Šค์นผ๋ผ(scalar)

  • ๊ฐ„๋‹จํ•œ ๊ฐ’..?! ๋ฌธ์ž or ์ˆซ์ž
  • ๋ณดํ†ต ์•„๋ฌด ํ‘œ์‹œ๋„ ์•ˆํ•˜์ง€๋งŒ ๋”ฐ์˜ดํ‘œ(")๋‚˜ ์ž‘์€ ๋”ฐ์˜ดํ‘œ(')๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•จ
  • ๋ฌธ์ž ์•ˆ์— ์ฝœ๋ก (:)์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ๋”ฐ์˜ดํ‘œ ํ•„์š”
  • ๋”ฐ์˜ดํ‘œ ์•ˆ์—์„œ ํŠน์ˆ˜ ๋ฌธ์ž๋Š” C์–ธ์–ด ์Šคํƒ€์ผ์„ ๋”ฐ๋ฆ„! ์˜ˆ๋ฅผ ๋“ค์–ด์„œ newline = \n
user:
  name: eunhye
  like:
    - "coffee"
    - 'dessert'

 

์‹œํ€€์Šค(sequence)

  • list or array
  • - ๋กœ ํ‘œ์‹œ
  • [ ] ๋กœ๋„ ๊ฐ€๋Šฅ
user:
  name: eunhye
  like:
    - coffee
    - dessert
user: {
  name: eunhye,
  like: [
    coffee, dessert
  ]
}

 

์ฐธ/๊ฑฐ์ง“(boolean)

  • true/false, yes/no ์ง€์›
user:
  name: eunhye
  male: false
  female: true

 

์ˆซ์ž(number)

  • ์Œ๋”ฐ์˜ดํ‘œ(")๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ž๋กœ ์ธ์‹
user:
  name: eunhye
  age: 27 #number 27
user:
  name: eunhye
  age: "27" #string 27

 

์ค„๋ฐ”๊ฟˆ(newline)

  • | ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ธ”๋ก ๋‚ด ์ค„๋ฐ”๊ฟˆ ํ—ˆ์šฉ๋˜๋ฉฐ ๋งˆ์ง€๋ง‰ ์ค„๋ฐ”๊ฟˆ ํฌํ•จ
lines: | 
  first line

  second line

  third line
{
  "lines": "first line\n\nsecond line\n\nthird line\n"
}
  • |- ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ธ”๋ก ๋‚ด ์ค„๋ฐ”๊ฟˆ ํ—ˆ์šฉ๋˜๋ฉฐ ๋งˆ์ง€๋ง‰ ์ค„๋ฐ”๊ฟˆ ๋ฏธํฌํ•จ
- lines: |-
  first line

  second line

  third line
{
  "lines": "first line\n\nsecond line\n\nthird line\n"
}
  • > ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ธ”๋ก ๋‚ด ์ค„๋ฐ”๊ฟˆ ํ—ˆ์šฉ๋˜๋ฉฐ ์ค‘๊ฐ„์— ๋“ค์–ด๊ฐ„ ์ค„๋ฐ”๊ฟˆ ๋ฏธํฌํ•จ, ๋งˆ์ง€๋ง‰ ์ค„๋ฐ”๊ฟˆ ํฌํ•จ
lines: >
  first line

  second line

  third line
{
  "lines": "first line\nsecond line\nthird line\n"
}

 

๋ฐ˜๋ณต

  • ๋ฐ˜๋ณต๋˜๋Š” ๋…ธ๋“œ๋“ค์€ achor์™€ alias๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ
users:
  first-anchor: &first
    name: eunhye
    age: "26"
  second-anchor: &second
    name: yeji
    age: "25"

first-child  : *first #first-child๋กœ ์ ‘๊ทผํ•˜๋ฉด first-anchor๋กœ ์ ‘๊ทผ
second-child : *second #secnod-child๋กœ ์ ‘๊ทผํ•˜๋ฉด second-anchor๋กœ ์ ‘๊ทผ

 

๋ฌธ์„œ์˜ ์‹œ์ž‘๊ณผ ๋

  • ์„ ํƒ ์‚ฌํ•ญ
--- #๋ฌธ์„œ์˜ ์‹œ์ž‘ 

... #๋ฌธ์„œ์˜ ๋

'Devops' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๋ฐฐํฌ ์ „๋žต  (0) 2021.10.22
terraform ๋ฒ„์ „ ๊ด€๋ฆฌ : tfenv  (0) 2021.10.03
Config ์ž๋™ํ™” ํˆด(puppet, chef, salt, ansible)  (0) 2021.04.13
Terraform ์‚ฌ์šฉ๋ฒ•  (0) 2021.03.20
AWS CDK ์‚ฌ์šฉ๋ฒ•  (0) 2021.03.20