このエントリーをはてなブックマークに追加

Alnair

概要

Alnairは、シンプルなシステム構成フレームワークでFabricなどと組み合わせて利用することが出来るみたいです。
PuppetやChefなどを使う場合はクライアントにインストールが必要になりますがAlnairは必要ありません。
GitHub Alnair <https://github.com/naoina/alnair> で開発されています。

インストール

$ sudo apt-get install build-essential pypy-dev python-crypto python-pip -y
$ pip install alnair

テンプレート作成

$ alnair generate template centos
creating directory: ./recipes/centos
creating file: ./recipes/centos/common.py

パッケージインストールコマンドの設定

$ vi recipes/centos/common.py
install_command = 'yum install --enablerepo=epel -y'

レシピの作成

$ alnair generate recipe tmux
creating file: recipes/centos/tmux.py

セットアップ

$ alnair setup centos tmux
root@stack01:~# alnair setup centos tmux
No hosts found. Please specify (single) host string for connection: 192.168.10.5
[192.168.10.5] sudo: yum install --enablerepo=epel -y tmux
[192.168.10.5] Login password for 'root':
[192.168.10.5] out: Loaded plugins: fastestmirror, priorities, refresh-packagekit, security
[192.168.10.5] out: Loading mirror speeds from cached hostfile
[192.168.10.5] out:  * epel: ftp.jaist.ac.jp
[192.168.10.5] out:  * sl: ftp.scientificlinux.org
[192.168.10.5] out:  * sl-security: ftp.scientificlinux.org
[192.168.10.5] out: 185 packages excluded due to repository priority protections
[192.168.10.5] out: Setting up Install Process
[192.168.10.5] out: Resolving Dependencies
[192.168.10.5] out: --> Running transaction check
[192.168.10.5] out: ---> Package tmux.x86_64 0:1.5-1.el6 will be installed
[192.168.10.5] out: --> Finished Dependency Resolution

[192.168.10.5] out: Dependencies Resolved

[192.168.10.5] out: ===================================================================================================
[192.168.10.5] out:  Package              Arch                   Version                    Repository            Size
[192.168.10.5] out: ===================================================================================================
[192.168.10.5] out: Installing:
[192.168.10.5] out:  tmux                 x86_64                 1.5-1.el6                  epel                 201 k

[192.168.10.5] out: Transaction Summary
[192.168.10.5] out: ===================================================================================================
[192.168.10.5] out: Install       1 Package(s)

[192.168.10.5] out: Total download size: 201 k
[192.168.10.5] out: Installed size: 473 k
[192.168.10.5] out: Downloading Packages:
[192.168.10.5] out: tmux-1.5-1.el6.x86_64.rpm                                                   | 201 kB     00:00
[192.168.10.5] out: Running rpm_check_debug
[192.168.10.5] out: Running Transaction Test
[192.168.10.5] out: Transaction Test Succeeded
[192.168.10.5] out: Running Transaction
[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#######                                  [192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [##############                           [192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [######################                   [192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#############################            [192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [####################################     [192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#######################################  [192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#########################################[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#########################################[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#########################################[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#########################################[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#########################################[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64 [#########################################[192.168.10.5] out:   Installing : tmux-1.5-1.el6.x86_64                                                           1/1
[192.168.10.5] out:   Verifying  : tmux-1.5-1.el6.x86_64                                                           1/1

[192.168.10.5] out: Installed:
[192.168.10.5] out:   tmux.x86_64 0:1.5-1.el6

[192.168.10.5] out: Complete!

ライブラリとしての利用

以下のようなコードをスクリプトから呼べばいいみたいです。

from alnair import Distribution

distname = 'centos'
with Distribution(distname) as dist:
   dist.setup('tmux')

設定ファイルのデプロイ

$ vi recipes/centos/nova.py
from alnair import Package

nova = Package()

nova.setup.config('/tmp/nova.conf').contents("""\
[DEFAULT]

# LOGS/STATE
verbose=True

# AUTHENTICATION
auth_strategy=keystone
""")

$ alnair config centos nova
[192.168.10.5] Login password for 'root':
[192.168.10.5] put: <file obj> -> /tmp/nova.conf

設定ファイルのライブラリとしての利用

from alnair import Distribution

distname = "centos"
with Distribution(distname) as dist:
   dist.config('nova')

セットアップ後にコマンドを実行

セットアップ後のコマンド単体実行というコマンドはまだ無いみたいです。

$ alnair generate recipe ntp
creating file: recipes/centos/ntp.py
$ vi recipes/centos/ntp.py
$ alnair setup centos ntp
No hosts found. Please specify (single) host string for connection: 192.168.10.5
[192.168.10.5] sudo: yum install --enablerepo=epel -y ntp
[192.168.10.5] Login password for 'root':
[192.168.10.5] out: Loaded plugins: fastestmirror, priorities, refresh-packagekit, security
[192.168.10.5] out: Loading mirror speeds from cached hostfile
[192.168.10.5] out:  * epel: ftp.jaist.ac.jp
[192.168.10.5] out:  * sl: ftp.scientificlinux.org
[192.168.10.5] out:  * sl-security: ftp.scientificlinux.org
[192.168.10.5] out: 185 packages excluded due to repository priority protections
[192.168.10.5] out: Setting up Install Process
[192.168.10.5] out: Package ntp-4.2.4p8-2.el6.x86_64 already installed and latest version
[192.168.10.5] out: Nothing to do

[192.168.10.5] sudo: service ntpd restart
[192.168.10.5] out: ntpd を停止中:                         [  OK  ]
[192.168.10.5] out: ntpd を起動中:                         [  OK  ]

セットアップ後のコマンドをライブラリとして利用

from alnair import Distribution

distname 'centos'
with Distribution(distname) as dist:
   dist.setup('ntp')