just wanted to ask, howo I can evaluate the type of any variable in ansible (jinja templates) easily. The specific case is, that I have vars in memory that look like this:
"DEFAULT_BACKUPPATH": "/backup",
"DEFAULT_BACKUPTYPE": "rsync",
"DEFAULT_ZIP_BACKUP": "0",
"DEFAULT_DD_BACKUP_SAVE_USED_PARTITIONS_ONLY": 0,
"DEFAULT_KEEPBACKUPS": "3",
"DEFAULT_KEEPBACKUPS_DD": 0,
"DEFAULT_KEEPBACKUPS_DDZ": 0,
"DEFAULT_KEEPBACKUPS_TAR": 0,
(as you can see there are STRINGS and NUMBERS) and now I want to use them in a template. In the template I need to have quotes around strings and nothing around numbers, as it´s fairly common.
the source is a yaml that looks like this (and I include it with include_vars)
# path to store the backupfile
DEFAULT_BACKUPPATH: "/backup"
# type of backup: dd, tar or rsync
DEFAULT_BACKUPTYPE: "rsync"
# zip tar or dd backup
DEFAULT_ZIP_BACKUP: "0"
# dd backup will save space used by partitions only
DEFAULT_DD_BACKUP_SAVE_USED_PARTITIONS_ONLY: 0
# how many backups to keep
DEFAULT_KEEPBACKUPS: "3"
the template module of ansible strips all and just displaying the value without regarding the type:
DEFAULT_BACKUPPATH=/backup
DEFAULT_BACKUPTYPE=rsync
DEFAULT_ZIP_BACKUP=0
DEFAULT_DD_BACKUP_SAVE_USED_PARTITIONS_ONLY=0
DEFAULT_KEEPBACKUPS=3
DEFAULT_KEEPBACKUPS_DD=0
DEFAULT_KEEPBACKUPS_DDZ=0
Template is fairly straight forward:
DEFAULT_BACKUPPATH={{ DEFAULT_BACKUPPATH }}
DEFAULT_BACKUPTYPE={{ DEFAULT_BACKUPTYPE }}
DEFAULT_ZIP_BACKUP={{ DEFAULT_ZIP_BACKUP }}
DEFAULT_DD_BACKUP_SAVE_USED_PARTITIONS_ONLY={{ DEFAULT_DD_BACKUP_SAVE_USED_PARTITIONS_ONLY }}
DEFAULT_KEEPBACKUPS={{ DEFAULT_KEEPBACKUPS }}
DEFAULT_KEEPBACKUPS_DD={{ DEFAULT_KEEPBACKUPS_DD }}
DEFAULT_KEEPBACKUPS_DDZ={{ DEFAULT_KEEPBACKUPS_DDZ }}
I don´t want to specify for every variable in template which type is should have. The angine could get this from the source, but how ?
Many thanks in advance and Greetings