LoginSignup
29
31

More than 5 years have passed since last update.

ssh config を汚さずに Ansible で Vagrant ホストを扱う

Last updated at Posted at 2014-08-12

vagrant ssh-config >> ~/.ssh/config はイヤだというときに。
ansible.cfg を使う。

ansible.cfg
[defaults]
hostfile = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
remote_user = vagrant
private_key_file = ~/.vagrant.d/insecure_private_key
host_key_checking = False

inventory には Vagrant が作成するものを使う。

ただし ansible provisioner を走らせないと Vagrant は inventory を生成してくれない。
http://qiita.com/janus_wel/items/cf5e0cf41ad771f92038 のように素直に provisioner を使えない場合は以下のようなダミーを使って生成させる。

generate-inventory.yml
--- # generate ansible inventory file with Vagrant
- hosts: default
  tasks:
    - name: ping
      action: ping

で、こう。

Vagrantfile
  config.vm.provision "ansible" do |ansible|
    ansible.host_key_checking = false
    ansible.playbook = "generate-inventory.yml"
  end

これで何も考えずに ansible-playbook playbook.yml できる。

29
31
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
29
31