syntax error while loading yaml script

1,230 views
Skip to first unread message

ansible_novice

unread,
Oct 5, 2015, 8:05:31 AM10/5/15
to Ansible Project
I`m trying to launch one playbook:

 ---
 - hosts:group1
   user:user1
   sudo:yes
   gather_facts:yes

 tasks:
 - name: ensure update
   apt:update_cache=yes
   apt:upgrade=full

I`m running this by command sudo ansible-playbook -i /etc/ansible/hosts test1.yml and Ansible said that my playbook has syntax error.

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


 tasks:
        ^

Maybe someone had similar problem, who knows, what is the reason of error, give me an answer, please.

Brian Coca

unread,
Oct 5, 2015, 8:09:53 AM10/5/15
to Ansible Project
it should look like this

tasks:
- name: ensure update
apt:update_cache=yes
- apt:upgrade=full

You cannot have multiple tasks per task, name is optional but - is not
as it indicates when the 'next task' starts


--
Brian Coca

ansible_novice

unread,
Oct 6, 2015, 3:33:23 AM10/6/15
to Ansible Project
Ok, now I have another code in playbook

 ---
 - hosts:group1
   user:chinkovm
   sudo:yes
   gather_facts:yes

tasks:
 - name: ensure update
   apt:update_cache=yes
 - name: ensure upgrade
   apt:upgrade=full

But ansible says about the same error in the same place: in colon of word 'tasks'.

David Karban

unread,
Oct 6, 2015, 3:42:17 AM10/6/15
to ansible...@googlegroups.com
Hi, 

tasks should have more spaces, it should be aligned to user, sudo, etc. keywords:

---
- hosts:group1
  user:chinkovm
  sudo:yes
  gather_facts:yes
  tasks:
   - name: ensure update
     apt:update_cache=yes
   - name: ensure upgrade
     apt:upgrade=full

David Karban
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

--
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/ece77445-7464-444e-b6a3-b477fd863f91%40googlegroups.com.

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

pixel fairy

unread,
Oct 6, 2015, 7:37:29 AM10/6/15
to Ansible Project
theres an intro to yaml syntax here. http://docs.ansible.com/ansible/YAMLSyntax.html

be carefull cutting and pasting from groups because things can get reformatted. heres an example with the code highlighting. i hope it comes out ok. also, you can put multiple variables in a single module call like this.

---
- hosts: group1
  user
: user1
  sudo
: yes
  gather_facts
: yes

  tasks
:
 
- name: ensure
update
    apt
: update_cache=yes upgrade=full cache_valid_time=3600


ansible_novice

unread,
Oct 6, 2015, 8:40:35 AM10/6/15
to Ansible Project
I`m trying to run your example, but I have a message of error again. Now this is another position. I thougth there could be a problem with spaces, but changes doesn`t work too.


ERROR: Syntax Error while loading YAML script, test1.yml
Note: The error may actually appear before this position: line 10, column 1
    apt:update_cache=yes upgrade=full cache_valid_time=3600
^

Brian Coca

unread,
Oct 6, 2015, 8:42:11 AM10/6/15
to Ansible Project
you need a space after :

apt: update_cache=yes upgrade=full cache_valid_time=3600



--
Brian Coca

ansible_novice

unread,
Oct 7, 2015, 3:47:32 AM10/7/15
to Ansible Project
Thank you. Now playbook doesn`t have syntax errors, but I have a permission error.


PLAY [group1] *****************************************************************

GATHERING FACTS ***************************************************************
<172.17.251.236> ESTABLISH CONNECTION FOR USER: user1
<172.17.251.236> REMOTE_MODULE setup
<172.17.251.236> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=user1 -o ConnectTimeout=10 172.17.251.236 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1444203780.43-167481022998325 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1444203780.43-167481022998325 && echo $HOME/.ansible/tmp/ansible-tmp-1444203780.43-167481022998325'
fatal: [172.17.251.236] => SSH Error: Permission denied (publickey,password).
    while connecting to 172.17.251.236:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

TASK: [ensure update] *********************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/test1.retry

172.17.251.236             : ok=0    changed=0    unreachable=1    failed=0


I guess there might ba problem with SSH key and I have to make it and save in directory /root/.ansible/cp/. But SSH agent can`t open a connection to my authentication agent. Do you know, where does the trouble lie?

Reply all
Reply to author
Forward
0 new messages