{"record":{"id":"c93e7c0b23402d88","repo":"hashicorp/vagrant","slug":"the-requested-ansible-compatibility-mode-compat","errorCode":null,"errorMessage":"The requested Ansible compatibility mode (%{compatibility_mode}) is in conflict with\nthe Ansible installation on your Vagrant %{system} system (currently: %{ansible_version}).\nSee https://docs.vagrantup.com/v2/provisioning/ansible_common.html#compatibility_mode\nfor more information.","messagePattern":"The requested Ansible compatibility mode \\(%(.+?)\\) is in conflict with\nthe Ansible installation on your Vagrant %(.+?) system \\(currently: %(.+?)\\)\\.\nSee https://docs\\.vagrantup\\.com/v2/provisioning/ansible_common\\.html#compatibility_mode\nfor more information\\.","errorType":"exception","errorClass":"VagrantPlugins::Ansible::Errors.AnsibleCompatibilityModeConflict","httpStatus":null,"severity":"error","filePath":"plugins/provisioners/ansible/provisioner/base.rb","lineNumber":80,"sourceCode":"            set_gathered_ansible_version(gather_ansible_version(\"ansible\"))\n          rescue StandardError => e\n            # Nothing to do here, as the fallback on safe compatibility_mode is done below\n            @logger.error(\"Error while gathering the ansible version: #{e.to_s}\")\n          end\n\n          begin\n            set_gathered_ansible_package_version(\"ansible-core\", gather_ansible_version(\"ansible-core\"))\n          rescue StandardError => e\n             @logger.error(\"Error while gathering the ansible-core version: #{e}\")\n          end\n          \n          if @gathered_version_major\n            if config.compatibility_mode == Ansible::COMPATIBILITY_MODE_AUTO\n              detect_compatibility_mode\n            elsif @gathered_version_major.to_i < 2 && config.compatibility_mode == Ansible::COMPATIBILITY_MODE_V2_0\n              # A better version comparator will be needed\n              # when more compatibility modes come... but so far let's keep it simple!\n              raise Ansible::Errors::AnsibleCompatibilityModeConflict,\n                ansible_version: @gathered_version,\n                system: @control_machine,\n                compatibility_mode: config.compatibility_mode\n            end\n          end\n\n          if config.compatibility_mode == Ansible::COMPATIBILITY_MODE_AUTO\n            config.compatibility_mode = Ansible::SAFE_COMPATIBILITY_MODE\n\n            @machine.env.ui.warn(I18n.t(\"vagrant.provisioners.ansible.compatibility_mode_not_detected\",\n              compatibility_mode: config.compatibility_mode,\n              gathered_version: @gathered_version_stdout) +\n            \"\\n\")\n          end\n\n          unless Ansible::COMPATIBILITY_MODES.slice(1..-1).include?(config.compatibility_mode)\n            raise Ansible::Errors::AnsibleProgrammingError,\n              message: \"The config.compatibility_mode must be correctly set at this stage!\",","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/provisioners/ansible/provisioner/base.rb#L62-L98","documentation":"The Ansible provisioner probes the installed ansible/ansible-core version and, when the Vagrantfile explicitly requests compatibility_mode \"2.0\" while the detected major version is < 2, it raises AnsibleCompatibilityModeConflict. The mode controls which option lexicon Vagrant emits (1.8 vs 2.0), so declaring 2.0 against an ansible 1.x install would generate unsupported flags. AUTO mode never raises here — it detects instead.","triggerScenarios":"set_and_check_compatibility_mode runs during provision; @gathered_version_major.to_i < 2 while config.compatibility_mode == Ansible::COMPATIBILITY_MODE_V2_0 (\"2.0\" in the Vagrantfile) — i.e. host or guest has ansible 1.9.x or older installed and the Vagrantfile pins mode \"2.0\".","commonSituations":"Legacy hosts still on ansible 1.9; a base box shipping ancient ansible while the Vagrantfile was written for modern ansible; installing ansible via pip into a different python than the one probed (so detection reads the old system copy); upgrading Vagrant changed the default and someone pinned \"2.0\" blindly.","solutions":["Upgrade ansible on the controlling machine to >= 2.0 (`pip install -U ansible` or the distro package)","Or set `ansible.compatibility_mode = \"auto\"` / remove the pin so Vagrant picks the right lexicon for what is installed","Or set compatibility_mode = \"1.8\" if you must keep the old ansible","Verify which ansible is detected: run `ansible --version` with the same user/environment vagrant uses (and `python3 -c \"import importlib.metadata; print(importlib.metadata.version('ansible'))\"`)"],"exampleFix":"# Vagrantfile — before (host runs ansible 1.9.x)\nansible.compatibility_mode = \"2.0\"\n# after — let Vagrant match the installed version\nansible.compatibility_mode = \"auto\"","handlingStrategy":"validation","validationCode":"installed = `ansible --version 2>/dev/null`[/ansible[^\\n]* ([\\d.]+)/, 1] || `python3 -c \"import importlib.metadata; print(importlib.metadata.version('ansible'))\" 2>/dev/null`\nabort 'ansible >= 2.0 required for compatibility_mode 2.0' if installed && installed.split('.').first.to_i < 2","typeGuard":"def ansible_supports_v2?\n  v = `python3 -c \"import importlib.metadata; print(importlib.metadata.version('ansible'))\" 2>/dev/null`.to_s.split('.').first.to_i\n  v >= 2\nend","tryCatchPattern":null,"preventionTips":["Leave compatibility_mode on \"auto\" unless you specifically need the 1.8 option lexicon","Pin host/guest ansible versions in the project README or bootstrap scripts so the pin and reality agree"],"tags":["ansible","provisioner","compatibility-mode","version-conflict"],"backgroundTag":"ansible-version-mismatch","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}