Más contenido relacionado La actualidad más candente (20) Similar a Ansible quickstart (20) Ansible quickstart3. 自己紹介
‣
氏名: 齊藤 秀喜(さいとう ひでき)
-
‣
Twitter: @saito_hideki
Blog: http://d.hatena.ne.jp/pyde/
勤務先: 株式会社インターネットイニシアティブ(IIJ)
-
http://www.iij.ad.jp/
‣
所属: 日本OpenStackユーザ会 ボードメンバー
‣
趣味: Python/OpenStack /Ansible
‣
仕事: クラウド基盤のちょっとした開発やちょっとした運用
-
http://www.iij.ad.jp/GIO/
3
6. Ansibleとは?
‣ 何をするものなのか?
- Pythonで書かれた*個々の作業*だけなく*まとまった仕事*の単位で自動
化を行うツール
- OS・ミドルウェア・アプリケーションのインストール・設定などの一連の作業を
Playbookとして1つにまとめてワンアクションで実行させることが可能
- 多数の外部モジュールが標準・オプションで提供されている
- 適用した作業に対する冪等性が担保されている(担保されていないモジュー
ルもある)
- push型でエージェントレス。操作対象ノードにSSHでログインできれば最低
限ど動作するため導入の敷居が低い
‣ 入手先は?
- 公式サイト: http://www.ansibleworks.com/
- ソースコード: https://github.com/ansible/ansible
- githubのtagによるとv0.01のリリースは2009年
- 現時点(2013-12)で最新の安定版はv1.4.1
6
11. 導入から稼働まで(ubuntu12.04lts編�[2])
!
3. githubからansibleを取得してインストール
- v1.3.4をcheckoutする
- この例ではモジュールはapp/share/ansible/にインストールされる
(app)
(app)
(app)
(app)
(app)
(app)
$ mkdir src && cd src
$ git clone https://github.com/ansible/ansible.git
$ cd ansible
$ git checkout -b v1.3.4 v1.3.4
Switched to a new branch 'v1.3.4’
$ python setup.py build
<pythonのvirtualenv環境>
modules
modules(A)
modules(B)
python
python-virtualenv(A)
~/app/
python-virtualenv(B)
~/hogehoge/
!
OS
virtualenvの外側に影響を与えない
11
18. Ansibleの外部モジュールの使い方
‣
ansible-docコマンドでモジュールのオプションを確認する
[書式] ansible-doc <モジュール名>
(app) $ ansible-doc file
> FILE
!
!
Sets attributes of files, symlinks, and directories, or removes
files/symlinks/directories. Many other modules support the same
options as the [file] module - including [copy], [template], and
[assemble].
Options (= is mandatory):
!
- force
force the creation of the symlinks in two cases: the source
file does not exist (but will appear later); the destination
exists and a file (so, we need to unlink the "path" file and
create symlink to the "src" file in place of it). (Choices:
yes, no)
<…>
Notes:
!
See also [copy], [template], [assemble]
- file: path=/etc/foo.conf owner=foo group=foo mode=0644
- file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
18
19. モジュールを使ってみる
‣
serviceモジュールでターゲットホストのhttpdをリスタートしてみる
(app) $ ansible -i hosts all -u foo -k -K -m service -a "name=httpd state=restarted"
SSH password: ********
sudo password [defaults to SSH password]: ********
172.16.0.1 | success >> {
"changed": true,
"name": "httpd",
"state": "started"
}
!
!
!
!
‣
yumモジュールを使ってlibselinux-pythonパッケージをインストールしてみる
(app) $ ansible -i hosts all -u foo -k -K -m yum -a "name=libselinux-python state=present"
SSH password: ********
sudo password [defaults to SSH password]: ********
172.16.0.1 | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror, prioritiesnLoading mirror speeds from cached hostfilen * base:
ftp.jaist.ac.jpn * epel: ftp.kddilabs.jpn * extras: ftp.jaist.ac.jpn * updates: ftp.jaist.ac.jpn183 packages
excluded due to repository priority protectionsnSetting up Install ProcessnResolving Dependenciesn--> Running
transaction checkn---> Package libselinux-python.x86_64 0:2.0.94-5.3.el6_4.1 will be installedn--> Finished
Dependency ResolutionnnDependencies Resolvedn
n================================================================================n Package
Arch
Version
Repository
Size
n================================================================================nInstalling:n libselinux-python
x86_64
2.0.94-5.3.el6_4.1
updates
202 knnTransaction Summary
n================================================================================nInstall
1 Package(s)nnTotal
download size: 202 knInstalled size: 653 knDownloading Packages:nRunning rpm_check_debugnRunning Transaction Test
nTransaction Test SucceedednRunning Transactionnr Installing : libselinux-python-2.0.94-5.3.el6_4.1.x86_64
1/1 nr Verifying : libselinux-python-2.0.94-5.3.el6_4.1.x86_64
1/1 nnInstalled:n libselinuxpython.x86_64 0:2.0.94-5.3.el6_4.1
nnComplete!n"
]
}
19
22. AnsibleのPlaybookで仕事をさせてみる(3)
ブログサーバを構築して提供するPlaybookを実行してみる
$ ansible-playbook -u root -k -i hosts site.yml
SSH password: ********
!
!
PLAY [Install Wordpress, MySQL, Nginx, and PHP-FPM] ***************************
GATHERING FACTS ***************************************************************
ok: [192.168.100.110]
[省略]
TASK: [Install Mysql package] *************************************************
changed: [192.168.100.110] => (item=mysql-server,MySQL-python,libselinux-python,libsemanage-python)
!
TASK: [Create Mysql configuration file] ***************************************
changed: [192.168.100.110]
[省略]
PLAY RECAP ********************************************************************
192.168.100.110
: ok=25
changed=24
unreachable=0
failed=0
22