Difference between revisions of "Ansible variables"
Jump to navigation
Jump to search
↑ https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#referencing-simple-variables
↑ https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#organizing-host-and-group-variables
(4 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
== Forcing the data type == | == Forcing the data type == | ||
* https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html#forcing-the-data-type | * https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html#forcing-the-data-type | ||
+ | - ansible.builtin.debug: | ||
+ | msg: test | ||
+ | [[when:]] some_string_value | [[bool]] | ||
+ | |||
+ | |||
+ | - name: YOUR-VAR | ||
+ | [[value:]] "{{ [[Ansible lookup plugins|lookup]]('env','YOUR-ENV-NAME') | [[string]] }}" | ||
== Related == | == Related == |
Latest revision as of 12:40, 12 December 2022
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]
vars:
- Ansible print and debug examples
- Msg: The task includes an option with an undefined variable.
- DEBUG
--extra-vars
lookup
- Jinja
See also[edit]
Advertising: