- name: Check desktop file exists ansible.builtin.stat: path: "{{ item }}" register: p - name: Edit desktop file ansible.builtin.lineinfile: path: "{{ item }}" insertafter: '^Type' line: 'NoDisplay=true' firstmatch: true state: present become: true when: p.stat.exists - debug: msg: "Warning - {{ item }} does not exist" when: p.stat.exists == False