geerlingguy / ansible-for-devops

Ansible for DevOps examples.
https://www.ansiblefordevops.com
MIT License
8.42k stars 3.45k forks source link

Chapter2 #352

Closed jmp8600e closed 3 years ago

jmp8600e commented 3 years ago

On chapter 2, I am following the whole chapter line by line and on Windows 10...the command "vagrant provision" throws below error. did anyone not get the same error? I am googling this error and there seems to be lot of configurations needed in order to go through this...how did it is work for you all? The chapter does say to install virtualbox and vagrant on a windows machine(page 10), i have also tried WSL route which is Appendix A but it just creates Ubuntu VM. The book is not making any clarification on how to make this work...

PS C:\Education\Ansible\VMs> vagrant provision ==> default: Running provisioner: ansible... Windows is not officially supported for the Ansible Control Machine. Please check https://docs.ansible.com/intro_installation.html#control-machine-requirements Vagrant gathered an unknown Ansible version:

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.

jmp8600e commented 3 years ago

If anyone is going through the same issue....I was able to figure out how to do this....It took some time but it was good going through this...

Do not try to make ansible and vagrant work using cygwin route. It does not work and you will just spend unnecessary time going through this....so the only option left is WLS, which is described in appending A of the book. Enable that feature. Then install Ubuntu version from Microsoft Store. I did not use Ubuntu LTS version. After installation, when you open for the 1st time it will ask for new user name and password. create one. When in the ubuntu terminal run following commands

sudo apt update
sudo apt upgrade
sudo apt install python3-pip
pip3 install ansible --user
echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
source .bashrc

now run below command and make sure ansible is installed: ansible --version

Now comes the important part....you can access windows 10 filesystem under /mnt/c/ from Ubuntu

I have created vagrantfile and playbook.yml under C:\Education\Ansible\VMs, so on the Ubunt I need to cd inside this folder /mnt/c/Education/Ansible/VMs and run following command to bring up the virtual machine:

vagrant.exe up

Keep in mind that Ansible is not installed on your windows 10. So in Vagrantfile you have to use ansible_local instead of ansible...

So chnage line config.vm.provision :ansible do |ansible| to: config.vm.provision :ansible_local do |ansible|

Now you can run following command from the Ubuntu and Ansible playbook will be run on that virtual machine defined in VegrantFile

vagrant.exe provision

Some information is given here: https://www.jeffgeerling.com/blog/2017/using-ansible-through-windows-10s-subsystem-linux

In the book it is not pretty clear on how to make this work.

Thanks, -Jatin

jatin99 commented 1 year ago

Thanks

baophuong0209 commented 1 year ago

Thank you so much for your instruction!

viniciuspc commented 1 year ago

For me the easier way was to add this ansible.compatibility_mode = "2.0"

inside the config.vm.provision :ansible do |ansible| block in the Vagrantfile