0

On bash script, I need to pass date as ansible extra variable but getting something single quotes related issues;

...
$DT="03-04-17"
ansible-playbook copy2s3.yml --extra-vars 'cdate={{ "$DT" }}'

and manually ansible-playbook working like

$ ansible-playbook copy2s3.yml --extra-vars 'cdate={{ "03-04-17" }}'

Here I dynamically pass the date on ansible playbook.

  • Try ansible-playbook copy2s3.yml --extra-vars "'cdate={{ 03-04-17 }}'" – cuonglm Apr 4 '17 at 6:48
  • @cuonglm here i need to pass $DT variable on script, manually it's working as you say – Nullpointer Apr 4 '17 at 6:49
  • I mean "'cdate={{ $DT }}'" – cuonglm Apr 4 '17 at 6:54
  • Complete output like 'cdate={{ "03-04-17" }}' but date comes from DT variable. – Nullpointer Apr 4 '17 at 6:56
  • Then it would be "'cdate={{ \"$DT\" }}'" – cuonglm Apr 4 '17 at 6:59
2

ansible-playbook copy2s3.yml --extra-vars 'cdate={{ "$DT" }}'

The ansible-playbook command (repeated above) is not going to see your single quotes anyway. What it would see are the following:

  • arg#1 copyy2s3.yml
  • arg#2 --extra-vars
  • arg#3 cdate={{ "$DT" }}

Note that the $DT will be a literal string and not a shell variable as also those spaces, which will be part of the argument. There are many ways you can do this as has already been shown to you by Cuonglm.

  • 'cdate={{ "'"$DT"'" }}'
  • 'cdate={{ '\""$DT"\"' }}'
  • "cdate={{ \"$DT\" }}"
  • cdate=\{\{\ \""$DT"\"\ \}\}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.