ansibleを使ってみた
なんでansibleかというと
従来の物と比べる時にエージェントが要らないという
考えてみれば色々入れるからこそ構成ツールなのにまず入れろってのは無いよな
まずはインストール
pythonのeasy_installとかpipとかvirtual_envとかって考えてたら
当たり前のようにbrewにてパッケージ管理されてました。
$ brew info ansible ansible: stable 1.6.2, HEAD http://www.ansible.com/home /usr/local/Cellar/ansible/1.6.2 (867 files, 9.9M) * Built from source From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/ansible.rb ==> Dependencies Required: libyaml ✔ ==> Options --with-accelerate Enable accelerated mode --HEAD install HEAD version ==> Caveats If you need Python to find the installed site-packages: mkdir -p ~/Library/Python/2.7/lib/python/site-packages echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
さくさくインストールしてみます。
$ brew install ansible ==> Installing ansible dependency: libyaml ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libyaml-0.1.6.mavericks.bottle.tar.gz ######################################################################## 100.0% ==> Pouring libyaml-0.1.6.mavericks.bottle.tar.gz /usr/local/Cellar/libyaml/0.1.6: 7 files, 348K ==> Installing ansible ==> Downloading http://releases.ansible.com/ansible/ansible-1.6.2.tar.gz ######################################################################## 100.0% ==> Downloading https://pypi.python.org/packages/source/p/pycrypto/ pycrypto-2.6.tar.gz ######################################################################## 100.0% ==> python setup.py install --prefix=/usr/local/Cellar/ansible/1.6.2/libexec ==> Downloading https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.10.tar.gz ######################################################################## 100.0% ==> python setup.py install --prefix=/usr/local/Cellar/ansible/1.6.2/libexec ==> Downloading https://pypi.python.org/packages/source/p/paramiko/paramiko-1.11.0.tar.gz ######################################################################## 100.0% ==> python setup.py install --prefix=/usr/local/Cellar/ansible/1.6.2/libexec ==> Downloading https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.18.tar.gz ######################################################################## 100.0% ==> python setup.py install --prefix=/usr/local/Cellar/ansible/1.6.2/libexec ==> Downloading https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz ######################################################################## 100.0% ==> python setup.py install --prefix=/usr/local/Cellar/ansible/1.6.2/libexec ==> python setup.py install --prefix=/usr/local/Cellar/ansible/1.6.2 ==> Caveats If you need Python to find the installed site-packages: mkdir -p ~/Library/Python/2.7/lib/python/site-packages echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth ==> Summary /usr/local/Cellar/ansible/1.6.2: 867 files, 9.9M, built in 30 seconds
さくさくインストール出来ました。
これで、ちゃんとコマンドラインが通るようになりました。
$ ansible --version ansible 1.6.2
brewだと/usr/local/Cellar/ansible/1.6.2以下にインストールされているので確認
configの設定
ansibleの公式サイトのconfigに関するThe Ansible Configuration Fileを見ると以下のようにある
Certain settings in Ansible are adjustable via a configuration file. The stock configuration should be sufficient for most users, but there may be reasons you would want to change them.}
Changes can be made and used in a configuration file which will be processed in the following order:
- ANSIBLE_CONFIG (an environment variable)
- ansible.cfg (in the current directory)
- .ansible.cfg (in the home directory)
- /etc/ansible/ansible.cfg
どうやらANSIBLE_CONFIGから順に設定ファイルを見に行くようにできているらしい
ここは取り敢えず/etc/andible以下に最新版のconfigファイルを配置します
$ sudo mkdir /etc/ansible $ cd /etc/ansible $ sudo wget https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg Password: --2014-06-04 11:34:25-- https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg Resolving raw.githubusercontent.com... 103.245.222.133 Connecting to raw.githubusercontent.com|103.245.222.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 7172 (7.0K) Saving to: 'ansible.cfg' 100%[===============================================================================================================================>] 7,172 --.-K/s in 0s 2014-06-04 11:34:26 (60.0 MB/s) - 'ansible.cfg' saved [7172/7172]
少し中身を見てみます。
# config file for ansible -- http://ansible.com/ # ============================================== # nearly all parameters can be overridden in ansible-playbook # or with command line flags. ansible will read ANSIBLE_CONFIG, # ansible.cfg in the current working directory, .ansible.cfg in # the home directory or /etc/ansible/ansible.cfg, whichever it # finds first [defaults] # some basic default values... hostfile = /etc/ansible/hosts library = /usr/share/ansible remote_tmp = $HOME/.ansible/tmp pattern = * forks = 5 poll_interval = 15 sudo_user = root #ask_sudo_pass = True #ask_pass = True transport = smart remote_port = 22 module_lang = C : : :
元記事は、こちら