I have a playbook which is doing my head in. I’ve abstracted the relevant parts that fail into:
---
- name: dummy playbook
block:
- name: do a check
block:
- name: check if copy required
lineinfile:
path: /tmp/myfile
regexp: '^copy=yes'
state: present
check_mode: yes
register: copy_needed
failed_when: (copy_needed is changed)
-name: copy the file
copy:
src: ex.cmd
dest: /tmp/ex.cmd
mode: 0500
rescue:
- name: no copy required
debug:
msg: 'copy not needed'
(this isn’t the functionality but it’s failing with the same error)
The requirement is:
- check if a matching line exists in a file
- if it does, stop processing this block but don’t fail the entire playbook
- if it doesn’t, copy a file
The error I’m getting is:
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
did not find expected '-' indicator
The error appears to be in '/home/ansible/ansible/roles/progress_odbc/tasks/main.yml': line 15, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
-name: copy the file
^ here
Could someone point me to the what I’m missing here? Thanks.