Ansible 紹介 R&Dセンター OSS 戦略企画室 OSS 技術第二課角馬文彦 本文中の会社名 商品名は 各社の商標及び登録商標です

Similar documents
Installation Manual WIND TRANSDUCER

Intermediate Conversation Material #10

Omochi rabbit amigurumi pattern

U N I T. 1. What are Maxine and Debbie talking about? They are talking about. 2. What doesn t Maxine like? She doesn t like. 3. What is a shame?

D80 を使用したオペレーション GSL システム周波数特性 アンプコントローラー設定. Arc 及びLine 設定ラインアレイスピーカーを2 から7 までの傾斜角度に湾曲したアレイセクションで使用する場合 Arcモードを用います Lineモード

アルゴリズムの設計と解析. 教授 : 黄潤和 (W4022) SA: 広野史明 (A4/A8)

Delivering Business Outcomes

Decisions in games Minimax algorithm α-β algorithm Tic-Tac-Toe game

Lesson 5 What The Last Supper Tells Us

相関語句 ( 定型のようになっている語句 ) の表現 1. A is to B what C is to D. A と B の関係は C と D の関係に等しい Leaves are to the plant what lungs are to the animal.

Final Product/Process Change Notification Document # : FPCN22191XD1 Issue Date: 24 January 2019

XG PARAMETER CHANGE TABLE

CER7027B / CER7032B / CER7042B / CER7042BA / CER7052B CER8042B / CER8065B CER1042B / CER1065B CER1242B / CER1257B / CER1277B

TED コーパスを使った プレゼンにおける効果的な 英語表現の抽出

CPM6018RA Datasheet 定電流モジュール. Constant-current Power Modules. TAMURA CORPORATION Rev.A May, / 15

Specifications characterize the warranted performance of the instrument under the stated operating conditions.

Chronicle of a Disaster: Understand

レーダー流星ヘッドエコー DB 作成グループ (murmhed at nipr.ac.jp) 本規定は レーダー流星ヘッドエコー DB 作成グループの作成した MU レーダー流星ヘッド エコーデータベース ( 以下 本データベース ) の利用方法を定めるものである

研究開発評価に関する国際的な視点や国際動向

P (o w) P (o s) s = speaker. w = word. Independence bet. phonemes and pitch. Insensitivity to phase differences. phase characteristics

Standardization of Data Transfer Format for Scanning Probe Microscopy


[ 言語情報科学論 A] 統計的言語モデル,N-grams

L1 Cultures Go Around the World

TDK-Lambda A C 1/27

Ⅲ. 研究成果の刊行に関する一覧表 発表者氏名論文タイトル名発表誌名巻号ページ出版年. lgo/kourogi_ pedestrian.p df. xed and Augmen ted Reality

磁気比例式 / 小型高速応答単電源 3.3V Magnetic Proportion System / Compact size and High-speed response. Vcc = +3.3V LA02P Series

次の対話の文章を読んで, あとの各問に答えなさい ( * 印の付いている単語 語句には, 本文のあとに 注 がある )

1XH DC Power Module. User manual ユーザマニュアル. (60V 15A module version) HB-UM-1XH

Keio University Global Innovator Accelera6on Program 2015 Day 7 Design Process Exercise

Minecraft You Need To Run The Version Manually At Least Once

車載カメラにおける信号機認識および危険運転イベント検知 Traffic Light Recognition and Detection of Dangerous Driving Events from Surveillance Video of Vehicle Camera

Title of the body. Citation. Issue Date Conference Paper. Text version author. Right

Instruction Manual. Model IB100 Interface Box. IM 12B06J09-01E-E 2nd edition. IM 12B06J09-01E-E_ed02.indd 1 01/12/16 15:52

Effects and Problems Coming in Sight Utilizing TRIZ for Problem Solving of Existing Goods

ITU-R WP5D 第 9 回会合報告書

4. Contact arrangement 回路形式 1 poles 1 throws 1 回路 1 接点 (Details of contact arrangement are given in the assembly drawings 回路の詳細は製品図による )

Omni LED Bulb. Illustration( 实际安装, 설치사례, 設置事例 ) Bulb, Downlight OBB. OBB-i15W OBB-i20W OBB-i25W OBB-i30W OBB-i35W. Omni LED.

Title inside of Narrow Hole by Needle-Typ. Issue Date Journal Article. Text version author.

Private Equity: where should you invest today? P&I Global Pension Symposium, Tokyo

P Z N V S T I. センサ信号入力仕様 Input signal type. 1 ~ 5 V 4 ~ 20 ma 1 ~ 5 V 4 ~ 20 ma 1 ~ 5 V 4 ~ 20 ma 1 ~ 5 V 4 ~ 20 ma

The seven pillars of Data Science

PH75A280-* RELIABILITY DATA 信頼性データ

超小型 Very small (L:3.2 W:1.5 t:0.4mm) 高利得 High gain 無指向性 Omini-directional. < 用途 Applications> PHS 機器 DECT 機器 その他 PHS & DECT systems, etc ST01

The Current State of Digital Healthcare

F01P S05L, F02P S05L, F03P S05L SERIES

品名 :SCM1561M 製品仕様書. LF No RoHS 指令対応 RoHS Directive Compliance 発行年月日 仕様書番号 SSJ SANKEN ELECTRIC CO., LTD. 承認審査作成 サンケン電気株式会社技術本部 MCD 事業部

GDC2009 ゲーム AI 分野オーバービュー

TDK Lambda A /9

修士 / 博士課程専門課題 Ⅱ 試験問題

Call for a Pro-Innovation

Season 15: GRAND FINAL PLAYER GUIDE. ver.2019/1/10

9 th TRIZ symposium Meltex, Inc. Tajima. QFD and TRIZ Case Study in Surface Treatment Chemical

特集 米国におけるコンシューマ向けブロードバンド衛星サービスの現状

IMPORTANT SAFETY INSTRUCTIONS Regulatory Safety Information

Present Status of SMEs I

Big thank you from Fukushima Friends UK (FF)

HARD LOCK Technical Reports

Studies on Modulation Classification in Cognitive Radios using Machine Learning

TDK Lambda C /35

Effective Utilization of Patent Information in Japanese global companies

SanjigenJiten : Game System for Acquiring New Languages Visually 三次元辞典 : 第二言語学習のためのゲームシステム. Robert Howland Emily Olmstead Junichi Hoshino

Study on Multipath Propagation Modeling and Characterization in Advanced MIMO Communication Systems. Yi Wang

Simple Utility-Interactive Photovoltaic Power Conditioners Installed in Veranda of Apartment Houses

Indonesian Printing Industry Trends, Current Technology, and Future Development

無線通信デバイスの技術動向 松澤昭 東京工業大学大学院理工学研究科電子物理工学専攻 TiTech A. Matsuzawa 1

Immersive and Non-Immersive VR Environments: A Preliminary EEG Investigation 没入型および非没入型 VR 環境 :EEG の比較. Herchel Thaddeus Machacon.

TDK Lambda WC /24

Page No. 原文 リライト EDITOR'S NOTES 1 4 NATURAL ART

超伝導加速空洞のコストダウン. T. Saeki (KEK) 24July ILC 夏の合宿一ノ関厳美温泉

2018 年 3 月期決算説明会 筒井公久. Presentation on Business Results of FY 3/2018 (April 1, 2017 to March 31, 2018)

科学技術 学術審議会大型プロジェクト作業部会 2015 年 12 月 22 日 永野博

屋内用 SSPA パッケージ. 余裕ある高出力 : 1.1kW S-Band 1.1kW C-Band 1.0kW X-Band 500W Ku-Band ユニバーサル電圧電源力率補正型

TDK Lambda INSTRUCTION MANUAL. TDK Lambda C A 1/35

Keysight 16451B Dielectric Test Fixture

NI PXI/PCI-5411/5431 Specifications

Infineon 24GHz Radar Solution. May 2017 PMM RSF DM PMM Business development

SITES OF JAPAN S MEIJI INDUSTRIAL REVOLUTION: IRON AND STEEL, SHIPBUILDING AND COAL MINING

3 안전을위한주의사항 AAH-02B3W. Product Composition & Specifications. Product Manual. Cautions for Safety. Cautions for Safety. Cautions.

Sales are increasing every year!

Multi-bit Sigma-Delta TDC Architecture for Digital Signal Timing Measurement

Forge You Need To Run The Version Manually At Least Once

INSTALLATION MANUAL NMEA DATA CONVERTER IF-NMEA2K2

Creation of Digital Archive of Japanese Products Design process

CG Image Generation of Four-Dimensional Origami 4 次元折り紙の CG 画像生成

アナログ RF 回路の先端設計技術動向. Akira Matsuzawa. Department of Physical Electronics Tokyo Institute of Technology A.

Preparation and Properties of Retted Kenaf Bast Fiber Pulp and Evaluation as Substitute for Manila Hemp Pulp

記号 / 定格 /Ratings. B. 電気的特性 /Electrical Characteristics 測定条件 /Measure Condition (Tc = 25 ±3 ) 記号 / 測定条件 /Measure Condition

第 1 回先進スーパーコンピューティング環境研究会 (ASE 研究会 ) 発表資料

GLXD4R. Note: WARNING. Half-Rack Wireless Receiver

都市基盤工学 ( リモートセンシングと GIS 入門 ) Introduction to Remote Sensing and GIS. Ground-based sensors 地上からのセンサ 第 4 回 千葉大学大学院融合理工学府

NINJA LASER INNOVATORS BY DESIGN SINCE 1770

りれきしょ. What to do before writing. Advice on writing your Entry Sheet Content. Entry Sheets and rirekisho. III. To Succeed in the Screening Process

NSSM124T Pb-free Reflow Soldering Application RoHS Compliant RGB Sorted (RGB die lit separately.)

NINJA Experiment : Neutrino Interaction research with Nuclear emulsion and J-PARC Accelerator

Hacked ace gangster. City Hacked. Key hacks [3] Money [4] Health [5] Exp [6] Ammo for all weapons [7] Attribute points [8] Skill

宇宙飛行生物学 (Bioastronautics( 宇宙飛行生物学 (Bioastronautics) の大学院教育への利用. Astrobiology)? 宇宙生物学 (Astrobiology( 宇宙生物学 カリキュラム詳細

User guide Air USB. For other languages visit:

artist Chim Pom Chim Pom (Ryuta Ushiro, Ellie)

GLXD4 WARNING. Note: Australia Warning for Wireless. Wireless Receivers. Caution: risk of electric shock. Caution: risk of danger (See note.

Transcription:

Ansible 紹介 2016.3.1 R&Dセンター OSS 戦略企画室 OSS 技術第二課角馬文彦 本文中の会社名 商品名は 各社の商標及び登録商標です

概要 Ansible について いわゆる構成管理ツール リモートホストに対して特定の言語で指定されたタスクを実行する 同様のツールとしてはchef, puppetなどが有名 システムの構成管理 アプリケーションの展開 実行 マルチノードオーケストレーション

特徴 Python ベース エージェントレス リモートホストには標準では python 以外の環境は必要ない モジュールの作成は Python 以外でも可能 ( 特定の条件を満たす言語 ) 作業はシーケンシャルに実行 ライセンス GPL version 3

コード 最新バージョン2.0(Over the Hills and Far Away) 現在も開発継続中ひとつ前 1.9.4(Dancing In the Streets) https://pypi.python.org/pypi/ansible 2.0のものはpypiから取得できる https://github.com/ansible/ansible 開発リポジトリ http://releases.ansible.com/ansible/ リリースターボール

動作確認環境 Ubuntu 14.04 サーバ クライアントホスト Python 2.7 ubuntu ansible パッケージ使用 ansible パッケージ詳細次ページ

apt show ansible Package: ansible Priority: optional Section: universe/admin Installed-Size: 2,758 kb Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Janos Guljas <janos@debian.org> Version: 1.5.4+dfsg-1 Depends: python (>= 2.7), python (<< 2.8), python:any(>= 2.7.1-0ubuntu2), python-crypto, python-yaml, openssh-client python-paramiko, python-jinja2, python-httplib2 Suggests: ansible-doc, sshpass Download-Size: 418 kb Homepage: http://ansible.com Bugs: https://bugs.launchpad.net/ubuntu/+filebug Origin: Ubuntu APT-Manual-Installed: yes APT-Sources: http://us.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages Description: Configuration management, deployment, and task execution system Ansible is a radically simple model-driven configuration management, multi-node deployment, and remote task execution system. Ansible works over SSH and does not require any software or daemons to be installed on remote nodes. Extension modules can be written in any language and are transferred to managed machines automatically. N: There is 1 additional record. Please use the '-a' switch to see it

ssh 環境は必須 処理の実行には ssh を利用 これが ansible がエージェントレスである理由 その為 ssh 環境は必須 リモートホストには ssh でログインできるように設定 予めパブリックキーを置いておく パスフレーズの入力待ちが起こらないように設定 ssh-agent などで回避

リモートホストは inventory ファイルで指定する 書式は下記 host-name1 host-ip [host-group1] host-name2 [host-group2] host-name3 inventory ファイル 詳細は下記参照 http://docs.ansible.com/ansible/intro_inventory.html

ホストの指定 リモートホストは下記の方法で指定可能 /etc/ansible/hosts 環境変数 ANSIBLE_HOSTS=file-path オプションコマンドのオプションで指定 ansible-i file-path ~ ansible-playbook-i file-path ~

ホストの指定例 cat./hosts test-misc1 [testserver1] tnet-misc2 tnet-misc3 [testserver2] tnet-misc2 172.17.61.11 ansible -i hosts test-misc1 --list-hosts test-misc1 ansible -i hosts testserver1 --list-hosts tnet-misc2 tnet-misc3 ansible -i hosts testserver2 --list-hosts tnet-misc2 172.17.61.11

動作確認用のホスト構成 以降の確認環境では下記の inventory ファイルを利用するものとする cat /etc/ansible/hosts tnet-misc2 [testserver1] tnet-misc3 [testserver2] tnet-misc3 tnet-misc4

Adhoc な実行 下記の書式で直接コマンドラインで実行 ansible host-name m module-name[-a options] ping モジュールを使った例を示す ansible testserver2 -m ping tnet-misc4 success >> { "changed": false, "ping": "pong" } tnet-misc3 success >> { "changed": false, "ping": "pong" }

ansible all -m ping tnet-misc2 success >> { "changed": false, "ping": "pong" } tnet-misc3 success >> { "changed": false, "ping": "pong" } tnet-misc4 success >> { "changed": false, "ping": "pong" } ping モジュールは ping コマンドでは無い (ICMP を送信したりはしない )

任意のコマンドの実行 下記の書式で任意のコマンドを実行可能 ansible host-name-a command-line uname コマンドを使った例を示す ansible testserver2 -a 'uname -a' tnet-misc3 success rc=0 >> Linux tnet-misc3 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux tnet-misc4 success rc=0 >> Linux tnet-misc4 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

PlayBooks PlayBooks 処理を ansible に指示する為の言語 PlayBook PlayBooks 言語で書かれたファイル 形式 PlayBooks はYAML フォーマットで表現 PlayBookの実行 ansible-playbook playbook-file-name[options]

PlayBook の書式 playbook の基本フォーマットを示す - hosts: host-name remote_user: user-name tasks: - name: task-name module-name: module-options 以降では playbook の良く使いそうな機能の例を示す

モジュールの実行 cat test-ping.yml - hosts: tnet-misc2 user: ubuntu tasks: -name: check host ping: ansible-playbook test-ping.yml PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [check host] ************************************************************ ok: [tnet-misc2] PLAY RECAP ******************************************************************** tnet-misc2 : ok=2 changed=0 unreachable=0 failed=0

任意のコマンドの実行 cat test-uname-cmd.yml - hosts: tnet-misc2 user: ubuntu tasks: - name: display results of uname command: uname-a ansible-playbook test-uname-cmd.yml PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [display results of uname] ********************************************** changed: [tnet-misc2] PLAY RECAP ******************************************************************** tnet-misc2 : ok=2 changed=1 unreachable=0 failed=0

実行結果の表示 1(--verbose オプション ) ansible-playbook test-uname-cmd.yml--verbose PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [display results of uname] ********************************************** changed: [tnet-misc2] => {"changed": true, "cmd": ["uname", "-a"], "delta": "0:00:00.001116", "end": "2016-02-12 04:53:42.664070", "rc": 0, "start": "2016-02-12 04:53:42.662954", "stderr": "", "stdout": "Linux tnet-misc2 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux"} PLAY RECAP ******************************************************************** tnet-misc2 : ok=2 changed=1 unreachable=0 failed=0

実行結果の表示 2(debug モジュール ) cat test-uname-dbg.yml - hosts: tnet-misc2 user: ubuntu tasks: - name: display results of uname command: uname -a register: uname_res - debug: var=uname_res.stdout_lines

ansible-playbook test-uname-dbg.yml PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [display results of uname] ********************************************** changed: [tnet-misc2] TASK: [debug var=uname_res.stdout_lines] ************************************** ok: [tnet-misc2] => { "uname_res.stdout_lines": [ "Linux tnet-misc2 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux" ] } PLAY RECAP ******************************************************************** tnet-misc2 : ok=3 changed=1 unreachable=0 failed=0

プロンプト cat test-prompt.yaml - user: ubuntu hosts: tnet-misc2 vars: file_path: /home/ubuntu/config vars_prompt: - name: "inputdata" prompt: "Please enter data" private: no 1) default: "test data" tasks: - lineinfile: dest={{ file_path }} create=yes line="{{ inputdata }}" - command: cat {{ file_path }} register: cat_results - debug: var=cat_results.stdout_lines 1) yes の場合 入力値のエコーバックを行わない

ansible-playbook test-prompt.yaml Please enter data [test data]: 192.168.1.1 host PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [lineinfile dest=/home/ubuntu/config create=yes line="192.168.1.1 host"] *** changed: [tnet-misc2] TASK: [command cat /home/ubuntu/config] *************************************** changed: [tnet-misc2] TASK: [debug var=cat_results.stdout_lines] ************************************ ok: [tnet-misc2] => { "cat_results.stdout_lines": [ "192.168.1.1 host" ] } PLAY RECAP ******************************************************************** tnet-misc2 : ok=4 changed=2 unreachable=0 failed=0

タスクの実行エラー 下記の playbook を使用した時のエラー例を示す cat test-lynx-list.yml - hosts: testserver2 user: ubuntu sudo: yes tasks: - name: list lynx command: dpkg -l lynx

ホスト shutdown 中 ansible-playbook test-lynx-list.yml PLAY [testserver2] ************************************************************ GATHERING FACTS *************************************************************** fatal: [tnet-misc4] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue fatal: [tnet-misc3] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue TASK: [list lynx] ************************************************************* FATAL: no hosts matched or all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/home/ubuntu/test-lynx-list.retry tnet-misc3 : ok=0 changed=0 unreachable=1 failed=0 tnet-misc4 : ok=0 changed=0 unreachable=1 failed=0 cat /home/ubuntu/test-lynx-list.retry tnet-misc3 tnet-misc4

コマンド実行エラー ansible-playbook test-lynx-list.yml PLAY [testserver2] ************************************************************ GATHERING FACTS *************************************************************** ok: [tnet-misc4] ok: [tnet-misc3] TASK: [list lynx] ************************************************************* changed: [tnet-misc3] failed: [tnet-misc4] => {"changed": true, "cmd": ["dpkg", "-l", "lynx"], "delta": "0:00:00.008187", "end": "2016-02-17 02:54:18.511604", "rc": 1, "start": "2016-02-17 02:54:18.503417"} stderr: dpkg-query: no packages found matching lynx PLAY RECAP ******************************************************************** to retry, use: --limit @/home/ubuntu/test-lynx-list.retry tnet-misc3 : ok=2 changed=1 unreachable=0 failed=0 tnet-misc4 : ok=1 changed=0 unreachable=0 failed=1 cat /home/ubuntu/test-lynx-list.retry tnet-misc4

複数タスクの処理 cat test-ovs-install.yml - hosts: tnet-misc2 user: ubuntu sudo: yes tasks: - name: install ovs apt: name=openvswitch-switch state=latest - name: create bridge command: ovs-vsctl--may-exist add-br br-test - name: check bridge command: ovs-vsctl show register: ovs_results - debug: var=ovs_results.stdout_lines # output result of ovs-vsctl

ansible-playbook test-ovs-install.yml PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [install ovs] *********************************************************** changed: [tnet-misc2] TASK: [create bridge] ********************************************************* changed: [tnet-misc2] TASK: [check bridge] ********************************************************** changed: [tnet-misc2]

TASK: [debug var=ovs_results.stdout_lines] ************************************ ok: [tnet-misc2] => { "ovs_results.stdout_lines": [ "132fbd78-de70-422e-93a4-c3d2b7ffd6cf", " Bridge br-test", " Port br-test", " Interface br-test", " type: internal", " ovs_version: "2.0.2 "" ] } PLAY RECAP ******************************************************************** tnet-misc2 : ok=5 changed=3 unreachable=0 failed=0

playbook の流用 include 文を使い ある playbook に他の playbook をインポートする事ができる 前述の playbook をインポートした例を示す cat test-main.yml - include: test-ping.yml - include: test-uname-cmd.yml include は playbook のインポートだけでなく tasks 文で指定して task を取り込むこともできる

ansible-playbook test-main.yml PLAY [testserver2] ************************************************************ GATHERING FACTS *************************************************************** ok: [tnet-misc3] ok: [tnet-misc4] TASK: [check host] ************************************************************ ok: [tnet-misc3] ok: [tnet-misc4] PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2] TASK: [display results of uname] ********************************************** changed: [tnet-misc2] PLAY RECAP ******************************************************************** tnet-misc2 : ok=2 changed=1 unreachable=0 failed=0 tnet-misc3 : ok=2 changed=0 unreachable=0 failed=0 tnet-misc4 : ok=2 changed=0 unreachable=0 failed=0

もう少し複雑な例下記の処理を実行 apache, lynx がインストールされていなければインストール lynx で apache のデフォルトページを表示 ( バリエーションの為 tnet-misc2 には予め lynx をインストールする ) cat test-apache-install.yml - hosts: all user: ubuntu sudo: yes tasks: - name: update package index apt: update_cache=yes - hosts: tnet-misc2 user: ubuntu sudo: yes tasks:

- name: check if apache2 exists command: dpkg -l apache2 ignore_errors: True 1) register: dpkg_results 2) - name: install apache when: dpkg_results failed 3) apt: name=apache2 state=latest notify: 4) - take interval handlers: 5) - name: take interval pause: seconds=3 - hosts: all user: ubuntu sudo: yes tasks: - name: check if lynx exists command: dpkg -l lynx ignore_errors: True register: dpkg_results - name: install lynx when: dpkg_results failed apt: name=lynx state=latest

- hosts: testserver2 user: ubuntu sudo: yes tasks: - name: diaplay apache init page command: lynx -dump http://tnet-misc2 ignore_errors: True register: lynx_results - debug: var=lynx_results.stdout_lines# output dump data of lynx - hosts: all user: ubuntu sudo: yes tasks: - name: verify packages after install command: dpkg -l apache2 lynx ignore_errors: True register: dpkg_results - debug: var=dpkg_results.stdout_lines # check if apache2 and lynx are installed

1) 実行結果を無視 2) 実行結果を指定の変数に格納 3) 条件判定 4) ハンドラ定義 5) ハンドラの指定

ansible tnet-misc2 --sudo-m apt -a 'name=lynx state=latest' tnet-misc2 success >> { "changed": true, "stderr": "", "stdout": "Reading package lists... nbuildingdependency tree... nreadingstate information... nthe following extra packages will be installed: n lynx-cur nthe following NEW packages will be installed: n lynx lynx-cur n0 upgraded, 2 newly installed, 0 to remove and 151 not upgraded. nneedto get 960 kb of archives. nafter this operation, 2570 kb of additional disk space will be used. nget:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main lynx-cur amd64 2.8.8pre4-1 [956 kb] nget:2 http://us.archive.ubuntu.com/ubuntu/ trusty/main lynx all 2.8.8pre4-1 [4184 B] nfetched 960 kb in 1s (689 kb/s) nselecting previously unselected package lynxcur. n(reading database... 61559 files and directories currently installed.) npreparingto unpack.../lynx-cur_2.8.8pre4-1_amd64.deb... nunpacking lynx-cur (2.8.8pre4-1)... nselectingpreviously unselected package lynx. npreparingto unpack.../lynx_2.8.8pre4-1_all.deb... nunpacking lynx (2.8.8pre4-1)... nprocessing triggers for mime-support (3.54ubuntu1.1)... nprocessing triggers for man-db(2.6.7.1-1ubuntu1)... nsetting up lynx-cur (2.8.8pre4-1)... nupdate-alternatives: using /usr/bin/lynx to provide /usr/bin/www-browser (www-browser) in auto mode nsetting up lynx (2.8.8pre4-1)... n" }

ansible-playbook test-apache-install.yml PLAY [all] ******************************************************************** GATHERING FACTS *************************************************************** ok: [tnet-misc2] ok: [tnet-misc3] ok: [tnet-misc4] TASK: [update package index] ************************************************** ok: [tnet-misc3] ok: [tnet-misc2] ok: [tnet-misc4] PLAY [tnet-misc2] ************************************************************* GATHERING FACTS *************************************************************** ok: [tnet-misc2]

TASK: [check if apache2 exists] *********************************************** failed: [tnet-misc2] => {"changed": true, "cmd": ["dpkg", "-l", "apache2"], "delta": "0:00:00.007453", "end": "2016-02-14 03:28:59.179386", "rc": 1, "start": "2016-02-14 03:28:59.171933"} stderr: dpkg-query: no packages found matching apache2...ignoring TASK: [install apache] ******************************************************** changed: [tnet-misc2] NOTIFIED: [take interval] ***************************************************** (^C-c = continue early, ^C-a = abort) [tnet-misc2] Pausing for 3 seconds ok: [tnet-misc2] PLAY [all] ******************************************************************** GATHERING FACTS *************************************************************** ok: [tnet-misc4] ok: [tnet-misc3] ok: [tnet-misc2]

TASK: [check if lynx exists] ************************************************** failed: [tnet-misc4] => {"changed": true, "cmd": ["dpkg", "-l", "lynx"], "delta": "0:00:00.008070", "end": "2016-02-14 03:29:27.453067", "rc": 1, "start": "2016-02-14 03:29:27.444997"} stderr: dpkg-query: no packages found matching lynx...ignoring failed: [tnet-misc3] => {"changed": true, "cmd": ["dpkg", "-l", "lynx"], "delta": "0:00:00.008109", "end": "2016-02-14 03:29:27.450850", "rc": 1, "start": "2016-02-14 03:29:27.442741"} stderr: dpkg-query: no packages found matching lynx...ignoring changed: [tnet-misc2] TASK: [install lynx] ********************************************************** skipping: [tnet-misc2] --> 処理のスキップ changed: [tnet-misc4] changed: [tnet-misc3] PLAY [testserver2] ************************************************************ GATHERING FACTS *************************************************************** ok: [tnet-misc4] ok: [tnet-misc3]

TASK: [diaplayapache init page] ********************************************** changed: [tnet-misc4] changed: [tnet-misc3] TASK: [debug var=lynx_results.stdout_lines] *********************************** ok: [tnet-misc3] => { "lynx_results.stdout_lines": [ " Ubuntu Logo Apache2 Ubuntu Default Page", " It works!", "", " This is the default welcome page used to test the correct operation of", " the Apache2 server after installation on Ubuntu systems. It is based on", " the equivalent page on Debian, from which the Ubuntu Apache packaging", 途中省略 ] } ok: [tnet-misc4] => { "lynx_results.stdout_lines": [ " Ubuntu Logo Apache2 Ubuntu Default Page", 途中省略 " 10. http://validator.w3.org/check?uri=referer" ] }

PLAY [all] ******************************************************************** GATHERING FACTS *************************************************************** ok: [tnet-misc2] ok: [tnet-misc4] ok: [tnet-misc3] TASK: [verify packages after install] ***************************************** failed: [tnet-misc3] => {"changed": true,... 途中省略 failed: [tnet-misc4] => {"changed": true,... 途中省略 changed: [tnet-misc2] TASK: [debug var=dpkg_results.stdout_lines] *********************************** ok: [tnet-misc2] => { "dpkg_results.stdout_lines": [ "Desired=Unknown/Install/Remove/Purge/Hold", " Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend", " / Err?=(none)/Reinst-required (Status,Err: uppercase=bad)", " / Name Version Architecture Description", +++-===================================-...==", "ii apache2 2.4.7-1ubuntu4.9 amd64 Apache HTTP Server", "ii lynx 2.8.8pre4-1 all Text-mode WWW Browser (transitional package)"

] } ok: [tnet-misc3] => { "dpkg_results.stdout_lines": [ "Desired=Unknown/Install/Remove/Purge/Hold", " Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend", " / Err?=(none)/Reinst-required (Status,Err: uppercase=bad)", " / Name Version Architecture Description", +++-===================================-...==", "ii lynx 2.8.8pre4-1 all Text-mode WWW Browser (transitional package)" ] } ok: [tnet-misc4] => { 途中省略 } PLAY RECAP ******************************************************************** tnet-misc2 : ok=11 changed=4 unreachable=0 failed=0 tnet-misc3 : ok=11 changed=4 unreachable=0 failed=0 tnet-misc4 : ok=11 changed=4 unreachable=0 failed=0

参考資料 http://docs.ansible.com/ http://docs.ansible.com/intro_getting_started.html http://docs.ansible.com/ansible/modules.html http://docs.ansible.com/ansible/modules_by_category.html https://github.com/ansible/ansible-examples