workshops

Training Course for Ansible Automation Platform

This project is maintained by ericzji

演習 2.7 - まとめ

Read this in other languages: uk English, japan 日本語.

最終チャレンジとまとめ

今までに学んだことを踏まえて以下の課題を実施してみましょう。

ステージの設定

今までの演習の延長です。以下の演習にチャレンジしてみましょう。

Git リポジトリ

すべてのコードは Github にあるものを使います。https://github.com/ansible/workshop-examples で Ansible Workshop Examples の gitリポジトリを確認してください。そこに role_webcontent Role を呼び出すプレイブック webcontent.yml があります。

以前の Apache インストールロールと比較すると、大きな違いがあります。index.html テンプレートには2つのバージョンがあり、そのソースファイルの一部には変数入力が存在し、タスクによりこのテンプレートがデプロイされます。

dev_index.html.j2

<body>
<h1>This is a development webserver, have fun!</h1>

</body>

prod_index.html.j2

<body>
<h1>This is a production webserver, take care!</h1>

</body>

main.yml

[...]
- name: Deploy index.html from template
  template:
    src: "_index.html.j2"
    dest: /var/www/html/index.html
  notify: apache-restart

インベントリーを確認する

これを達成する方法は1つだけではありませんが、次のことを行う必要があります。

ヒント

YAML スタートを意味する1行目のハイフンは消さないでください!

テンプレートの作成

結果を確認します

今回は、Ansibleのアドホックコマンドを使って結果を確認します。利用するモジュールは command モジュールで、各ノードの curl 実行結果を確認してみます。

$ ansible web -m command -a "curl -s http://localhost:80"
 [WARNING]: Consider using the get_url or uri module rather than running 'curl'.  If you need to use command because get_url or uri is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.

node2 | CHANGED | rc=0 >>
<body>
<h1>This is a production webserver, take care!</h1>
prod wweb
</body>

node1 | CHANGED | rc=0 >>
<body>
<h1>This is a development webserver, have fun!</h1>
dev wweb
</body>

node3 | CHANGED | rc=0 >>
<body>
<h1>This is a development webserver, have fun!</h1>
dev wweb
</body>

Ansible では、 curl コマンドを command モジュールで実行するよりも優れたモジュールが提供されているため、警告が出ますが、今回は無視して大丈夫です。

Survey の追加

結果を確認しまし。先ほど command モジュールで curl を実行し、警告が表示されたので、今回は専用 uri モジュールを使用します。引数として、実際の URL と結果の本文を出力するフラグが必要です。

$ ansible web -m uri -a "url=http://localhost return_content=yes"
node2 | SUCCESS => {
    "accept_ranges": "bytes",
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "connection": "close",
    "content": "<body>\n<h1>This is a production webserver, take care!</h1>\nprod wweb\n</body>\n",
    "content_length": "77",
    "content_type": "text/html; charset=UTF-8",
    "cookies": {},
    "cookies_string": "",
    "date": "Wed, 10 Jul 2019 22:15:45 GMT",
    "elapsed": 0,
    "etag": "\"4d-58d5aef2a5666\"",
    "last_modified": "Wed, 10 Jul 2019 22:09:42 GMT",
    "msg": "OK (77 bytes)",
    "redirected": false,
    "server": "Apache/2.4.6 (Red Hat Enterprise Linux)",
    "status": 200,
    "url": "http://localhost"
}
[...]

解決方法

解決方法はここでは記載しません

ラボで必要な構成手順はすべて完了しています。不明な場合は、それぞれの章を参照してください。

終わり

おめでとうございます、ラボを終了しました! 我々はこのラボを楽しく開発しました。皆様の Ansible Tower との初めて出会いが、それ以上に楽しいものであったことを願っています!!!


Ansible Tower ワークショップ表紙に戻る