Upload
naoya-hashimoto
View
964
Download
0
Embed Size (px)
Citation preview
1
Container-SIG#1 10/7/2016
Naoya Hashimoto
Ansible Container
Table of contents
• What is Ansible Container?• Why Ansible Container Project begins?• How to use ansible-container? • Ansible Container Demonstration
2
Ansible Container?
3
ansible-container
shipit
push
buildrun
build, run, push and shipitinit
docker-compose?
5
Feature
• Docker Imageのビルドは Dockerfileから Playbookへ• Playbook=Ansible Moduleでビルド /デプロイ• Playbookは YAML形式、 docker-composeユーザに優しい
6
ansible-container init (ver 0.1)
7
$ ansible-container init$ tree ansibleansible/├── container.yml├── main.yml└── requirements.txt
ansible-container init
8
container.yml• Dockerfileや docker-compose.ymlに相当• Imageやバージョン、マップするポート、環境変数などを定義main.yml• Master Playbook (site.yml)に相当• イメージをビルドする際に実行する Ansibleの Roleや Taskを定義• container.ymlが自動で生成したインベントリを参照requirements.txt• イメージをビルドする際に必要な Pythonライブラリを定義• pipのフォーマットに準拠
ansible-container init (ver 0.2)
9
$ ansible-container init$ tree ansibleansible/├── ansible.cfg├── container.yml├── main.yml├── meta.yml├── requirements.txt└── requirements.yml
Why Ansible Container Project
begins?
10
Ansible Container Project“5 REASONS WE STARTED THE ANSIBLE CONTAINER PROJECT”https://www.ansible.com/blog/ansible-container-project
1. Because our community has been using Ansible to manage containers for quite a while now.
2. Because the new Docker connection plug-in makes it far simpler to run Ansible against a Docker container.
3. Because shell scripts aren’t good enough.4. Because Ansible can be a great bridge to larger-scale
container orchestration.5. Because we believe that communities make the best
software.
11
Ansible Community & DockerDocker Containerを Playbookで管理• Docker Hubに公開しているAnsibleのイメージは約1,000件に• メンバーが様々なDocker ContainerのベストプラクティスをBlogに公開
• 集約されたナレッジをツールとして開発する流れに
Docker Moduleや機能を拡張• Docker ModuleがAnsible Moduleの中で最も利用される• Connection PluginにDocker Connection Pluginをリリース• 初期のDocker ModuleはDeprecated
https://docs.ansible.com/ansible/guide_docker.html• 2.2から docker_containerや docker_imageに置き換え
https://github.com/ansible/ansible-modules-core/blob/devel/cloud/docker/_docker.py
12
Ansible Docker Modules & Plugins
13
Version
Module/Plugin Feature
1.4(2013)
docker (Deprecated)
Docker Moduleのオリジナルdocker build, load, pull, push, tagなどに相当
1.6 Dynamic Inventory Docker Containerの Inventoryを動的に生成2.0 Docker Connection Docker Containerに sshを利用せずに接続2.0 docker_login docker login に相当2.1 docker_service docker-composeに相当 , version 1, 2に対応2.1 docker_container Docker Containerをデプロイ2.1 docker_image_facts Docker Hostでキャッシュした Dockerイメージ
を Inspect, Factsなどに利用2.2(2016)
docker_network docker network に相当
Docker Connection Plugin
14
Ansible 2.1で Docker Connection Pluginをリリース• Connection Driverに Docker Connection Pluginを指定• Playbookの実行に docker execを利用• Playbookは VM, Containerで互換性を保てる ?
2.1
sshdapp app
End the bash madness
15
"Ansible Container represents an end to the command && command && command (and so on) syntax you’ve been struggling with to build containers.”https://www.ansible.com/ansible-container
# grab tini for signal processing and zombie killingENV TINI_VERSION v0.9.0RUN set -x \ && curl -fSL "https://$URI/$TINI_VERSION/tini" -o /usr/local/bin/tini \ && curl -fSL "https://$URI/$TINI_VERSION/tini.asc" -o /usr/local/bin/tini.asc \ && export GNUPGHOME="$(mktemp -d)" \ && gpg --keyserver ha.pool.sks-keyservers.net \ --recv-keys 6380DC428747F6C393FEACA59A84159D7001A4E5 \ && gpg --batch --verify /usr/local/bin/tini.asc /usr/local/bin/tini \ && rm -r "$GNUPGHOME" /usr/local/bin/tini.asc \ && chmod +x /usr/local/bin/tini \ && tini -h
How to use ansible-container?
16
Usage: $ ansible-container --help
17
Command Docker Command Featureinit ansible-garaxy init テンプレートを生成build docker build
docker-compose buildDocker Imageをビルド
run docker rundocker-compose up
Docker Containerを起動push docker push Docker Registryに Image
をプッシュshipit oc new-app
oc runオーケストレーション環境にデプロイe.g. Kubernetes, OpenShift
Ansible Container Examples
18
https://github.com/ansible/ansible-container-examples
Demonstration
19
build & run
20
Prerequisites• Python 2.7 • pip• setuptools 20.0.0+• Docker 1.11 or access to a Docker daemon.
Installation$ sudo pip install ansible-container$ ansible-container version
Build & Run$ git clone https://github.com/ansible/ansible-container-examples.git$ cd ansible-container-examples/ ; cp -r helloworld-nginx/ ansible$ ansible-container build$ ansible-container run –d$ ansible-container stop
Push$ docker login$ ansible-container push
Reference
21
Ansible Containerhttps://github.com/ansible/ansible-containerDocumentationhttps://www.ansible.com/ansible-containeransible-container-exampleshttps://github.com/ansible/ansible-container-examples5 REASONS WE STARTED THE ANSIBLE CONTAINER PROJECThttps://www.ansible.com/blog/ansible-container-project6 WAYS ANSIBLE MAKES DOCKER-COMPOSE BETTERhttps://www.ansible.com/blog/six-ways-ansible-makes-docker-compose-betterANSIBLE AND CONTAINERS: WHY AND HOWhttps://www.ansible.com/blog/ansible-and-containers-why-and-how
Q&A
22