Syntax error in Ansible playbook when using variables

时间:2017-04-27 06:59:16

标签: ansible rhel

I have written the following Ansible playbook to transfer files:

---
- hosts: webservers
  vars:
     appname: myapp
     repofile: /etc/ansible/packagerepo/scripts/
  become: yes
  tasks:
     - name: Copy tomcat template file.
       copy:
       src: "{{ repofile }}"/tomcat_template.sh
       dest: /apps/bin/tomcat_template.sh

     - name: Copy App template file
       copy:
       src: "{{ repofile }}"/app_template
       dest: /etc/init.d/app_template

But it's giving the following error when using Ansible variables. If we do not use variables, it works absolutely fine.

   The offending line appears to be:

     #src: /etc/ansible/packagerepo/scripts/tomcat_template.sh
     src: "{{ repofile }}"/tomcat_template.sh
                          ^ here
 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 }}"

Please suggest.

1 个答案:

答案 0 :(得分:2)

引用整个字符串:

src: "{{ repofile }}/tomcat_template"