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.

Reply via email to