Windonws上でVagrantとansibleを使ってつまづいた箇所
経緯
Windows上で開発用のVMを設定するのに、ansibleを使いたい。使いたくない?
↓
Vagrant上でansible_localを使えばいけんじゃね!?
つまづきどころ
以下では、Vagrantで立ち上げるサーバはcontroller
とtarget
で、
controller
がansibleをインストールするVM、
target
がansibleを流されるVMとして、話を進める。
ask_vault_pass
オプションがねえ
開発用の環境なのでお行儀は悪い。
Vagrantfile
にこんな感じで書く。
Vagrant.configure(2) do |config| config.vm.box = '...' config.vm.provision :shell, inline: "echo 'password' > /tmp/vault_pass" config.vm.define :controller do |machine| ... machine.vm.provision 'ansible_local' do |ansible| ... ansible.vault_password_file = "/tmp/vault_pass" ... end end end
/tmp/vault_pass
ファイルにパスワードを流し込んで、vault_password_file
にそのファイルを設定している。
Authentication failure.
と出る
fatal: [192.168.x.x]: UNREACHABLE! => {"changed": false, "msg": "Authentication failed.", "unreachable": true}
これはVagrantのエラーではなく、ansibleのエラーのほう。
hosts
ファイルに以下のように書く。
[target] 192.168.x.x ansible_ssh_pass=vagrant ansible_ssh_user=vagrant
それと、controller
からtarget
へ、一回SSHで繋いでおく。
$ vagrant ssh controller [vagrant@controller ~] $ ssh <targetのIPアドレス> yes password: vagrant
でおk。