Skip to content

Instantly share code, notes, and snippets.

@eyasuyuki
Created July 29, 2015 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyasuyuki/30b2206592e2724fab88 to your computer and use it in GitHub Desktop.
Save eyasuyuki/30b2206592e2724fab88 to your computer and use it in GitHub Desktop.
Ansibleの紹介

Ansible

タイムインターメディア技術部会資料

Ansibleとは

構成管理ツール。

セットアップスクリプトを記述し、パッケージインストールやデーモンの起動をリモート設定できる。

URL: http://www.ansible.com/

Ansibleの特徴

  • リモート側にAnsibleをインストールする必要がない
  • スクリプトは記述した順番に実行される
  • YAMLによるシンプルな文法
  • 各種のモジュールが利用できる。ex. serviceモジュール、yumモジュール、homebrewモジュール、etc.
  • 冪等性

設定例

serviceモジュールは、リモートサーバーへのパッケージインストール、デーモン起動、サーバー再起動時の自動起動などをシンプルに記述できる。

- name: Install monit And Start And On Boot
  service: name=monit enabled=yes state=started

応用例

MacBook の設定

https://github.com/eyasuyuki/ansible-macbook

多段ssh

ansible.cfg

[defaults]
inventory = ./hosts

[ssh_connection]
ssh_args = -o ControlMaster=no -F ./ssh.config

ssh.config

Host *
    IdentityFile /home/yasuyuki/.ssh/id_rsa
    ProxyCommand ssh -W %h:%p endo@gatewayhost

デバッグ

起動オプションに -vvvv を付けるとssh -vvv で動作する。

ansible-playbook hoge.yml -vvvv -K

Sudoパスワード

起動オプションに -K を付けるとsudoパスワードのプロンプトが表示される。

これによってスクリプト内部にパスワードを平文で記述する必要がなくなる。

(ターゲットホストが複数ある場合は全て同じパスワードにしておく必要がある)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment