Great!! Thanks a lot!

Edgars

otrdiena, 2015. gada 24. marts 14:37:34 UTC+1, Jonathan Davila rakstīja:
>
> Hi Edgars,
>
> You want to use ansible's with_dict method of looping. Here is an example 
> of looping through that dict and then a sample conditional for it as well
>
> # This is the sample with_dict loop
>     - debug: msg="The device {{ item.key }} with these partitions {{ 
> item.value.partitions }}"
>       with_dict: ansible_devices
>
> # This msg will only be printed on the condition that a device has no 
> partitions
>     - debug: msg="The device {{ item.key }} has no partitions"
>       with_dict: ansible_devices
>       when: not item.value.partitions
>
> Hopefully that helps you out.
>
> On Tuesday, March 24, 2015 at 6:23:41 AM UTC-4, Edgars wrote:
>>
>> Hi
>>
>> I have some troubles to understand how to loop over facts in playbook. 
>> Suppose I have the following:
>>
>>
>> ansible node01 -m setup -a 'filter=ansible_devices'
>> SSH password:
>> SU password[defaults to SSH password]:
>> node01 | success >> {
>>     "ansible_facts": {
>>         "ansible_devices": {
>>             "sda": {
>>                 "holders": [],
>>                 "host": "Serial Attached SCSI controller: VMware PVSCSI 
>> SCSI Controller (rev 02)",
>>                 "model": "Virtual disk",
>>                 "partitions": {
>>                     "sda1": {
>>                         "sectors": "204800",
>>                         "sectorsize": 512,
>>                         "size": "100.00 MB",
>>                         "start": "2048"
>>                     },
>>                     "sda2": {
>>                         "sectors": "104650752",
>>                         "sectorsize": 512,
>>                         "size": "49.90 GB",
>>                         "start": "206848"
>>                     }
>>                 },
>>                 "removable": "0",
>>                 "rotational": "1",
>>                 "scheduler_mode": "noop",
>>                 "sectors": "104857600",
>>                 "sectorsize": "512",
>>                 "size": "50.00 GB",
>>                 "support_discard": "0",
>>                 "vendor": "VMware"
>>             },
>>             "sdb": {
>>                 "holders": [],
>>                 "host": "Serial Attached SCSI controller: VMware PVSCSI 
>> SCSI Controller (rev 02)",
>>                 "model": "Virtual disk",
>>                 "partitions": {
>>                     "sdb1": {
>>                         "sectors": "10469376",
>>                         "sectorsize": 512,
>>                         "size": "4.99 GB",
>>                         "start": "16384"
>>                     }
>>                 },
>>                 "removable": "0",
>>                 "rotational": "1",
>>                 "scheduler_mode": "noop",
>>                 "sectors": "10485760",
>>                 "sectorsize": "512",
>>                 "size": "5.00 GB",
>>                 "support_discard": "0",
>>                 "vendor": "VMware"
>>             },
>>             "sdc": {
>>                 "holders": [],
>>                 "host": "Serial Attached SCSI controller: VMware PVSCSI 
>> SCSI Controller (rev 02)",
>>                 "model": "Virtual disk",
>>                 "partitions": {},
>>                 "removable": "0",
>>                 "rotational": "1",
>>                 "scheduler_mode": "noop",
>>                 "sectors": "14680064",
>>                 "sectorsize": "512",
>>                 "size": "7.00 GB",
>>                 "support_discard": "0",
>>                 "vendor": "VMware"
>>             }
>>         }
>>     },
>>     "changed": false
>> }
>>
>> So there are 3 disks: sda, sdb and sdc. Two of them has partitions, one 
>> does not. So I want to loop over all disks and check which disk have 
>> partitions and which does not have and then do something about it. I know I 
>> can do something like this:
>>
>> {{ ansible_devices['sda']['partitions'] }}
>>
>> But when I will run this playbook I will not know neither disk labels nor 
>> number of disks.
>>
>> Any ideas?
>>
>> Thanks
>> Edgars
>>
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5c9181c1-93a1-4aec-ace5-feb74c9ce11b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to