윈도우즈 호스트 환경에서 WSL2에 Vagrant/Ansible을 설치하여 호스트에 설치된 virtualbox을 활용하여 Ansible 실습/테스트 환경을 구성하고 환경구성 검증을 위해 Drupal provisioning 함
윈도우에는 ansible control 서버를 설치 할 수 없어 ansible provisioner를 사용할 수 없음
여기에 기술된 방법은 WSL2을 Ansible Controller로 Ansible 실습/테스트 환경을 구성하는 방법으로 Host가 Linux 또는 Mac OS에서와 같은 Ansible 실습/테스트 환경을 구성할 수 있도록 해줌
vagrant에서 ansible/ansible_local 지원
ansible provioner는 호스트에 asnible 설치, ansible_local는 guest에 ansible 설치 따라서 window host에서는 ansible_local 사용
windows에서는 vagrant가 provider(VM제공,하이퍼바이저 역할) virtualbox와 provisoner(서버구성 / SW설치 / 설정) ansible_local을 이용
WSL2 Linux에서는 Ansible(linux) --> vagrant(linux) ---> vagrant(windows) ---> virtualbox(windows)
참고
호스트 vagrant(windows 10)와 WSL2 vagrant 버전 통일
NOTE: When Vagrant is installed on the Windows system the version installed within the Linux distribution must match.'
에러 메세지
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system.
The reason is shown below:
VirtualBox is complaining that the kernel module is not loaded. Please
run `VBoxManage --version` or open the VirtualBox GUI to see the error
message which should contain instructions on how to fix this error.
WSL2 vagrant 삭제후 재 설치
> wget https://releases.hashicorp.com/\
vagrant/2.2.16/vagrant_2.2.16_linux_amd64.zip
> unzip vagrant_2.2.16_linux_amd64.zip
> sudo mv ./vagrant /usr/local/bin/vagrant
vagrant가 아카이브 파일 읽고/쓰기 위해 필요, 미 설치로 다음 에러 발생
INFO interface: error: The executable 'bsdtar'
Vagrant is trying to run was not
found in the PATH variable. This is an error. Please verify
this software is installed and on the path.
The executable 'bsdtar' Vagrant is trying to run was
not found in the PATH variable.
This is an error. Please verify
this software is installed and on the path.
INFO interface: Machine: error-exit
["Vagrant::Errors::CommandUnavailable",
"The executable 'bsdtar' Vagrant is trying to run
was not found in the PATH variable.
This is an error. Please verify
this software is installed and on the path."]
설치
> sudo apt install libarchive-tools
ssh 오류 해결 plugin 설치: vagrant plugin install virtualbox_WSL2
...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
wsl.conf 생성 : /etc/wsl.conf
private key 권한 변경 시 리눅스 파일 시스템 권한 설정 기능 필요
wsl.conf의 역할 : WSL 실행시 자동 구성 수행
Automatically configure functionality in WSL that will be applied every time you launch the subsystem using
wsl.conf
. This includes automount options and network configuration.
wsl.conf
is located in each Linux distribution in/etc/wsl.conf
.
automout / metata
metadata Whether metadata is added to Windows files to support Linux system permissions
설정 내용
> cat /etc/wsl.conf
[automount]
options = "metadata"
Other useful WSL related environment variables:
VAGRANT_WSL_WINDOWS_ACCESS_USER - Override current Windows username
VAGRANT_WSL_DISABLE_VAGRANT_HOME - Do not modify the VAGRANT_HOME variable
VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH - Custom Windows system home path
출처 : https://www.vagrantup.com/docs/other/wsl
# for ansible + vagrant
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export PATH="$PATH:/mnt/d/virtualbox"
export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/d/Ansible-Handson/"
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "geerlingguy/ubuntu2004"
config.vm.network :private_network, ip: "192.168.88.8"
config.vm.hostname = "drupal.test"
config.ssh.insert_key = false
config.vm.provider :virtualbox do |v|
v.memory = 2048
end
#config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder '.', '/vagrant'
# Ansible provisioning.
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "provisioning/playbook.yml"
end
end
ansible [core 2.11.1]
config file = /etc/ansible/ansible.cfg
configured module search path =
['/home/igotoo/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location = /home/igotoo/.local/lib/
python3.8/site-packages/ansible
ansible collection location = /home/igotoo/.ansible/
collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
jinja version = 2.10.1
libyaml = True
and falls back on the compatibility mode '1.8'.
Alternatively, the compatibility mode can be specified in
your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/
ansible_common.html#compatibility_mode
default: Running ansible-playbook...
The Ansible software could not be found! Please verify
that Ansible is correctly installed on your host system.
If you haven't installed Ansible yet, please install Ansible
on your host system. Vagrant can't do this for you in a safe and
automated way.
Please check https://docs.ansible.com for more information.
> vagrant provision
==> default: Running provisioner: ansible_local...
default: Installing Ansible...
default: Running ansible-playbook...
Vagrant gathered an unknown Ansible version:
ansible [core 2.11.2]
config file = None
configured module search path = ['/home/igotoo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/igotoo/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/igotoo/.ansible/collections:/usr/share/ansible/collections
executable location = /home/igotoo/.local/bin/ansible
python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
jinja version = 2.10.1
libyaml = True
and falls back on the compatibility mode '1.8'.
Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode
If Vagrant is not able to detect any supported Ansible version, it will fall back on the compatibility mode "1.8" with a warning.
# Ansible provisioner.
config.vm.provision :ansible do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "playbook.yml"
ansible.become = true
end