Ansible variables

From wikieduonline
Revision as of 12:40, 12 December 2022 by Ant (talk | contribs) (→‎Forcing the data type)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Creating a variable:

vars:
   your_new_variable: your_new_var_value

Using variables, just reference it using {{ }}: [1]

{{ your_new_var_value }}



- name: Execute a command
  ansible.builtin.command: "false"
  debugger: on_failed

Variable attributes[edit]

add, append, as_integer_ratio, bit_length, capitalize, center, clear, conjugate, copy, count, decode, denominator, difference, difference_update, discard, encode, endswith, expandtabs, extend, find, format, fromhex, fromkeys, get, has_key, hex, imag, index, insert, intersection, intersection_update, isalnum, isalpha, isdecimal, isdigit, isdisjoint, is_integer, islower, isnumeric, isspace, issubset, issuperset, istitle, isupper, items, iteritems, iterkeys, itervalues, join, keys, ljust, lower, lstrip, numerator, partition, pop, popitem, real, remove, replace, reverse, rfind, rindex, rjust, rpartition, rsplit, rstrip, setdefault, sort, split, splitlines, startswith, strip, swapcase, symmetric_difference, symmetric_difference_update, title, translate, union, update, upper, values, viewitems, viewkeys, viewvalues, zfill

Forcing the data type[edit]

- ansible.builtin.debug:
     msg: test
  when: some_string_value | bool


- name: YOUR-VAR
  value: "{{ lookup('env','YOUR-ENV-NAME') | string }}"

Related[edit]

See also[edit]

Advertising: