# Newbie: Can't get to the bottom of this error

**URL:** <https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158>\
**Category:** Get Help\
**Created:** [August 29, 2024, 8:41am UTC](https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158 "2024-08-29T08:41:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lb483](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lb483](https://forum.ansible.com/u/lb483)\
**Post date:** [August 29, 2024, 8:41am UTC](https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158/1 "2024-08-29T08:41:33Z")

</div>

I have a playbook which is doing my head in. I’ve abstracted the relevant parts that fail into:

```auto
---
- 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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![lb483](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lb483](https://forum.ansible.com/u/lb483)\
**Post date:** [August 29, 2024, 8:45am UTC](https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158/2 "2024-08-29T08:45:43Z")

</div>

Never mind. Just spotted the “-name” rather than “- name”!

---

<div class="post-metadata">

**Author:** ![gundalow](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gundalow/32/99_2.png) [@gundalow](https://forum.ansible.com/u/gundalow)\
**Post date:** [August 30, 2024, 6:31pm UTC](https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158/3 "2024-08-30T18:31:42Z")

</div>

Glad you got it sorted.  
Depending what text editor you are using, you might be able to enable YAML/Ansible syntax highlighting which can help.

If you use VScode, then the [official Red Hat Ansible VScode plugin](https://marketplace.visualstudio.com/items?itemName=redhat.ansible) is really useful

---

<div class="post-metadata">

**Author:** ![lb483](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lb483](https://forum.ansible.com/u/lb483)\
**Post date:** [August 30, 2024, 8:17pm UTC](https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158/4 "2024-08-30T20:17:24Z")

</div>

Yeah. It was the context-sensitive editor on the forum which highlighted the issue :-/

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 29, 2024, 8:18pm UTC](https://forum.ansible.com/t/newbie-cant-get-to-the-bottom-of-this-error/8158/5 "2024-09-29T20:18:15Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
