Hyppää sisältöön

Docs CSC now features an automatic Finnish translation. Click here for more information.

Warning!

Puhti and Mahti will be decommissioned after Roihu becomes available. Users should clean up unnecessary files and move any required data by the end of August 2026. See the Roihu data preparation instructions for details.

Puhti scratch is very full: keep only active data there and move or delete everything else. No new Puhti scratch quota will be granted.

Perustaso

Tarvitset vain perustason tietoteknistä osaamista. On hyödyllistä tietää, miten XML tai JSON toimii.

Lyhyt johdanto YAMLiin

YAMLia käytetään avain-arvo-kuvausten ja taulukoiden kuvaamiseen. YAML-tiedostot tunnistetaan tiedostopäätteestä .yml tai .yaml.

YAML-aineisto voi olla

  • arvo
value
  • taulukko
- value 1
- value 2
- value 3

tai

[value 1, value 2, value 3]
  • sanakirja
key: value
another_key: another value

tai

key:
  value
another_key:
  another value
  • YAML-aineisto
key:
  - value 1
  - another key:
      yet another key: value 2
    another key 2:
      - more values
    this keys value is also an array:
    - but indentation is not necessary here

Arvoja voidaan syöttää usealle riville käyttäen merkkiä >:

key: >
  Here's a value that is written over multiple lines
  but is actually still considered a single line until now.

  Placing double newline here will result in newline in the actual data.

Sanatarkka tyyli on tuettu merkillä |:

key: |
  Now each
  newline is
  treated as such

YAML vs JSON

YAML on JSONin (JavaScript Object Notation) yläsarja. Siten

{
  "key": [
    {
      "value 1": {
        "another key": {
          "yet another key": "value 2"
        },
        "another key 2": [
          "more values"
        ],
        "this keys value is also an array": ["but indentation is not necessary here"]
      }
    }
  ]
}

on myös kelvollista YAMLia. Yleisesti ottaen YAML on tiiviimpää kuin JSON:

key:
  - value 1:
      another key:
        yet another key: value 2
      another key 2:
        - more values
      this keys value is also an array:
        - but indentation is not necessary here

yq-komentorivityökalu

yq on hyödyllinen työkalu yamlin käsittelyyn. Sen voi asentaa käyttäen pip:

$ pip show yq  
Name: yq
Version: 3.0.2
Summary: Command-line YAML/XML processor - jq wrapper for YAML/XML documents
Home-page: https://github.com/kislyuk/yq
Author: Andrey Kislyuk
Author-email: kislyuk@gmail.com
License: Apache Software License
Location: /home/jtahir/Documents/csc-stuff/osclient/lib/python3.6/site-packages
Requires: argcomplete, PyYAML, toml, xmltodict
Required-by: 

yq on jq-wrapperi, mikä tarkoittaa, että se muuntaa yaml-syötteen jsoniksi ja välittää sitten käsittelyn jq:lle. Tästä syystä sen syntaksi on sama kuin jq:n. Alla olevassa esimerkissä .data.WebHookSecretKey:n arvo haetaan raakamuodossa (ilman lainausmerkkejä):

$ echo 'apiVersion: v1
kind: Secret
data:
  WebHookSecretKey: dGhpc19pc19hX2JhZF90b2tlbgo=
metadata:
  name: webhooksecret
  namespace: mynamespace     # set this to your project namespace
' | yq ' .data.WebHookSecretKey ' -r
dGhpc19pc19hX2JhZF90b2tlbgo=

Lisätietoja on sivustoilla yaml.org ja json.org.

Suomenkielinen tekoälykäännös

Sisällössä voi esiintyä virheellistä tietoa tekoälykäännöksestä johtuen.

Klikkaa tästä antaaksesi palautetta