如何将变量与ansible脚本中的路径连接起来

时间:2017-09-22 10:36:59

标签: python windows ansible

我创建了一个Ansible脚本来下载PuTTY并在Windows上安装它。

- hosts: windows
  tasks:
     - name: Download Zip File
       win_get_url:
         url: "{{zipurl}}"
         dest: "{{myvarfile}}"
     - name: Extract zipfile
       win_unzip:
         src: "{{myvarfile}}"
         dest: "C:\{{packagename}}"
         recurse: yes
         rm: true

然后:

ansible-playbook deploywar.yml \
  --extra-vars="myvarfile=c:\putty.zip zipurl=https://the.earth.li/~sgtatham/putty/latest/w64/putty.zip packagename=putty"

现在我需要将包名称作为参数传递,并需要在:

中连接
dest: "C:\\{{packagename}}"

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

使用单引号:

dest: 'C:\{{packagename}}'

或转义特殊字符:

dest: "C:\\{{packagename}}"