chore(ansible): add sources, add max/min examples

This commit is contained in:
Michele Cereda
2025-09-24 00:23:14 +02:00
parent 3a2396a112
commit 072356dd88
2 changed files with 10 additions and 0 deletions

View File

@@ -1796,6 +1796,8 @@ Another _better (?)_ solution in playbooks/roles would be to sanitize the input
- [Ansible Map Examples - Filter List and Dictionaries]
- [Advanced playbook syntax]
- [Ansible delegation madness: delegate_to and variable substitution]
- [Tim Grützmacher's Ansible best practices]
- [set_fact vs set_stats]
<!--
Reference
@@ -1886,6 +1888,8 @@ Another _better (?)_ solution in playbooks/roles would be to sanitize the input
[only do something if another action changed]: https://raymii.org/s/tutorials/Ansible_-_Only-do-something-if-another-action-changed.html
[removing empty values from a list and assigning it to a new list]: https://stackoverflow.com/questions/60525961/ansible-removing-empty-values-from-a-list-and-assigning-it-to-a-new-list#60526774
[running your ansible playbooks in parallel and other strategies]: https://toptechtips.github.io/2023-06-26-ansible-parallel/
[set_fact vs set_stats]: https://gregsowell.com/?p=7540
[Tim Grützmacher's Ansible best practices]: https://timgrt.github.io/Ansible-Best-Practices/
[unique filter of list in jinja2]: https://stackoverflow.com/questions/44329598/unique-filter-of-list-in-jinja2
[what is the exact list of ansible setup min?]: https://stackoverflow.com/questions/71060833/what-is-the-exact-list-of-ansible-setup-min#71061125
[Why Ansible and Python fork break on macOS High Sierra+ and how to solve]: https://ansiblepilot.medium.com/why-ansible-and-python-fork-break-on-macos-high-sierra-and-how-to-solve-d11540cd2a1b

View File

@@ -1,5 +1,7 @@
---
# Refer <https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html>.
- name: Convert between types
tags:
- convert_types
@@ -264,6 +266,10 @@
- manipulate_numbers
- number_manipulation
ansible.builtin.set_fact:
max_of_n: "{{ [ 3, 4, 2 ] | max }}"
max_of_values: "{{ [{'val': 1}, {'val': 2}] | max(attribute='val') }}"
min_of_n: "{{ [ 3, 4, 2 ] | min }}"
min_of_values: "{{ [{'val': 1}, {'val': 2}] | min(attribute='val') }}"
round: "{{ 42.21 | round }}"
round_up: "{{ 42.21 | round(method='ceil') }}"
round_down_to_2nd_decimal: "{{ (2.5 * (42.2109 / 3) + 1) | round(2, 'floor') }}"