Ansible error: File is absent cannot continue

File is absent cannot continue

This error usually happens on using the Ansible file module. It will throw an error if the path does not exist or if the path is not a file.

For example,

- name: check file that doesn't exist with state file
  file:
    path: /tmp/test.txt
    state: file

Here we are using the "state: file" in the playbook. It will throw an error if the path does not exist or if the path is not a file.

In-order to resolve this issue, we need to use state: touch.

For Example,

- name: check file that doesn't exist with state touch
  file:
    path: /tmp/test.txt
    state: touch

This will create an empty file if a path does not exist and will not throw an error if the path is a directory or symlink.

That's all…

Leave a Reply

Your email address will not be published. Required fields are marked *