LoginSignup
3
3

More than 5 years have passed since last update.

ansible (1)

Posted at

目的

ansibleを試す環境を作るところまで

事前準備

  • virtualbox install
  • vagrant install

仮想マシン準備

mkdir ansible
cd ansible
vagrant init

作成されたVagrantファイルを編集する前に、
以下のどちらかでvmのテンプレートを探す。
https://atlas.hashicorp.com/boxes/search
http://www.vagrantbox.es/

今回はopscodeさんのcentos7を利用することにした。

-  config.vm.box = "base"
+  config.vm.box = "chef/centos-7.0"

仮想マシン起動、sshログインできれば仮想マシン準備完了
vagrant up
vagrant ssh

ansible用の準備

ansible install

brew install ansible

なんども思考出来るようsnapshotプラグインインストール

vagrant plugin install vagrant-vbox-snapshot

ansibleテスト

チュートリアルを見ながら実施
http://yteraoka.github.io/ansible-tutorial/

ansibleは、sshでパスワードなしでログインできるようにしておく必要が有る。
具体的には、ssh ホスト名 でパスワードなしで実行出来ればOK。

そのために、
* 「vagrant ssh-config」の実行結果を~/.ssh/configにコピーする
* コピーする際、Host名をわかりやすいものに変更する

Host centos
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /(各自の環境依存)/ansible/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

ansibleは、設定ファイルがないと動かないぽいので、
hosts名だけが入ったファイルを作成する。

echo centos > hosts

ssh centosができれば準備完了

$ ansible -i hosts centos -m ping

localhost | success >> {
    "changed": false,
    "ping": "pong"
}
$ ansible -i hosts centos -a 'uname -r'
centos | success | rc=0 >>
3.10.0-123.el7.x86_64
3
3
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
3
3