0

the input file format which i am using the (json/dictionary) as in below format dictionary :

 {
     "disks": {
    "disk2": {
      "name": "S",
      "label": "Sample",
      "disknum": 2
    },
    "disk3": {
      "name": "T",
      "label": "Testing",
      "disksize": 10
    },
    "disk4": {
      "name": "K",
      "label": "Urban",
      "disknum": 4
    }

the code which I have used is below, but the disk number is hardcoded here in the input, which I need to replace with the values retrieved from ansible win_disk_facts,

starting disk number need to be from 2, as disk 0, disk 1 is already consumed, can we include the disk number from facts in the loop mentioned below?

 - name: Perform Partition of disks
    win_partition:
    drive_letter: "{{item.value.name}}"
    partition_size: -1
    disk_number: "{{item.value.disknum}}"
    loop: "{{ lookup('dict', disks) }}"
Pranav Choudhary
  • 2,726
  • 3
  • 18
  • 38
  • 2
    Welcome to SO! Please read the [formatting help](https://stackoverflow.com/editing-help) and update your question accordingly, as in its current state, it is very hard to read and given that YAML is an indentation-based format, it is important to see the indentation in your file correctly. – flyx Jun 17 '20 at 12:50

1 Answers1

0

i have found out a way to resolve these 2 situations

1.increase the index value (with indexed_items)

  • debug: msg: "disk number is {{item.0 +2}} " with_indexed_items: - "{{ lookup('dict', disks) }}"

2.use indexing value in partitioning (loop_control)

  • name: Perform Partition of disks win_partition: drive_letter: "{{item.value.name}}" partition_size: -1 disk_number: "{{ 2 + my_idx|int }}" loop: "{{ lookup('dict', disks) }}" loop_control: index_var: my_idx