geerlingguy / ansible-vagrant-examples

Ansible examples using Vagrant to deploy to local VMs.
MIT License
2.09k stars 707 forks source link

Vagrant gathered an unknown Ansible version #83

Closed abidmunirmalik closed 3 years ago

abidmunirmalik commented 4 years ago

Hi there, I am following the "Ansible for DevOps" book where I have created "playbook.yml", when I attempt to run "vagrant provision" I get the error: "Vagrant gathered an unknown Ansible version and falls back on the compatibility mode '1.8'. default: Running ansible-playbook... Traceback (most recent call last): 65: from /opt/vagrant/embedded/gems/2.2.10/gems/vagrant-2.2.10/bin/vagrant:205:in `

'

I believe this is version incompatibility issue?

geerlingguy commented 3 years ago

Can you check what version of Ansible you have installed? Try ansible --version.

Also are you on a Linux workstation, Mac, or Windows? If you installed Ansible via a package manager, it could be far out of date. Maybe try with pip3 install ansible.

stale[bot] commented 3 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] commented 3 years ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

jamesquilty commented 3 years ago

@geerlingguy I'm seeing a similar problem, just without the traceback. I suspect it's because the Homebrew-installed version of Ansible is, when asked, reporting the version number in an unexpected format:

$ ansible --version
ansible [core 2.11.0]
  config file = None
  configured module search path = ['/Users/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/4.0.0/libexec/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/username/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.5 (default, May  4 2021, 03:29:30) [Clang 11.0.0 (clang-1100.0.33.17)]
  jinja version = 3.0.1
  libyaml = True

On Raspberry Pi OS (Stretch) I receive:

$ ansible --version
ansible 2.9.22
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/pi/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Apr 16 2021, 14:02:03) [GCC 6.3.0 20170516]

I'm not sure if this is out of scope for this project or if it should be raised as a separate Issue?

BTW, thanks for writing Ansible for DevOps, I'm enjoying it very much!

geerlingguy commented 3 years ago

@jamesquilty - I'm guessing that's something Vagrant will need to fix up, because the new version output is indeed a bit different than the classic version output. It's broken a number of different scripts that are in use :(

jamesquilty commented 3 years ago

Right you are, and I see it's already been reported as https://github.com/hashicorp/vagrant/issues/12404, https://github.com/hashicorp/vagrant/issues/12405 and fixed in https://github.com/hashicorp/vagrant/pull/12391. As noted in one of the comments, it's just a matter of waiting until the next release to receive the fix.

jamesquilty commented 3 years ago

It's very easy to apply the fix to the existing installation of Vagrant 2.2.16 by editing /opt/vagrant/embedded/gems/2.2.16/gems/vagrant-2.2.16/plugins/provisioners/ansible/provisioner/base.rb and making the change to line 392 shown in https://github.com/hashicorp/vagrant/pull/12391/commits/89c071d374437c8c24dce52a75434dafe90ccd69 which is to remove the ^ character from the match regexp. It's literally a one-character change 😄

Cilyan commented 3 years ago

Same here with Archlinux and ansible [core 2.11.3]. Please re-open the issue, so fix can be tracked.

Vagrant 2.2.16

jamesquilty commented 3 years ago

@Cilyan This particular problem was fixed with the Vagrant 2.2.17 release and I can confirm that it's definitely not present in the 2.2.18 release. I can understand that you might not be able to or want to update just now and, if that's the case, please try the fix I mentioned above. That fix worked for me on 2.2.16 until I was in a position to update.

Cilyan commented 3 years ago

Oops, if that's the case, my bad. I'm always assuming that Arch is up to date, as this is a rolling release with bleeding edge in mind. But it seems that the official repos are still on 2.2.16 and did not update yet.

guleyupo commented 2 years ago

Problem still exists on the brew-installed mac os (ansible --version -> ansible [core 2.12.4]) environment. Google finds this page as the first link on searching for the error text while following the book examples. I thought it may help to put this workaround here for easy copy/paste solution, even though the warning mentions it as a solution as well: To avoid the verbose warning message add ansible.compatibility_mode = "2.0" inside the config.vm.provision "ansible" do |ansible| block.

RanchoHam commented 9 months ago

As of Jan 2024, this problem still exists for vagrant and ansible installs using SUSE Tumbleweed packages. The fix by @guleyupo for getting rid of the compatibility fall-back worked for me. But it is like this version of ansible couldn't figure out which OS was running on the guest: I was running a Debian 11 guest, but ansible wanted to know what "dnf is in use" like it was trying to install on a fedora OS.