-プロビジョニングツール

#contents

*インストール前に [#m389e3bc]

コントロールされる側に以下のパッケージが必要。

python-simplejson

*Install [#a1ef0832]

Pythonのパッケージ管理であるpipを使うと楽。EPEL から yum でもインストール可能。

 yum install ansible --enablerepo=epel

*文法チェック [#lcd9b61e]

 ansible-playbook -i hosts simple-playbook.yml --syntax-check

*Playbook [#a57e2726]

 - hosts: all
   user: hoge
   tasks:
     - script: /home/hoge/test.sh

*モジュール [#oe3c52a8]

**Command Module [#da755925]

リモートでOSコマンドを実施する。

 # Example from Ansible Playbooks.
 - command: /sbin/shutdown -t now
 
 # createsに指定されたファイルがない場合はcommandの処理を実行
 - command: /usr/bin/make_database.sh arg1 arg2 creates=/path/to/database

 # somedir以下に移動し、かつ
 # createsに指定されたファイルがない場合はcommandの処理を実行
 - command: /usr/bin/make_database.sh arg1 arg2
   args:
     chdir: somedir/
     creates: /path/to/database

 #繰り返し処理のサンプル。変数定義済みであればwith_items:{{users}}でもOK
 - name: add several users
   user: name={{ item }} state=present groups=wheel
   with_items:
      - testuser1
      - testuser2

 #コンパイルのタスクだが、実際にはシェルが実行できるのでなんでもOK
 - name: Apacheコンパイル
   shell:
     make
       chdir=/usr/local/src/httpd-2.4.12
       creates=/usr/local/apache/2.4.12/bin/httpd

**Script Module [#o42793d1]

操作先にShellを送り込んで実行。操作先にpythonが必要ないのもメリット

**Shell Module [#b6a7badd]

Ansibleの実行サーバー先にあるshファイルをリモートに送り込んで実行できる。


*条件 [#e7f8c9ad]

変数は{{}}で囲まないので注意

 - user: root
   hosts: all
   tasks:
     - name: install mlocate
       yum: name=mlocate state=installed
       when: install == "y"

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS