40
Y Masatani, National Institute of Informatics インフラ・コード化の実践における IPython Notebookの適用 政谷 好伸 谷沢 智史 横山 重俊 吉岡 信和 合田憲人 国立情報学研究所 Towards “Literate Computing for Infrastructure” 6/3/2015

Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

  • Upload
    no-bu

  • View
    336

  • Download
    5

Embed Size (px)

Citation preview

Page 1: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

インフラ・コード化の実践における IPython Notebookの適用

政谷 好伸 谷沢 智史 横山 重俊 吉岡 信和 合田憲人

国立情報学研究所

Towards “Literate Computing for Infrastructure” – 6/3/2015

Page 2: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

IPython Notebook

http: //ipython.org

1991: Python 1995: Numeric → NumPy (~2006) 2001: SciPy 2001: IPython 2003: Matplotlib … 2011: IPython Notebook 2015: Jupyter

Page 3: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

IPython Notebook

•  Python の Rich Web client な対話インターフェース

•  実行Code,実行結果(計算の結果や,結果を埋め込んだ図表),自然言語による手順や経緯の説明を ひとつにまとめて記述

•  “The purpose of Computing is insight, not numbers” – Hamming [Numerical

Methods for Scientists and Engineers (1962) Preface]

•  数理系研究者のツールとして発展

http: //ipython.org

1991: Python 1995: Numeric → NumPy (~2006) 2001: SciPy 2001: IPython 2003: Matplotlib … 2011: IPython Notebook 2015: Jupyter

アイデアの探索課程の記録,共同開発,再現可能な成果の公開,教育

Page 4: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Jupyter – Language Agnostic Notebook

- Interactive Python shell - Network protocol and Rich Web clients - Kernel for Python - Notebook file format and tools - Tools for Interactive Parallel - Nbviewer Computing

Page 5: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Jupyter – Language Agnostic Notebook

http: //jupyter.org

- Interactive Python shell - Network protocol and Rich Web clients - Kernel for Python - Notebook file format and tools - Tools for Interactive Parallel - Nbviewer Computing

Jupyter = Julia, Python & R †

Github でもサポート

- Language Agnostic

† https://github.com/jupyter/design/wiki/Jupyter-Logo

Page 6: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Literate Computing

Notebook という形

•  ... inspired by open language of science

• 計算機 = computation と 人間=communication が役割分担

ü 実際の実行結果が、説明に埋め込まれている..

手順や経緯 が具体的に,再現可能な形で表現・伝達 → reproducibility

ü  Technical と Non-Technical で 理解を共有

Page 7: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Literate Computing

Notebook という形

•  ... inspired by open language of science

• 計算機 = computation と 人間=communication が役割分担

ü 実際の実行結果が、説明に埋め込まれている..

手順や経緯 が具体的に,再現可能な形で表現・伝達 → reproducibility

ü  Technical と Non-Technical で 理解を共有

“Literate Computing” というアプローチ ü  The Notebook: “Literate Computing” – Fernando Perez

[ http://blog.fperez.org/2013/04/literate-computing-and-computational.html ]

インフラの構築・運用の場面に適用

Page 8: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Literate Computing

Notebook という形

•  ... inspired by open language of science

• 計算機 = computation と 人間=communication が役割分担

ü 実際の実行結果が、説明に埋め込まれている..

手順や経緯 が具体的に,再現可能な形で表現・伝達 → reproducibility

ü  Technical と Non-Technical で 理解を共有

“Literate Computing” というアプローチ ü  The Notebook: “Literate Computing” – Fernando Perez

[ http://blog.fperez.org/2013/04/literate-computing-and-computational.html ]

インフラの構築・運用の場面に適用..

It shall be applicable to Infrastructure / DevOps

Page 9: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Infrastructure as Code

Orchestration with “Coding Style”

•  CFEngine (1993~): http: //en.wikipedia.org/wiki/CFEngine

•  Puppet (2005~): http: //en.wikipedia.org/wiki/Puppet_(software)

•  Chef (2009~): https: //www.chef.io/blog/2009/01/15/announcing-chef/

•  Ansible (2012~): http: //en.wikipedia.org/wiki/Ansible_(software)

Page 10: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Infrastructure as Code

Orchestration with “Coding Style”

•  CFEngine (1993~): http: //en.wikipedia.org/wiki/CFEngine

•  Puppet (2005~): http: //en.wikipedia.org/wiki/Puppet_(software)

•  Chef (2009~): https: //www.chef.io/blog/2009/01/15/announcing-chef/

•  Ansible (2012~): http: //en.wikipedia.org/wiki/Ansible_(software)

DSL

DSL + ruby

DSL + ad-hoc

Page 11: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Infrastructure as Code

Orchestration with “Coding Style”

•  CFEngine (1993~): http: //en.wikipedia.org/wiki/CFEngine

•  Puppet (2005~): http: //en.wikipedia.org/wiki/Puppet_(software)

•  Chef (2009~): https: //www.chef.io/blog/2009/01/15/announcing-chef/

•  Ansible (2012~): http: //en.wikipedia.org/wiki/Ansible_(software)

Benefit of “Coding Style” : –  Validation, Auditing, cross OS …

–  CI (Continuous Integration), Automation …

–  Code vs. Config (Hiera,

DSL

DSL + ruby

DSL + ad-hoc

Page 12: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Automation だけではなく..

“as Code”(コード化)= Coding Style を適用する

•  作業手順が Code になる

•  作業手順の正当性がプログラムコードのように検証可能

•  実行結果も機械的に検証可能

•  記述言語の能力

•  記述に基づく機械化・自動化ツールの利便性

Page 13: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Automation だけではなく..

“as Code”(コード化)= Coding Style を適用する

•  作業手順が Code になる

•  作業手順の正当性がプログラムコードのように検証可能

•  実行結果も機械的に検証可能

•  記述言語の能力

•  記述に基づく機械化・自動化ツールの利便性

現場的には Communication が大切…

•  スキルセットが異なる当事者間においても.. 個々の作業の再現性を担保したい..

•  インフラの状態やそこに至るまでの経緯を理解し易くする..

•  その上で作業をカスタマイズ・再利用すると言ったプロセス自体も(Code として)見える化

•  伝達可能にすること,蓄積・発展させること

Automation ?

Page 14: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Automation だけではなく..

“as Code”(コード化)= Coding Style を適用する

•  作業手順が Code になる

•  作業手順の正当性がプログラムコードのように検証可能

•  実行結果も機械的に検証可能

•  記述言語の能力

•  記述に基づく機械化・自動化ツールの利便性

現場的には Communication が大切…

•  スキルセットが異なる当事者間においても.. 個々の作業の再現性を担保したい..

•  インフラの状態やそこに至るまでの経緯を理解し易くする..

•  その上で作業をカスタマイズ・再利用すると言ったプロセス自体も(Code として)見える化

•  伝達可能にすること,蓄積・発展させること

“Literate Computing for Infrastructure” – Open Communication about Design and Process through Notebook

Automation ?

Page 15: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

現実の問題として..

CI が適用できるようなケースも重要だけど..

すべてが Immutable, Idempotent という訳にはゆかない… 副作用積み重ねとして運用せざるを得ない… そういったものこそ手間がかかるし,気をつかう

Page 16: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

現実の問題として..

CI が適用できるようなケースも重要だけど..

すべてが Immutable, Idempotent という訳にはゆかない… 副作用積み重ねとして運用せざるを得ない… そういったものこそ手間がかかるし,気をつかう

相互にスキルセットが異なる状況..

• 運用担当... スキルセットの継承, ひとりですべてが解る訳ではない..

• 利用者… 目的に合わせてインフラをカスタマイズしたい..

/サポート担当… 手解き,問合せに効率的に対応したい ユーザの自立を促したい.. セルフ・アドミン

Page 17: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Continuous Integration

• Maintain a code repository – Revision Control

• Automated Build

• Make the build self-testing

–  Everyone commits to the baseline (every day.. Nightly build… )

–  Every commit to baseline should be build and tested

•  Keep the build FAST

–  Test in a clone of the production deployment

–  Make it easy to get the latest deliverables

–  Everyone can see the results of the latest build

• Automate deployment – Continuous deployment

http://en.wikipedia.org/wiki/Continuous_integration

Page 18: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

実現したいこと

•  作業の信頼性向上

•  手順の再利用

•  ポータブルな手順

•  環境に依存しない…

•  環境の変更に追従できる…

Page 19: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

実現したいこと

•  作業の信頼性向上

•  手順の再利用

•  ポータブルな手順

•  環境に依存しない…

•  環境の変更に追従できる…

Infrastructure でも Social Coding / Design Review のような..

情報の共有「綺麗なコード」を意識.. 美意識 à

architecture (operation込) における rationality /

cardinality of design を 対象化

Page 20: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

やってみたこと

Ansible + IPython Jupyter Notebook + Github

•  記述 à Ansible と Notebook で書き分け(再現性・斉一性の粒度など.. )

•  手順 à Github Pull Request を活用したワークフロー

•  “Who” (誰が) - “When did” (いつ) - “in What operation” (何をどうして) with “intention; Why” (どういうつもりが), then “Consequences

happened” (どうなった)

•  Narrative History of .. everything rationale

Page 21: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

運用作業者のための「追随可能な手順書」

http://localhost:8888/notebooks/実行例/運用者向_手順書%20-%20ACC開始.ipynb

http://localhost:8888/notebooks/実行例/運用者向_手順書%20-%20CentOS6.5マシン準備(必要ソフトウェアのインストール).ipynb

Page 22: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

利用者のための「追随可能な指示書・作業確認書」

内容の確認

カスタマイズに必要な情報の提供

セルフ・アドミニストレーション

http://localhost:8888/notebooks/実行例/ユーザ向_指示書・作業確認書-仮想マシン起動例.ipynb 

http://localhost:8888/notebooks/実行例/ユーザ向_先生用仮想マシン起動.ipynb 

Page 23: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

委託作業者による作業の「追試可能な作業報告書」

システムの構築作業を委託

→ 作業報告書や システムの保守・運用手順が

紙,電子ファイルとして納入される…

報告書 → 実作業の証跡としての有効

手順書 → 再利用する機会

Page 24: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

再利用性を重視したHadoopクラスタの構築手順書

http://localhost:8888/tree/murmur/notebooks/default

Page 25: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Anywhere Aggregation: なんでも、どこにでも配置できる

HDFS HDFS

YARN YARN Presto

HBase

Tez, Hive, Storm, Spark

Pre-Condition (Requirement for Serv) •  Ansibleが操作できるノード •  管理系ネットワークが設定済 •  Bootstrap OSがインストール済

Serv Serv Serv Serv Serv Serv Serv Serv Serv Serv Serv

http://localhost:8888/tree/murmur/notebooks/default

Hadoop族を対象に Ansible + Notebook で..

HDFS

Presto

Page 26: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Sample & DEMO

Page 27: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Ansible と Notebook の使い分け

Ansibleを選択する場合:

•  作業単位に冪等性がある,ないしは作業後の状態が一意に確定するなど再利用性が高い作業単位

•  複数の文脈で顕れる類似する作業群をパラメタ化によってひとつに集約して記述できる作業単位

•  複数の対象,サーバ群などに対する作業単位

Notebookを選択する場合:

•  依存関係のある一連の文脈を伴う作業の記述.例えば,事前・事後処理のあるひとまとまり作業単位

•  作業結果に基づいて一定の判断,確認が必要な作業単位

•  一部,機械化できない状態,人での作業を伴う作業単位

Page 28: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

再利用性を重視したHadoopクラスタの構築手順書

Page 29: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

再利用性を重視したHadoopクラスタの構築手順書

Page 30: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

再利用性を重視したHadoopクラスタの構築手順書

構造化はどのように進展するか?

Page 31: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

構造に関するもの

Ansible と Notebook の使い分け

• 文脈に依存しない手順はAnsibleで構造化

インフラの環境構成とシステムのあるべき姿としてのソフトウェア構成を記述

• 副作用を把握しなければならない手順,文脈を伴う手順についてはNotebookで構造化する

Page 32: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

構造に関するもの

Ansible と Notebook の使い分け

• 文脈に依存しない手順はAnsibleで構造化

インフラの環境構成とシステムのあるべき姿としてのソフトウェア構成を記述

• 副作用を把握しなければならない手順,文脈を伴う手順についてはNotebookで構造化する

• すべての作業はNotebookから実行

Ansibleの動作を含めすべてのコマンドによる作業の経緯を記録

• Ansibleのpleybookとrole,Notebookをバージョン管理

Page 33: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

経緯に関するもの

インフラ運用において伝達・共有したいこと…

過去に起こった経緯(いきさつ)これから起こるであろう経緯(なりゆき)

トレーサビリティの把握

複数作業間の依存関係,文脈の把握

Page 34: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

経緯に関するもの

インフラ運用において伝達・共有したいこと…

過去に起こった経緯(いきさつ)これから起こるであろう経緯(なりゆき)

トレーサビリティの把握

ü  “Who” (誰が) - “When did” (いつ) - “in What operation” (何をどうして) with “intention; Why” (どういうつもりが), then “Consequences happened” (どうなった)

ü  作業対象としてのインフラが,現在どうなっているか理解したい

複数作業間の依存関係,文脈の把握

ü  When(どういう時に)Why(なんのために)What operation(何をどうして)Consequence(どうなって欲しいのか)

ü  やり直しの効く範囲はどこまでか,戻せるのか

ü  (状況が変わったら,失敗したら)どこまで戻ればよいのか

ü  回復できないポイントとその回避可能性

ü  依存関係が恒常的なのか一時的なのか

ü  事前,事後の依存する作業

ü  分離できる条件と範囲, 作業の構造を見通したい

Page 35: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

どのような構造を把握すべきか

記述・ドキュメントの..「形」は何にしたがう..

ソフトウェアのアーキテクチャ

収容構成

運用の体制

当事者たる人間の関係性

蓄積と発展

Page 36: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

どのような構造を把握すべきか

記述・ドキュメントの..「形」は何にしたがう..

ソフトウェアのアーキテクチャ

収容構成

運用の体制

当事者たる人間の関係性

蓄積と発展

機能に従う

失敗に従う

Social な “Literacy”

Page 37: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

Notebookを作成する際の指針

•  インフラの状況を把握・確認する作業に対しては,予めコマンド群とその利用手順をまとめた定型Notebookを用意すると供に,正常時の実行結果を記録した状態で保存しておいたものを用いて作業する.既知のトラブル対応の作業等も同等.

•  非定型の運用作業は,原則Notebookをフロントとして実施し,実行コマンドとその出力結果を記録した状態で保存する.作業が何のために行われたかなど,機械的に記録されない内容はNotebookの中に直接記載する.定型的な運用作業は業務ごとにNotebookとして予め記述しておき手順書として利用する.

•  独立性のある一連の作業をひとつのNotebookとして記述する,Notebook間(作業間)に依存関係が存在する場合はNotebook上に説明する

•  環境情報,構成管理情報,複数のAnsibleのプレイブックにおいて共通化可能なパラメタ情報は,それらを設定管理するNotebookを独立に設ける

•  設計上の依存関係がある構成と作業についてはパラメタ化したAnsibleプレイブックとして記述する,あるいは共通のプレイブックを参照する類似・派生Notebookとして構造化を図る

模索中

Page 38: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

まとめ •  設計/運用情報を、再利用を考慮して構造化することができた,これにより構造化された

手順の依存関係を考慮して作業を実施できる

•  開発初期から運用中も含めて「あるべき姿」「現状」「過去の変更履歴」をトレースできる状態にある

•  手順書と実際に実行されるコマンドが一体とな à スキルの異なるメンバが作業しても,作業結果に乖離が発生しづらい「追随可能な手順書」というコンセプトは有効

•  Notebook化された手順を使って、開発者・運用者同士,あるいは利用者とコミュニケーションできる状態にある

•  NotebookやAnsibleプレイブックをGit管理することで履歴管理ができた

•  コラボレーションツールとして複数人が共同編集するのは難しい

 

「追随可能な手順書」~ Literate Computing for Infrastructure というコンセプトは運用者,利用者どちらからも受け入れられ得ることを確認できたと考える

今後 .. より分かりやすい記述,実行環境の配布方法,Gitとの連携,Jenkinsなどのテスト駆動ツールと連携するワークフローの在り方…

Page 39: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics

まとめ •  設計/運用情報を、再利用を考慮して構造化することができた,これにより構造化された

手順の依存関係を考慮して作業を実施できる

•  開発初期から運用中も含めて「あるべき姿」「現状」「過去の変更履歴」をトレースできる状態にある

•  手順書と実際に実行されるコマンドが一体とな à スキルの異なるメンバが作業しても,作業結果に乖離が発生しづらい「追随可能な手順書」というコンセプトは有効

•  Notebook化された手順を使って、開発者・運用者同士,あるいは利用者とコミュニケーションできる状態にある

•  NotebookやAnsibleプレイブックをGit管理することで履歴管理ができた

•  コラボレーションツールとして複数人が共同編集するのは難しい

 

「追随可能な手順書」~ Literate Computing for Infrastructure というコンセプトは運用者,利用者どちらからも受け入れられ得ることを確認できたと考える

今後 .. より分かりやすい記述,実行環境の配布方法,Gitとの連携,Jenkinsなどのテスト駆動ツールと連携するワークフローの在り方…

Page 40: Literate Computing for Infrastructure - インフラ・コード化の実践におけるIPython (Jupyter) Notebookの適用

Y Masatani, National Institute of Informatics