2017-04-27 58 views
0

我寫了下面的Ansible劇本傳輸文件變量時:語法錯誤在Ansible劇本使用

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

但它的使用Ansible變量時給出以下錯誤。如果我們不使用變量,它工作得很好。

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 }}" 

請建議。

回答

2

引用整個字符串:

src: "{{ repofile }}/tomcat_template"