1

I am trying to learn ansible and I have coded my first playbook but it gives me the error saying 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 key

The error appears to be in /home/ubuntu/first-playbook.yml: line 13, column 9, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

          state: present
        - name: Start Nginx
        ^ here
---
# YAML documents begin with the document separator ---

- name: Install and Start Nginx
  hosts: all
  become: true
    
  tasks:
    - name: Install Nginx
      apt:
          name: nginx
          state: present
        - name: Start Nginx
          service:
              name: nginx
              state: started

# Three dots indicate the end of a YAML document
...

1 Answer 1

1

You have wrong indentation. This name: Start Nginx is the next task, it should be indented the same level as name: Install Nginx:

---
- name: Install and Start Nginx
  hosts: all
  become: true

  tasks:
    - name: Install Nginx
      apt:
          name: nginx
          state: present
    - name: Start Nginx
      service:
          name: nginx
          state: started
...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .