LoginSignup
9
10

More than 5 years have passed since last update.

Mac上のCentOS(vagrant)にansibleで環境を構築する(準備)

Posted at

概要

vagrantのprovision機能を使って、ansibleによる環境構築をするのではなく、Macでansible-playbookコマンドを叩いて、vagrantの環境を構築する準備をします

ansibleの導入

  1. xcodeをインストール
  2. pipのインストール

sudo easy_install pip

  1. pipからansibleをインストール

sudo pip install ansible --quiet

  1. ansibleのインストールを確認

ansible --version

ansibleを使ってvagrantに接続

  1. vagrantへの接続情報を取得

vagrant ssh-config > ssh_config

ssh_config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2201
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile ~/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
  1. 先ほど取得した接続方法を使うようにansibleの設定ファイルを書く
ansible.cfg
 [ssh_connection]
 ssh_args = -F ssh_config
  1. 接続先のroleを指定するためのファイルを作成
 [front] # role名。名前は適当
 default # ssh_configでHostがdefaultという名前なので
  1. 接続できるか確認
 $ ls
 Vagrantfile ansible.cfg hosts ssh_config

 $ ansible -i hosts front -a 'uname -r'

まとめ

以上で準備は完了です。あとは、ansibleのplaybookを書いて、
ansible-playbook -i hosts playbook.ymlとかするといろんな環境が構築できます。

9
10
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
10