Share
Embed
VBAから見たAnsiblePlaybookとの比較/diff-vba-ansible
mito
December 18, 2020
Transcript
11 slides
-
VBA Ansible ?? はじめに 2 ✘ 習得済みのスキルを活かして、次のスキルの理解速度を上げたい ✘ 本資料のみでAnsible Playbookが書けるようになるわけではありません
✘ Ansible Playbookの最適な書き方は紹介しません(できない) -
VBA ✘ 記載する順番はない Sub main() Dim str_hoge As String str_hoge
= "テスト" MsgBox str_hoge Dim i As = 11 i = i + 10 End Sub インデントはなくても動く TABも使える 全体的な構文の比較 Ansible Playbook ✘ 記載内容が定まったセクションあり --- - hosts: all vars: filename: test tasks: - name: touch file file: path: /etc/{{ filename }} state: touch インデントは必要(半角SP2個が基準) TABは使えない 4 -
VBA ✘ 関数と処理を書く Function func_test(para_a As String) MsgBox param_a End
Function ✘ 呼び出し処理を書く call func_test( str_xx ) 関数の比較 Ansible Playbook ✘ 関数や処理はモジュールとして用意 されており、基本的にそれを使う ✘ モジュールを選び、パラメータを 指定する - name: touch file file: path: /etc/{{ filename }} state: touch 5 モジュール名(=関数名) パラメータ(=引数) -
VBA ✘ 型宣言あり Dim str_hoge As String ‘ 文字列型 Dim
i As Long ‘ 長整数型 ✘ 変数に代入する場合 str_xxx = str_hoge 変数の比較 1 Ansible Playbook ✘ 型宣言はないが、違いはある ✘ 定義と初期化がセット minute: "11" # 文字列は"で囲む minute: 11 # 数値として扱える ✘ 変数に代入する場合 time: “{{ minute }}” ✘ 基本的に定数として使う 6 -
VBA ✘ グローバル変数として扱う場合 Public Dim s_hoge as String ‘ 変更可能な文字列
Public Const c_hoge = “テキスト” ‘ 変更できない文字列 ✘ 定数を推奨 Ansible Playbook ✘ グローバル変数として扱う場合 vars_files: - test.yml tasks: - name: xxx # 専用ファイルとして用意し、 tasksセクション毎に書く 変数の比較 2 7 -
VBA ✘ システムによるエラー以外は、 作成者が仕込む必要がある ✘ 被疑個所やその少し前にブレーク ポイントを設けて、ステップモード で1行ずつ実行し、変数の中身を 確認する デバッグ方法の比較
Ansible Playbook ✘ モジュールにエラーメッセージが 含まれるため、全般的に表示される ✘ オプション-V(--verbose)で、処理内 容の詳細を表示する ✘ ansible-lintで、Ansible文法の正しさ をチェックする $ ansible-lint test.yml ✘ オプション--syntax-checkで、Yaml 文法の正しさをチェックする 8 -
その他 変数の配列 vars: fruits_list: - apple - gorilla Loop処理 debug:
msg: "{{ item }}" loop: - rap - panda Select case文 file: path: /etc/xxx.conf state: touch when: XXX == 'ostrich' If文 うーん・・・ その他 etc 9 ファイルの分け方 roles/ xxxx/ tasks/main.yml vars/main.yml -
11 Free templates for all your presentation needs Ready to
use, professional and customizable 100% free for personal or commercial use Blow your audience away with attractive visuals For PowerPoint and Google Slides