{"record":{"id":"6207303caa3fbe20","repo":"hashicorp/vagrant","slug":"ansible-failed-to-complete-successfully-any-error","errorCode":null,"errorMessage":"Ansible failed to complete successfully. Any error output should be\nvisible above. Please fix these errors and try again.","messagePattern":"Ansible failed to complete successfully\\. Any error output should be\nvisible above\\. Please fix these errors and try again\\.","errorType":"exception","errorClass":"VagrantPlugins::Ansible::Errors.AnsibleCommandFailed","httpStatus":null,"severity":"error","filePath":"plugins/provisioners/ansible/provisioner/guest.rb","lineNumber":119,"sourceCode":"          prepare_ansible_config_environment_variable\n\n          execute_ansible_command_on_guest \"galaxy\", ansible_galaxy_command_for_shell_execution\n        end\n\n        def execute_ansible_playbook_on_guest\n          prepare_common_command_arguments\n          prepare_common_environment_variables\n\n          execute_ansible_command_on_guest \"playbook\", ansible_playbook_command_for_shell_execution\n        end\n\n        def execute_ansible_command_on_guest(name, command)\n          remote_command = \"cd #{config.provisioning_path} && #{command}\"\n\n          ui_running_ansible_command name, remote_command\n\n          result = execute_on_guest(remote_command)\n          raise Ansible::Errors::AnsibleCommandFailed if result != 0\n        end\n\n        def execute_on_guest(command)\n          @machine.communicate.execute(command, error_check: false) do |type, data|\n            if [:stderr, :stdout].include?(type)\n              @machine.env.ui.info(data, new_line: false, prefix: false)\n            end\n          end\n        end\n\n        def ship_generated_inventory(inventory_content)\n          inventory_basedir = File.join(config.tmp_path, \"inventory\")\n          inventory_path = File.join(inventory_basedir, \"vagrant_ansible_local_inventory\")\n\n          @machine.communicate.sudo(\"mkdir -p #{inventory_basedir}\")\n          @machine.communicate.sudo(\"chown -R -h #{@machine.ssh_info[:username]} #{config.tmp_path}\")\n          @machine.communicate.sudo(\"rm -f #{inventory_path}\", error_check: false)\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/provisioners/ansible/provisioner/guest.rb#L101-L137","documentation":"When the ansible (guest-side) provisioner runs the playbook, it streams the command's stdout/stderr to the Vagrant UI and raises AnsibleCommandFailed if the remote exit code is non-zero. The error itself carries no details — everything ansible printed is already visible above it in the output. Fixing it means fixing whatever ansible complained about (or the playbook's environment), then re-running `vagrant provision`.","triggerScenarios":"execute_ansible_command_on_guest('playbook', ...) where execute_on_guest runs `cd <provisioning_path> && <ansible-playbook ...>` with error_check: false and the returned exit status != 0 — failed tasks, unreachable hosts, syntax errors in the playbook, missing collections/roles in the guest.","commonSituations":"Playbook task failure (package install, service start); role/collection not present in the guest's ansible; inventory generated by Vagrant missing expected groups; python interpreter mismatch inside guest; vault password prompt blocking the non-interactive run.","solutions":["Scroll up: the ansible task traceback right above the error names the failing task and reason","Reproduce interactively: `vagrant ssh` then run the printed `cd /vagrant-ansible... && ansible-playbook ...` command","Fix the playbook/dependencies (install requirements via ansible.galaxy_role_file/galaxy_collection_file, or a pre-provision shell step)","Add `ansible.verbose = \"vvv\"` in the Vagrantfile for more ansible detail on the next `vagrant provision`"],"exampleFix":"# Vagrantfile — before (collection missing in guest -> nonzero exit)\nconfig.vm.provision \"ansible\" do |ansible|\n  ansible.playbook = \"site.yml\"   # site.yml uses community.general\nend\n# after — ship the collection into the guest first\nconfig.vm.provision \"shell\", inline: \"ansible-galaxy collection install community.general\"\nconfig.vm.provision \"ansible\" do |ansible|\n  ansible.playbook = \"site.yml\"\nend","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  machine.provision\nrescue Ansible::Errors::AnsibleCommandFailed\n  # ansible output was already streamed to the UI; decide whether to retry after remediation\n  retry if remediate_playbook_deps! && (attempts += 1) < 2\n  raise\nend","preventionTips":["Lint the playbook (`ansible-lint`, `ansible-playbook --syntax-check`) before wiring it into Vagrant","Install roles/collections in the guest via a preceding shell/galaxy provisioner step","Develop with `ansible.verbose = true` so failures carry enough detail the first time"],"tags":["ansible","provisioner","guest","playbook","exit-code"],"backgroundTag":"ansible-playbook-failed","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}