Ansible Pilot

Ansible troubleshooting - Destination does not exist rc 257

How to troubleshoot the error “Destination does not exist”, return code 257 enabling PasswordAuthentication for SSH using Ansible lineinfile module.

July 11, 2022
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

Today we’re going to talk about Ansible troubleshooting, specifically about the “Destination does not exist” message, “return code 257”.

This fatal error message happens when we are trying to edit a file that doesn’t exist on the target file system. The root cause could be a misspelled file or not existing at all.

These circumstances are usually related to Ansible Playbook or Ansible configuration.

I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

The Best Resources For Ansible

Video Course

Printed Book

eBooks

demo

The best way of talking about Ansible troubleshooting is to jump in a live demo to show you practically the “Destination does not exist”, return code 257, and how to solve it!

This demo is going to try to edit a configuration file “/etc/ssh/sshd_config” misspelled on our target system.

error code

---
- name: PasswordAuthentication enabled
  hosts: all
  become: true
  gather_facts: false
  tasks:
    - name: ssh PasswordAuthentication
      ansible.builtin.lineinfile:
        dest: /etc/ssh/sshd_config2
        regexp: '^PasswordAuthentication'
        line: "PasswordAuthentication yes"
        state: present
      notify: ssh restart
  handlers:
    - name: ssh restart
      ansible.builtin.service:
        name: sshd
        state: restarted

error execution

$ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/destinationdoesnotexist_257_error.yml

PLAY [PasswordAuthentication enabled] *************************************************************
TASK [ssh PasswordAuthentication] *****************************************************************
fatal: [demo.example.com]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "msg": "Destination /etc/ssh/sshad_config2 does not exist !", "rc": 257}
PLAY RECAP ****************************************************************************************
demo.example.com           : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

fix code

---
- name: PasswordAuthentication enabled
  hosts: all
  become: true
  gather_facts: false
  tasks:
    - name: ssh PasswordAuthentication
      ansible.builtin.lineinfile:
        dest: /etc/ssh/sshd_config
        regexp: '^PasswordAuthentication'
        line: "PasswordAuthentication yes"
        state: present
      notify: ssh restart
   handlers:
    - name: ssh restart
      ansible.builtin.service:
        name: sshd
        state: restarted

fix execution

$ ansible-playbook -i virtualmachines/demo/inventory edit\ single-line\ text/enable_password_auth.yml
PLAY [PasswordAuthentication enabled] *************************************************************
TASK [ssh PasswordAuthentication] *****************************************************************
changed: [demo.example.com]
RUNNING HANDLER [ssh restart] *********************************************************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com           : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

verification

$ ssh [email protected]
[devops@demo ~]$ sudo su
[root@demo devops]# grep 'PasswordAuthentication yes' /etc/ssh/sshd_config 
#PasswordAuthentication yes
PasswordAuthentication yes
[root@demo devops]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-07-11 08:49:05 UTC; 56s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 5106 (sshd)
    Tasks: 1 (limit: 4952)
   Memory: 2.8M
   CGroup: /system.slice/sshd.service
           └─5106 /usr/sbin/sshd -D -u0 -oCiphers=[email protected],chacha20-poly1305@openssh>

Jul 11 08:49:05 demo.example.com systemd[1]: sshd.service: Succeeded.
Jul 11 08:49:05 demo.example.com systemd[1]: Stopped OpenSSH server daemon.
Jul 11 08:49:05 demo.example.com systemd[1]: Starting OpenSSH server daemon...
Jul 11 08:49:05 demo.example.com sshd[5106]: Server listening on 0.0.0.0 port 22.
Jul 11 08:49:05 demo.example.com sshd[5106]: Server listening on :: port 22.
Jul 11 08:49:05 demo.example.com systemd[1]: Started OpenSSH server daemon.
Jul 11 08:49:29 demo.example.com sshd[5123]: Accepted publickey for devops from 192.168.43.5 port >
Jul 11 08:49:29 demo.example.com sshd[5123]: pam_unix(sshd:session): session opened for user devop>
[root@demo devops]#

code with ❤️ in GitHub

Recap

Now you know better how to troubleshoot the Ansible destination does not exist error, return code 257 and solve it! 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

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases