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
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
* https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html | * https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html | ||
− | Creating a variable: | + | Creating a [[variable]]: |
[[vars:]] | [[vars:]] | ||
your_new_variable: your_new_var_value | your_new_variable: your_new_var_value | ||
+ | |||
+ | [[Using variables]], just reference it using <code><nowiki>{{ }}</nowiki></code>: <ref>https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#referencing-simple-variables</ref> | ||
+ | <nowiki>{{ your_new_var_value }}</nowiki> | ||
+ | |||
Line 13: | Line 17: | ||
ansible.builtin.command: "false" | ansible.builtin.command: "false" | ||
[[debugger:]] [[on_failed]] | [[debugger:]] [[on_failed]] | ||
+ | |||
+ | == Variable attributes == | ||
+ | <code>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</code> | ||
+ | |||
+ | == 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 == | ||
Line 20: | Line 37: | ||
* [[DEBUG]] | * [[DEBUG]] | ||
* <code>[[--extra-vars]]</code> | * <code>[[--extra-vars]]</code> | ||
+ | * <code>[[Ansible lookup plugins|lookup]]</code> | ||
+ | * [[Jinja]] | ||
== See also == | == See also == |
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: