0

Im using ansible 2.9.2, i have a playbook that copys a file to a virtual machine in a vcenter, i need to put a var in a string :

   somevar = home
   dest: 'c:\Users\"{{ somevar }}"\Desktop\test'

This way didnt work, the error i get :

msg = 'A specified parameter was not correct

I want to get it like this :

  dest: 'c:\Users\home\Desktop\test'

How can i do it ? Thanks

Batchen Regev
  • 685
  • 1
  • 7
  • 28

1 Answers1

0

Try the below code

vars:
  somevar: home
tasks:
  - name: some task
    dest: "c:\Users\{{ somevar }}\Desktop\test"

Always use double quotes for variable interpolation for the whole line

Nitish
  • 597
  • 1
  • 4
  • 9
  • `dest: "c:\Users\{{ somevar }}\Desktop\test" ^ 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` – Batchen Regev Jan 09 '20 at 09:26
  • @BatchenRegev I assume you have defined the variable under vars in your playbook. I'm updating my answer. – Nitish Jan 09 '20 at 09:47
  • Use double backslash. `dest: "c:\\Users\\{{ somevar }}\\Desktop\\test"` – Nitish Jan 09 '20 at 10:48