====== Ansible ====== {{ :serverapps:configmgmt:ansible:ansible_logo.png?nolink&200|}} * 構成管理(configuration management) * アプリケーション構築(application deployment) * オーケストレーション(orchestration) ===== ===== を行うためPython製ツール\\ Ansibleの最大の特徴はエージェントレス * pythonがインストールされていること * sshでLogin可能なこと 上記が満たされていればOK ===== インストール(管理する側) ===== ==== CentOS 6.6 ==== epelリポジトリを設定((詳しい設定は[[os:centos:yum#サードパーティが提供しているyumレポジトリ]]))する。epelレポジトリは普段は使用しないよう(enabled=0)にしておく # rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel.repo インストール # yum install --enablerepo=epel ansible 確認 # ansible --version ansible 1.7.2 以下のようなWarnが出る場合があるが、支障がないので放置((updateがリポポジトリになかった)) [WARNING]: The version of gmp you have installed has a known issue regarding timing vulnerabilities when used with pycrypto. If possible, you should update it (ie. yum update gmp). 2015.10.13:追記\\ 6.7でsshパスワードを入力しようとすると以下のエラー FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program 以下のオプションでOKという話だったが、うちの環境ではだめ -c paramiko 結局、素直にsshpassをインストール yum install --enablerepo=epel sshpass この状態でアクセスすると以下のエラー FAILED => Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host. ssh-keyscan でホストキーを known_hosts に登録 ssh-keyscan 192.168.xx.yyy >> ~/.ssh/known_hosts ==== FreeBSD 10.1 ==== インストール # pkg install ansible 確認 # ansible --version ansible 1.7.2 ==== pip ==== pipをインストール # curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python Ansibleのインストール必要なパッケージをインストール(CentOS) yum -y install gcc python-devel ansibleのインストール # pip install ansible ===== インストール(リモートホスト) ===== * pythonがインストールされていること * sshでLogin可能なこと ==== ==== 上記が満たされていればOK ===== 設定 ===== /usr/local/etc/ansible/hosts((Linuxでは/etc/ansible/hosts)) にリモートホストをini形式で記述する((/usr/local/share/examples/ansible/にサンプルがある)) 192.168.1.xxx host.example.com [serevrs] host1 host2 ...... ユーザ名、秘密鍵の指定も可能 192.168.1.xxx ansible_ssh_user=ansibleuser ansible_ssh_private_key_file=/home/ansibleuser/.ssh/ansibleuser.pem linuxからFreeBSDをコントロールしようとすると、pyrhonが見つからないといわれるので以下のように 192.168.1.xxx ansible_python_interpreter=/usr/bin/python ===== テスト ===== ping モジュールでテスト\\ 前述のhostsファイルを作成していないと $ ansible myhost -m ping ERROR: Unable to find an inventory file, specify one with -i ? とエラーになる。\\ Ansibleはインベントリファイルに書かれたホストにしかアクセスしないので、適当に書いて以下のように指定することも可能 $ echo myhost > hosts $ ansible -i hosts myhost -m ping myhost | success >> { "changed": false, "ping": "pong" } ホスト名(IP)の代わりに"all"を指定すると ansible/hostsすべてに実行される $ ansible all -m ping myhost | success >> { "changed": false, "ping": "pong" } hostB | success >> { ...... -aを指定することで任意のコマンドを実行 $ ansible 192.168.1.xxx -a 'hostname' 192.168.1.xxx | success | rc=0 >> host --sudo オプションを指定することで、root 権限の必要なコマンドも実行可能((当然、sudo権限を持っていること)) $ ansible host --sudo -a id host | success | rc=0 >> uid=0(root) gid=0(root) groups=0(root) ...... ===== 参考 ===== [[http://docs.ansible.com/|公式のドキュメント]] [[http://www.ansible.com/blog|公式ブログ]] [[http://ansible-users.connpass.com/|日本のAnsibleユーザ会]] [[http://yteraoka.github.io/ansible-tutorial/|チュートリアル]] [[https://github.com/ansible/ansible/blob/devel/CONTRIBUTING.md#mailing-lists|メーリングリスト]] [[http://tdoc.info/blog/2014/01/20/ansible_beyond_configuration.html|Ansibleのアーキテクチャー: 構成管理を超えて]] [[http://qiita.com/progre/items/ccc2d8c2ec7ae8a4ed61|AnsibleをゲストOSに押し込んでVagrant環境構築する]] [[http://d.hatena.ne.jp/akishin999/20130815/1376520672|Ansible の Playbook を使ってみる]] [[http://phansible.com/|Phansible]] -- PHPの開発環境を構築する Vagranfile を生成します。Ansible でプロビジョンを行うので、Playbook の書き方など参考になります。 [[http://qiita.com/kakkotetsu/items/3bf035de2ac37739df75|Python が入っていない NW 機器も Ansible で (一応) 制御できる]] http://lazy-dog.hatenablog.com/entry/2014/09/21/114738 [[http://tdoc.info/blog/2014/10/09/ansible_coding.html|Ansible コーディング規約 (の例)]] [[http://blog.n-z.jp/blog/2014-06-21-ansible-yaml.html|ansible使いのためのYAML入門]]