9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansible入門

Last updated at Posted at 2014-10-06

gitをansibleで入れるだけの簡単なお仕事です

まずはこちらを最後までやっていただくとansibleのテスト環境が出来上がります

playbookを作成

cd ~/ansible
vi git-playbook.yml

playbookの中身

git-playbook.yml
- hosts: sandbox
  sudo: yes
  vars:
    homedir: /home/vagrant/
  tasks:
    - name: git is installed
      yum: name=git state=installed

実行

gmpを入れろという警告が出ますが今回は問題ないのでそのまま

$ ansible-playbook git-playbook.yml
 [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).


PLAY [git] *****************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.66.54]

TASK: [git is installed] ******************************************************
changed: [192.168.66.54]

冪等性の確認

ansibleは冪等性を保つように作られています。冪等性とはある操作を1回行っても複数回行っても結果が同じであることをいう概念です。

もう一度playbookを実行してみる

$ ansible-playbook git-playbook.yml
 [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).


PLAY [git] *****************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.66.54]

TASK: [git is installed] ******************************************************
ok: [192.168.66.54]

1回目のplaybook実行時には「changed」と表記されたところが2回目だと「ok」と出たのが確認できたと思います。これはもう既に入っているよという事でタスクは実行されていません。

冪等性が保てない例外

rawモジュールで指定できるtaskは生のコマンドを流すだけなので冪等性は保たれませんので別のモジュールで対応できるところはなるべく冪等性を保てるようにしましょう

参考

日本語のドキュメントがあるので色々やってみたくなったらこちら

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?