# playbook syntax

**URL:** <https://forum.ansible.com/t/playbook-syntax/23500>\
**Category:** Ansible Project\
**Created:** [January 19, 2017, 1:20am UTC](https://forum.ansible.com/t/playbook-syntax/23500 "2017-01-19T01:20:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Batie](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Alan\_Batie](https://forum.ansible.com/u/Alan_Batie)\
**Post date:** [January 19, 2017, 1:20am UTC](https://forum.ansible.com/t/playbook-syntax/23500/1 "2017-01-19T01:20:42Z")

</div>

I’m giving ansible a try, and it seems the examples aren’t quite right - using authorized\_keys as a starting point:

[http://docs.ansible.com/ansible/authorized\_key\_module.html](http://docs.ansible.com/ansible/authorized_key_module.html)

# cat e.yml

- name: Set authorized key took from file  
authorized\_key:  
user: charlie  
state: present  
key: “{{ lookup(‘file’, ‘/home/charlie/.ssh/id\_rsa.pub’) }}”

# ansible-playbook e.yml

ERROR! ‘authorized\_key’ is not a valid attribute for a Play

The error appears to have been in ‘/etc/ansible/e.yml’: line 1, column 3, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Set authorized key took from file  
^ here

I use a yaml syntax validator, which didn’t like the comment after name: but removing that doesn’t change anything.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 19, 2017, 6:04pm UTC](https://forum.ansible.com/t/playbook-syntax/23500/2 "2017-01-19T18:04:12Z")

</div>

You have not created a playbook, effectively you have only created a tasks file. A playbook will have a `hosts` declaration, and all tasks will be under a `tasks` section.

See [http://docs.ansible.com/ansible/playbooks\_intro.html#playbook-language-example](http://docs.ansible.com/ansible/playbooks_intro.html#playbook-language-example) for more information.

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [January 19, 2017, 7:54pm UTC](https://forum.ansible.com/t/playbook-syntax/23500/3 "2017-01-19T19:54:07Z")

</div>

PS: Alan Batie of Agora fame?

---

<div class="post-metadata">

**Author:** ![Alan\_Batie](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Alan\_Batie](https://forum.ansible.com/u/Alan_Batie)\
**Post date:** [January 19, 2017, 8:26pm UTC](https://forum.ansible.com/t/playbook-syntax/23500/4 "2017-01-19T20:26:37Z")

</div>

It’s still not happy with it:

# ansible-playbook e.yml --list-hosts

ERROR! Syntax Error while loading YAML.

The error appears to have been in ‘/etc/ansible/e.yml’: line 5, column 1, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

authorized\_key:  
user: charlie  
^ here

# cat e.yml

- hosts: all  
tasks:
- name: Make sure admin03 root ssh key is present  
authorized\_key:  
user: charlie  
state: present  
key: “{{ lookup(‘file’, ‘/home/charlie/.ssh/id\_rsa.pub’) }}”

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 19, 2017, 8:41pm UTC](https://forum.ansible.com/t/playbook-syntax/23500/5 "2017-01-19T20:41:03Z")

</div>

A direct copy paste from your email works without problems for me:

$ ansible-playbook e.yml --list-hosts --list-tasks

playbook: e.yml

play #1 (all): all TAGS:   
pattern: [u’all’]  
hosts (1):  
localhost  
tasks:  
Make sure admin03 root ssh key is present TAGS:

I’m not sure if maybe you have tabs, or mixed indentation that didn’t translate via email? Generally speaking, make sure you only uses spaces in YAML.

---

<div class="post-metadata">

**Author:** ![Alan\_Batie](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Alan\_Batie](https://forum.ansible.com/u/Alan_Batie)\
**Post date:** [January 19, 2017, 9:17pm UTC](https://forum.ansible.com/t/playbook-syntax/23500/6 "2017-01-19T21:17:01Z")

</div>

Tabs were it, arrgh. Thanks!
