 
		
		
		
		
		
	
			
		
		
			
					
		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 :
What is the difference between :
How ansible interprets each case.
Thank you so much.
 Chetan_Tiwary_
		
			Chetan_Tiwary_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hello @Hamdi_Gabsi !
Thanks for reaching out!
Refer it here : https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-syntax
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html
**************************************************************
Regarding second part :
hosts: 'datacenter*' --> * is interpreted as literal * --> host pattern matching for any host that starts with datacenter.
hosts: "datacenter*" --> wildcard expansion is same as the previous one with ' ' --> which will match the host pattern that starts with the word "datacenter".
 Travis
		
			Travis
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		One more thing to understand here is that you can also do it without any quotes. It will use the * as a wildcard to get anything and pattern match on groups or single hostname. The cool thing about the RHLS and self-paced lab environment is that as @Chetan_Tiwary_ demoed above, you can change up the playbooks a little and experiment and actually see what happens.
The other thing to keep in mind, Ansible is YAML files and YAML is nothing but lists of lists and dictionaries (KEY: VALUE) pairs. What we teach you with the "best practices" for playbook writing is to not have things in "folded" form but to use the expanded form in a playbook. The HOSTS piece of the playbook is the only time we make an exception as we generally see that in folded form on the line instead of the list format with the "-".
 Chetan_Tiwary_
		
			Chetan_Tiwary_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hello @Hamdi_Gabsi !
Thanks for reaching out!
Refer it here : https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-syntax
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html
**************************************************************
Regarding second part :
hosts: 'datacenter*' --> * is interpreted as literal * --> host pattern matching for any host that starts with datacenter.
hosts: "datacenter*" --> wildcard expansion is same as the previous one with ' ' --> which will match the host pattern that starts with the word "datacenter".
 
		
		
		
		
		
	
			
		
		
			
					
		Hello Chetan,
sorry for picking up this old post, but I was not sure about the last part. Perhaps you can explain me better?
"
Regarding second part :
hosts: 'datacenter*' --> * is interpreted as literal * --> host pattern matching for any host that starts with datacenter.
hosts: "datacenter*" --> wildcard expansion is same as the previous one with ' ' --> which will match the host pattern that starts with the word "datacenter".
If I understand correctly if wildcard is double quotes then it can be interpreted by the shell and expanded to all strings in the execution environment that start with datacenter, imagining you don t have any, then only datacenter string will be passed to ansible
While in single quote the asterisk is preserverd in ansible and used for host pattern matching...
IS this correct?
Thank you very much
Miguel
 Chetan_Tiwary_
		
			Chetan_Tiwary_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		@MARAmorim I have corrected the 2nd part, it seems both the patterns work in similar way in host pattern matching , I verified this in ch06s02 RH294 course :
Thanks for your understanding.
 Travis
		
			Travis
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		One more thing to understand here is that you can also do it without any quotes. It will use the * as a wildcard to get anything and pattern match on groups or single hostname. The cool thing about the RHLS and self-paced lab environment is that as @Chetan_Tiwary_ demoed above, you can change up the playbooks a little and experiment and actually see what happens.
The other thing to keep in mind, Ansible is YAML files and YAML is nothing but lists of lists and dictionaries (KEY: VALUE) pairs. What we teach you with the "best practices" for playbook writing is to not have things in "folded" form but to use the expanded form in a playbook. The HOSTS piece of the playbook is the only time we make an exception as we generally see that in folded form on the line instead of the list format with the "-".
 
		
		
		
		
		
	
			
		
		
			
					
		Thank you guys!!
Yeah I wasn t finding any difference between single, double and unquoted host patterns...
Cheers
Miguel
 
		
		
		
		
		
	
			
		
		
			
					
		Thank you so much @Chetan_Tiwary_ for these details.
I think it is clear now.
I appreciate your response.
 Chetan_Tiwary_
		
			Chetan_Tiwary_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Glad it helped @Hamdi_Gabsi ! All the best !
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.