Ansible troubleshooting - Destination does not exist
How to reproduce the destination does not exist error in Ansible, troubleshooting, and fix to be able to successfully download a file from an URL in a home directory with your Ansible playbook.


Ansible Troubleshooting: Destination Does Not Exist Error
Author: Luca Berton
Date: 2022-01-04
Tags: ansible, troubleshooting, url, linux, download, error, fatal, filesystem
Categories: troubleshooting, linux
Introduction
Welcome to another episode of Ansible Pilot! I’m Luca Berton, and today we’ll dive into troubleshooting Ansible, specifically focusing on the notorious “destination does not exist error.” This error often occurs when attempting to download a file from a URL using Ansible, and it can be a stumbling block for many users. In this article, I’ll walk you through the error, demonstrate how to reproduce it, and provide a fix to ensure a smooth Ansible playbook execution.
The destination does not exist
Error
Let’s start by examining the error through a live demo. Below is a simplified Ansible playbook (destinationdoesnotexist_error.yml
) that attempts to download a file using the get_url
module:
---
- name: get_url module demo
hosts: all
become: false
vars:
myurl: "https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz"
mycrc: "sha256:https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz.sha"
mydest: "ansible-2.9.25.tar.gz"
tasks:
- name: download file
ansible.builtin.get_url:
url: "{{ myurl }}"
dest: "{{ mydest }}"
checksum: "{{ mycrc }}"
mode: '0644'
Upon execution, you might encounter the following error:
$ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/destinationdoesnotexist_error.yml
PLAY [get_url module demo] ******************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [demo.example.com]
TASK [download file] ************************************************************************
fatal: [demo.example.com]: FAILED! => {"changed": false, "checksum_dest": null, "checksum_src": "574e24659f555fe370571167d3d44704671f1773", "dest": "ansible-2.9.25.tar.gz", "elapsed": 3, "msg": "Destination does not exist", "src": "/home/devops/.ansible/tmp/ansible-tmp-1640555219.326019-1431-267536126421544/tmpmx_ra0hd", "url": "https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz"}
PLAY RECAP **********************************************************************************
demo.example.com : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
The error message clearly indicates that the destination does not exist.
Reproducing and Fixing the Error
Reproducing the Error
To reproduce the error, we can use the provided playbook (destinationdoesnotexist_error.yml
). This playbook attempts to download the Ansible archive into the home directory, resulting in the “destination does not exist” error.
The Best Resources For Ansible
Certifications
Video Course
Printed Book
eBooks
Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Ansible Cookbook: A Comprehensive Guide to Unleashing the Power of Ansible via Best Practices, Troubleshooting, and Linting Rules with Luca Berton
Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
Ansible Automation Platform By Example: A step-by-step guide for the most common user scenarios
Fixing the Error
Let’s address the issue by modifying the playbook. In the fixed version (destinationdoesnotexist_fix.yml
), we adjust the destination path to include the current directory:
---
- name: get_url module demo
hosts: all
become: false
vars:
myurl: "https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz"
mycrc: "sha256:https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz.sha"
mydest: "ansible-2.9.25.tar.gz"
tasks:
- name: download file
ansible.builtin.get_url:
url: "{{ myurl }}"
dest: "./{{ mydest }}"
checksum: "{{ mycrc }}"
mode: '0644'
Now, when you execute this playbook, you should observe a successful download without encountering the “destination does not exist” error.
$ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/destinationdoesnotexist_fix.yml
PLAY [get_url module demo] ******************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [demo.example.com]
TASK [download file] ************************************************************************
changed: [demo.example.com]
PLAY RECAP **********************************************************************************
demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Verification
To confirm the success, log in to the target machine and check if the file has been downloaded to the specified directory:
$ ssh [email protected]
[devops@demo ~]$ ls -al
total 13964
drwx------. 4 devops wheel 140 Dec 26 21:47 .
...
-rw-r--r--. 1 devops wheel 14280306 Dec 26 21:47 ansible-2.9.25.tar.gz
Recap
In this article, we explored the Ansible “destination does not exist” error, reproduced it in a live demo, and provided a fix. Now you have the knowledge to troubleshoot and overcome this common issue in your Ansible playbooks. If you found this tutorial helpful, consider subscribing for more Ansible tips and tricks. Happy automating!
Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate