perl 剖析 yaml 的套件

  • Ubuntu :

    sudo apt-get install libyaml-perl

#!/usr/bin/perl
 
use YAML::Loader;
use Data::Dumper;
 
# Load a YAML stream of 3 YAML documents into Perl data structures.
my $loader = YAML::Loader->new;
my $hash = $loader->load(<<'...');
stages:
- name: Deploy--DB
  iiidevops: deployed-environments
  steps:
  - applyAppConfig:
      answers:
        db.gui: true
        db.name: todo_db
        db.password: templatePassword
        db.tag: 13
        db.type: postgresql
        db.username: iiidevops
        git.branch: ${CICD_GIT_BRANCH}
        git.commitID: ${CICD_GIT_COMMIT}
        git.repoName: ${CICD_GIT_REPO_NAME}
        git.url: ${CICD_GIT_URL}
      catalogTemplate: cattle-global-data:iii-dev-charts3-db
      name: ${CICD_GIT_REPO_NAME}-${CICD_GIT_BRANCH}-db
      targetNamespace: ${CICD_GIT_REPO_NAME}
      version: 0.3.1
  when:
    branch:
      include:
      - master
 
- name: Deploy--Wait DB deployment
  iiidevops: deployed-environments
  steps:
  - env:
      deploy_name: ${CICD_GIT_REPO_NAME}-${CICD_GIT_BRANCH}-db
      max_wait: 128
      namespace: ${CICD_GIT_REPO_NAME}
    envFrom:
    - sourceKey: API_TOKEN
      sourceName: pipeline-api-key
      targetKey: rancher_api_token
    - sourceKey: rancher-url
      sourceName: rancher
      targetKey: rancher_url
    runScriptConfig:
      image: iiiorg/deployment-waiter:0.0.2
      shellScript: rancher login ${rancher_url} -t ${rancher_api_token} --skip-verify; bash /app/run.sh
  when:
    branch:
      include:
      - master
...
 
# Dump the Perl data structures back into YAML.
#print Dumper($hash);
 
$i=0;
while ($hash->{'stages'}[$i]) {
        $hash_t = $hash->{'stages'}[$i];
        #print Dumper($hash_t);
        print("----- ".$hash_t->{'name'}." ---\n");
        print("\t ".$hash_t->{'iiidevops'}." \n");
        $i++;
}

執行結果

~$ perl example.pl
----- Deploy--DB ---
         deployed-environments
----- Deploy--Wait DB deployment ---
         deployed-environments
~$
  • tech/perl/yaml.txt
  • 上一次變更: 2021/08/28 20:40
  • jonathan