Skip to content

Instantly share code, notes, and snippets.

@Kagee
Created June 11, 2020 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kagee/78060dee9db1d5c8f9be1d4bd41ca1ea to your computer and use it in GitHub Desktop.
Save Kagee/78060dee9db1d5c8f9be1d4bd41ca1ea to your computer and use it in GitHub Desktop.
- name: loop test
gather_facts: no
hosts: localhost
vars:
- array_usage:
- id: 0
usage: 89
- id: 1
usage: 70
- id: 2
usage: 24
- id: 3
usage: 33
tasks:
- debug:
msg: "{{ array_usage }}"
- name: Set min cap
set_fact:
use_capacity: "{{ array_usage | map(attribute='usage') | list | min }}"
PLAY [loop test] *************************************************************************************************************************************************************************************************************************************************************************
TASK [debug] *****************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
{
"id": 0,
"usage": 89
},
{
"id": 1,
"usage": 70
},
{
"id": 2,
"usage": 24
},
{
"id": 3,
"usage": 33
}
]
}
TASK [Set initial capacity fact] *********************************************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [debug] *****************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
"24"
]
}
PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment