playbook syntax

353 views
Skip to first unread message

Alan Batie

unread,
Jan 19, 2017, 1:00:18 PM1/19/17
to Ansible Project
I'm giving ansible a try, and it seems the examples aren't quite right - using authorized_keys as a starting point:


# 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.

Matt Martz

unread,
Jan 19, 2017, 1:05:00 PM1/19/17
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ed0e9120-542d-46c6-8feb-e6c5a40d9c5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Matt Davis

unread,
Jan 19, 2017, 2:54:08 PM1/19/17
to Ansible Project
PS: Alan Batie of Agora fame? 

Alan Batie

unread,
Jan 19, 2017, 3:26:38 PM1/19/17
to Ansible Project


On Thursday, January 19, 2017 at 10:05:00 AM UTC-8, Matt Martz wrote:
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.

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

Matt Martz

unread,
Jan 19, 2017, 3:41:52 PM1/19/17
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Alan Batie

unread,
Jan 19, 2017, 4:17:01 PM1/19/17
to Ansible Project
Tabs were it, arrgh.  Thanks!
Reply all
Reply to author
Forward
0 new messages