# Syntax Error while loading YAML.

**URL:** <https://forum.ansible.com/t/syntax-error-while-loading-yaml/23837>\
**Category:** Ansible Project\
**Tags:** ubuntu, aws\
**Created:** [February 28, 2017, 5:24am UTC](https://forum.ansible.com/t/syntax-error-while-loading-yaml/23837 "2017-02-28T05:24:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pankaj\_Navneet](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pankaj\_Navneet](https://forum.ansible.com/u/Pankaj_Navneet)\
**Post date:** [February 28, 2017, 5:24am UTC](https://forum.ansible.com/t/syntax-error-while-loading-yaml/23837/1 "2017-02-28T05:24:36Z")

</div>

Hi All,

I have written a YAML to install Nginx on my AWS Slave server. But every time i got below error while running my playbook. I googled to resolve this issue, but unable to do so. Can you guys help me in sorting what i am doing wrong here. I am using Ubuntu 16 and my YAML is,

**- hosts: AWS\_Slave**  
**tasks:**  
**- name: nginx**  
**apt\_key: url=[http://nginx.org/keys/nginx\_signing.key](http://nginx.org/keys/nginx_signing.key) state=present**

**- name: nginx | Adding sources.list deb url for nginx**  
**lineinfile: dest=/etc/apt/sources.list line=“deb [http://nginx.org/packages/mainline/ubuntu/](http://nginx.org/packages/mainline/ubuntu/) xenial nginx”**

**- name: nginx | Updating apt cache**  
**apt:**  
**update\_cache: yes**

**- name: nginx | Installing nginx**  
**apt:**  
**pkg: nginx**  
**state: latest**

**- name: nginx | Starting nginx**  
**service:**  
**name: nginx**  
**state: started**

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 28, 2017, 8:09am UTC](https://forum.ansible.com/t/syntax-error-while-loading-yaml/23837/2 "2017-02-28T08:09:41Z")

</div>

> Hi All,
> 
> I have written a YAML to install Nginx on my AWS Slave server. But every  
> time i got below error while running my playbook. I googled to resolve this  
> issue, but unable to do so. Can you guys help me in sorting what i am doing  
> wrong here. I am using Ubuntu 16 and my YAML is,

In YAML indentation is very important, and you need to be consistent in the indentation.

> - hosts: AWS\_Slave  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt\_key: url=[http://nginx.org/keys/nginx\_signing.key](http://nginx.org/keys/nginx_signing.key) state=present
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Adding sources.list deb url for nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineinfile: dest=/etc/apt/sources.list line="deb  
> [http://nginx.org/packages/mainline/ubuntu/](http://nginx.org/packages/mainline/ubuntu/) xenial nginx"
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Updating apt cache  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update\_cache: yes
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Installing nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pkg: nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: latest
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Starting nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: started

Here is an example with indentation that should work.

- hosts: AWS\_Slave  
&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt\_key: url=[http://nginx.org/keys/nginx\_signing.key](http://nginx.org/keys/nginx_signing.key) state=present

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Adding sources.list deb url for nginx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineinfile: dest=/etc/apt/sources.list line="deb [http://nginx.org/packages/mainline/ubuntu/](http://nginx.org/packages/mainline/ubuntu/) xenial nginx"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Updating apt cache  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update\_cache: yes

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Installing nginx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pkg: nginx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: latest

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx | Starting nginx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: nginx  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: started

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [February 28, 2017, 2:49pm UTC](https://forum.ansible.com/t/syntax-error-while-loading-yaml/23837/3 "2017-02-28T14:49:08Z")

</div>

> In YAML indentation is very important, and you need to be consistent  
> in the indentation.

Also, all indentation should be space characters, not tabs.

(If you've got tabs in your playbook, could Ansible catch that and  
identify the problem more clearly than it currently does?)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)  
This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
