user2439278
user2439278

Reputation: 1214

how to concatenate variable with the path in ansible script

I have created an Ansible script to download PuTTY and install it on 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

Then:

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

now i need to pass the package name as parameter and need to concatenate in:

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

How can I achieve this?

Upvotes: 0

Views: 3274

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68269

Either use single quotes:

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

or escape special characters:

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

Upvotes: 1

Related Questions