[NetSIG] ansible question - are ansible variables interpreted as strings?
Greg H
greg.horie at gmail.com
Fri Jun 25 12:23:08 EDT 2021
I think it's more of a YAML question, so I checked Wikipedia -
https://en.wikipedia.org/wiki/YAML
YAML autodetects the datatype of the entity, but sometimes one wants to
cast the datatype explicitly. The most common situation is where a
single-word string that looks like a number, boolean or tag requires
disambiguation by surrounding it with quotes or using an explicit datatype
tag.
---
a: 123 # an integer
b: "123" # a string, disambiguated by quotes
c: 123.0 # a float
d: !!float 123 # also a float via explicit data type prefixed
by (!!)
e: !!str 123 # a string, disambiguated by explicit type
f: !!str Yes # a string via explicit type
g: Yes # a boolean True (yaml1.1), string "Yes"
(yaml1.2)
h: Yes we have No bananas # a string, "Yes" and "No" disambiguated by
context.
So I believe Ansible (via YAML) would autodetect this ...
---
my_greeting: Hello World!
... as a string. It looks like I could disambiguate this with quotes, but
in practice I like leaving off the quotes because I find it a bit easier to
read when there are many variables being defined.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://vicpimakers.ca/pipermail/netsig_vicpimakers.ca/attachments/20210625/27d3c677/attachment.htm>
More information about the NetSIG
mailing list