YAML syntax error (beginner)

308 views
Skip to first unread message

WS

unread,
Apr 11, 2014, 3:20:04 AM4/11/14
to ansible...@googlegroups.com
Hello

I just started to use ansible so please bear with me. I managed to run a few basic playbooks but I am stuck with the following one (basic as well):

---
- hosts: all
  tasks
:
 
- name: copy bashrc to .bashrc
    action
: copy src=files/bashrc dest=~root/.bashrc backup=yes
 
- name: copy bashrc to .bash_profile
    action
: copy src=files/bashrc dest=~root/.bash_profile backup=yes
 
- name: ensure joe is installed apt
    apt
: pkg=joe state=latest update_cache=yes
   
when: ansible_os_family == "Debian"
 
- name: ensure joe is installed yum
    apt
: name=joe state=latest
   
when: ansible_os_family == "CentOS" or ansible_os_family == "Fedora"



I get the following error when running it:

ERROR: Syntax Error while loading YAML script, commonconfig.yml
Note: The error may actually appear before this position: line 7, column 1


 
- name: copy bashrc to .bash_profile
        action
: copy src=files/bashrc dest=~root/.bash_profile backup=yes


The script runs fine when there is only one name/action pair (the first one).

Sorry if this is obvious but I am just starting with YAML.

James Tanner

unread,
Apr 11, 2014, 12:06:48 PM4/11/14
to ansible...@googlegroups.com
--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4e2abd33-13a7-4489-97eb-8ac4f8e6310f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

It seems like the error is pointing out that action: is not aligned with name:

I'm not sure what editor you are using but perhaps you could replace all tabs with spaces and then make sure things are lined up correctly.

http://stackoverflow.com/questions/11094383/how-can-i-convert-tabs-to-spaces-in-every-file-of-a-directory


Brian Green

unread,
Apr 11, 2014, 2:24:21 PM4/11/14
to ansible...@googlegroups.com
While this may not be the cause of your issues, the following is (or will be) an issue for you.

  
- name: ensure joe is installed yum
    apt
: name=joe state=latest
    
when: ansible_os_family == "CentOS" or ansible_os_family == "Fedora"

change to:

  - name: ensure joe is
 installed yum
    yum
: name=joe state=latest
    
when: ansible_os_family == "CentOS" or ansible_os_family == "Fedora"

WS

unread,
Apr 12, 2014, 10:17:17 AM4/12/14
to ansible...@googlegroups.com
Thank you for your help. I was not aware that tabs are not allowed (I finally RTFM, that is the YAML reference).

Changing this immediately helped.

Reply all
Reply to author
Forward
0 new messages