syntax error in vars bubstution [ shell module ]

107 views
Skip to first unread message

olga

unread,
Oct 8, 2014, 3:41:46 PM10/8/14
to ansible...@googlegroups.com
Hi,

---
- hosts: service
  vars:
    app_service_port: 8080
    tomcat_home: /opt/apache-tomcat-8.0.9
  remote_user: deploy
  tasks:
  - name: stop tomcat
    shell: {{ tomcat_home }}/bin/shutdown.sh
  - name: start tomcat
    shell: {{ tomcat_home }}/bin/startup.sh

When i run this play, i get

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

  tasks:
  - shell: {{ tomcat_home}}/bin/shutdown.sh

is variable substitution not allowed in shell module. 

These are custom installed tomcat dir, so i have to use shell command to start and stop the tomcat. Also, has anyone verified if the java process got killed. I have seen some times that after shutdown, the java process still run. OR is there any easy method in ansible to do this.

Thanks,
olaga

Michael Peters

unread,
Oct 8, 2014, 4:03:15 PM10/8/14
to ansible...@googlegroups.com
Try quoting the templated part. The {{ }} syntax markers mess up the
yaml parsing - http://docs.ansible.com/YAMLSyntax.html#gotchas
> --
> 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/72a6af6d-d972-4747-bb6f-21eb0c63350b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

olga

unread,
Oct 10, 2014, 5:24:24 AM10/10/14
to ansible...@googlegroups.com
Hi Michael,

Quoting also did not work. I added "sh" before the {{ and it worked.

  tasks:
  - name: stop tomcat
    shell: sh {{ tomcat_home }}/bin/shutdown.sh
  - name: start tomcat
    shell: sh {{ tomcat_home }}/bin/startup.sh

Thanks for the link.

Regards,
Olga

Michael DeHaan

unread,
Oct 13, 2014, 4:50:18 PM10/13/14
to ansible...@googlegroups.com
"Quoting also did not work. I added "sh" before the {{ and it worked."

Please show me what you tried and what the output was?

Thanks!


Subramanian Olagappan

unread,
Oct 15, 2014, 12:21:01 PM10/15/14
to ansible...@googlegroups.com
Hi Michael,

---
- hosts: service
  vars:
    app_service_port: 8080
    tomcat_home: /opt/apache-tomcat-8.0.9
  remote_user: deploy
  tasks:
  - name: stop tomcat
    shell: "{{ tomcat_home }}"/bin/shutdown.sh
  - name: start tomcat
    shell: "{{ tomcat_home }}"/bin/startup.sh

olga@olga-vbox:~$ ansible-playbook test.yml
ERROR: Syntax Error while loading YAML script, test.yml
Note: The error may actually appear before this position: line 7, column 31
  - name: stop tomcat
    shell: "{{ tomcat_home }}"/bin/shutdown.sh
                                            ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:           
    with_items:
      - {{ foo }}
Should be written as:
    with_items:
      - "{{ foo }}"     

Thanks,
Olga

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/n5jvt2qOI9I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Michael Peters

unread,
Oct 15, 2014, 12:25:11 PM10/15/14
to ansible...@googlegroups.com
You need to quote the whole line, not just the templated part:

---
- hosts: service
vars:
app_service_port: 8080
tomcat_home: /opt/apache-tomcat-8.0.9
remote_user: deploy
tasks:
- name: stop tomcat
shell: "{{ tomcat_home }}/bin/shutdown.sh"
- name: start tomcat
shell: "{{ tomcat_home }}/bin/startup.sh"

> https://groups.google.com/d/msgid/ansible-project/CAKQjojRVtsDjw1mVLiqQvnJfei4kujgN74UMatjuck5%2Bi5fRHQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages