Working with Variables
Learn the different types of variables and the various ways to define and utilize them in Ansible.
We'll cover the following
Variable types
Variables can be of different types, including the following:
- Basic type variables, such as strings, integers, booleans, lists, and dictionaries.
- Nested variables.
- Null variables.
- Magic variables.
- Connection variables.
- Facts.
Basic types
- Strings: These variables are used to store and manipulate text-based data. Strings can be defined using single (
' '
) or double (" "
) quotes. In the following example, we’re using thename
variable to store theMy name
string value, thedocker_version
variable to store a string value of20.10.14
, and also thepackage_name
variable to store thecurl
value:
Note: Simple strings without special characters or spaces do not have to be enclosed within quotes.
Get hands-on with 1400+ tech skills courses.