• 1,629 Views

Interpretation of single- double quoted value

Jump to solution

Hi ,

I started my RH294 training, and I am a little bit confused about the interpretation of single- double quoted value in Ansible.

When should I use : 

  • "{{ my_var }}"
  • {{ my_var }}
  • '{{my_var }}'

What is the difference between :

  • hosts: 'datacenter*'
  • hosts: "datacenter*"

How ansible interprets each case.

Thank you so much.

1 Solution

Accepted Solutions
Chetan_Tiwary_
Moderator
Moderator
  • 1,599 Views

Hello @Hamdi_Gabsi !

Thanks for reaching out!

Refer it here : https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-syntax 

Chetan_Tiwary__0-1692025099958.png

https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html 

  1. "{{ my_var }}" --> case of variable interpolation or Dynamic Injection. Use it when you want to use the actual value of the variable during execution in a string or a command.
  2.  '{{ my_var }}' --> case of literal string or Static Injection. No variable interpolation ( means no variable substitution ) is done here. Use it when you want the origial placeholder text rather than it's value. 
  3. {{ my_var }} --> same as the first one but generally used for larger strings.

**************************************************************

Regarding second part : 

hosts: 'datacenter*' --> * is interpreted as literal * --> host pattern matching for any host that starts with datacenter.


hosts: "datacenter*" --> wildcard expansion is allowed here --> which will match any string that contains the word "datacenter".

 

View solution in original post

3 Replies
Chetan_Tiwary_
Moderator
Moderator
  • 1,600 Views

Hello @Hamdi_Gabsi !

Thanks for reaching out!

Refer it here : https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-syntax 

Chetan_Tiwary__0-1692025099958.png

https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html 

  1. "{{ my_var }}" --> case of variable interpolation or Dynamic Injection. Use it when you want to use the actual value of the variable during execution in a string or a command.
  2.  '{{ my_var }}' --> case of literal string or Static Injection. No variable interpolation ( means no variable substitution ) is done here. Use it when you want the origial placeholder text rather than it's value. 
  3. {{ my_var }} --> same as the first one but generally used for larger strings.

**************************************************************

Regarding second part : 

hosts: 'datacenter*' --> * is interpreted as literal * --> host pattern matching for any host that starts with datacenter.


hosts: "datacenter*" --> wildcard expansion is allowed here --> which will match any string that contains the word "datacenter".

 

  • 1,593 Views

Thank you so much  @Chetan_Tiwary_  for these details.

I think it is clear now.

I appreciate your response.

Chetan_Tiwary_
Moderator
Moderator
  • 1,582 Views

Glad it helped @Hamdi_Gabsi ! All the best !

Join the discussion
You must log in to join this conversation.