I have a input
"storage_details_test_capacity": [
      {
        "servername": "server1",
        "cap_unit": "GB",
        "size": "10"
      },
      {
        "servername": "server1",
        "cap_unit": "GB",
        "size": "11"
      },
      {
        "servername": "server1",
        "cap_unit": "GB",
        "size": "11"
      },
      {
        "cap_unit": "GB",
        "servername": "server2",
        "size": "12"
      },
      {
        "cap_unit": "GB",
        "servername": "server2",
        "size": "13"
      },
      {
        "cap_unit": "GB",
        "servername": "",
        "size": "14"
      },
      {
        "cap_unit": "GB",
        "servername": "",
        "size": "14"
      },
      {
        "cap_unit": "GB",
        "servername": "",
        "size": "14"
      },
      {
        "cap_unit": "GB",
        "servername": "",
        "size": "15"
      }
    ]
--------------------------------------------------------





=> I want generate ' storage_device' variable which give me below data 
[capacity of server with no_of_vols].
---------------------------------------------------------
storage_device:
  - servername: server1
    capacity:
      - no_of_vols: 1   # how many 10 GB for  server1
        size: 10
        cap_unit: GB
      - no_of_vols: 2
        size: 11
        cap_unit: GB
  - server: server2
    capacity:
      - no_of_vols: 1  # how many 12 GB for  server2
        size: 12
        cap_unit: GB
      - no_of_vols: 1
        size: 13
        cap_unit: GB
  - servername: ''   # how many 10 GB for  '<blank>'
    capacity:
      - no_of_vols: 3
        size: 14
        cap_unit: GB
      - no_of_vols: 1
        size: 15
        cap_unit: GB

On Monday, December 18, 2023 at 6:56:29 PM UTC+5:30 Will McDonald wrote:

> It's not 100% clear to me from your sample data exactly what you're trying 
> to achieve.
>
> Reading between the lines though, for each server, you want to calculate 
> the number of volumes? 
>
> What do you want to count as a 'volume'? Each block device? Partition? PV? 
> LV? Filesystem? Something else?
>
> And do you need to do this using a statically defined var, or is that just 
> illustrative? It's highly likely that you can pull the data you need from 
> setup/facts and calculate the values you need based on that.
>
>
> On Mon, 18 Dec 2023 at 12:56, javed khan Siddque <[email protected]> 
> wrote:
>
>> i want to print Data Based On Size In Given Server and generate the 
>> 'no_of_vols'.
>> storage_device:
>>   - servername: server1
>>     capacity:
>>       - no_of_vols: 1
>>         size: 10
>>         cap_unit: GB
>>       - no_of_vols: 2
>>         size: 11
>>         cap_unit: GB
>>   - server: server2
>>     capacity:
>>       - no_of_vols: 1
>>         size: 12
>>         cap_unit: GB
>>       - no_of_vols: 1
>>         size: 13
>>         cap_unit: GB
>>   - servername: ''
>>     capacity:
>>       - no_of_vols: 3
>>         size: 14
>>         cap_unit: GB
>>       - no_of_vols: 1
>>         size: 15
>>         cap_unit: GB
>>
>>
>> below is my code working till creating epecting list of dictionaries , 
>> but 'no_of_vols' i am facing issue.
>>
>> ---
>> - name: "This Play To Print Data Based On Size In Given Server"
>>   hosts: localhost
>>   gather_facts: false
>>   vars:
>>     storage_device:
>>       - servername: server1
>>       - servername: server2
>>     "storage_details_test_capacity": [
>>       {
>>         "servername": "server1",
>>         "cap_unit": "GB",
>>         "size": "10"
>>       },
>>       {
>>         "servername": "server1",
>>         "cap_unit": "GB",
>>         "size": "11"
>>       },
>>       {
>>         "servername": "server1",
>>         "cap_unit": "GB",
>>         "size": "11"
>>       },
>>       {
>>         "cap_unit": "GB",
>>         "servername": "server2",
>>         "size": "12"
>>       },
>>       {
>>         "cap_unit": "GB",
>>         "servername": "server2",
>>         "size": "13"
>>       },
>>       {
>>         "cap_unit": "GB",
>>         "servername": "",
>>         "size": "14"
>>       },
>>       {
>>         "cap_unit": "GB",
>>         "servername": "",
>>         "size": "14"
>>       },
>>       {
>>         "cap_unit": "GB",
>>         "servername": "",
>>         "size": "14"
>>       },
>>       {
>>         "cap_unit": "GB",
>>         "servername": "",
>>         "size": "15"
>>       }
>>     ]
>>   tasks:
>>     - name: Populate storage_device list
>>       ansible.builtin.set_fact:
>>         storage_device: "{{ storage_device | default([]) + 
>> [{'servername': item.servername | default(''), 'capacity': [{'size': 
>> item.size | int, 'cap_unit': item.cap_unit}]}] }}"
>>       loop: "{{ storage_details_test_capacity }}"
>>
>>
>>     - name: Debug storage_device list
>>       ansible.builtin.debug:
>>         var: storage_device
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/fc1c5e4d-eb2e-4712-b2c1-9ac6f8d2c7aen%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/fc1c5e4d-eb2e-4712-b2c1-9ac6f8d2c7aen%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6a3c2403-b7a5-4dfc-ac3c-e4c64a438fd1n%40googlegroups.com.

Reply via email to