LoginSignup
46
46

More than 5 years have passed since last update.

AnsibleをUbuntuのローカルで使う

Last updated at Posted at 2013-10-25

Ansibleを少し触ってみたが、Chefとは違ってクライアントプログラムのインストールが不要で、ファイル・ディレクトリ構成が小規模で自由度が高いので、ローカル環境の管理に向いていると思う。
ついでに言うと、接続先をローカルとするオプションも存在する。

インストール

pipを使ってAnsibleをインストールする。
virtualenvなどを使えば仮想的な実行環境を作れるらしいが、今回はシステムワイドにインストールする。

sudo apt-get install python-pip
sudo pip install ansible

Playbook

インベントリファイルでホスト変数にansible_connection=localを設定して、ローカルに接続するように設定する。

localhost
127.0.0.1 ansible_connection=local

とりあえずapt-getgitをインストールしてみる。

site.yml
---
- hosts: 127.0.0.1
  user: itiut
  tasks:
    - name: "apt-get install git"
      apt: pkg=git
      sudo: yes

実行

オプション-iでインベントリファイルを指定し、オプション-Kもしくは--ask-sudo-passsudoのパスワードを要求するようにする。

ansible-playbook site.yml -i localhost -K
46
46
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
46
46