我需要创建一个 YAML 代码来为 windows 分区和格式化磁盘,输入将是一个动态 /json 文件,其中包含磁盘名称、标签的详细信息
I need to create a YAML code to partition and format disk for windows , the input will be a dynamic /json file ,with the details of disk name,label
我正在使用 (json/dictionary) 的输入文件格式,格式如下
字典:
{
"disks": {
"disk2": {
"name": "S",
"label": "Sample",
"disknum": 2
},
"disk3": {
"name": "T",
"label": "Testing",
"disksize": 10
},
"disk4": {
"name": "K",
"label": "Urban",
"disknum": 4
}
我使用的代码如下,但是磁盘号在输入中是硬编码的,我需要用从 ansible win_disk_facts、
检索到的值替换它
起始盘号需要从2开始,因为0号盘,1号盘已经被消耗了,能否在下面提到的循环中包含facts中的盘号?
- name: Perform Partition of disks
win_partition:
drive_letter: "{{item.value.name}}"
partition_size: -1
disk_number: "{{item.value.disknum}}"
loop: "{{ lookup('dict', disks) }}"
我找到了解决这两种情况的方法
1.increase索引值(withindexed_items)
- 调试:
msg: "磁盘号是 {{item.0 +2}} "
与_indexed_items:
- “{{查找('dict',磁盘)}}”
2.use 分区中的索引值 (loop_control)
- name: 执行磁盘分区
win_partition:
drive_letter: "{{item.value.name}}"
partition_size:-1
disk_number: "{{ 2 + my_idx|int }}"
循环:“{{查找('dict',磁盘)}}”
loop_control:
index_var: my_idx
我正在使用 (json/dictionary) 的输入文件格式,格式如下 字典:
{
"disks": {
"disk2": {
"name": "S",
"label": "Sample",
"disknum": 2
},
"disk3": {
"name": "T",
"label": "Testing",
"disksize": 10
},
"disk4": {
"name": "K",
"label": "Urban",
"disknum": 4
}
我使用的代码如下,但是磁盘号在输入中是硬编码的,我需要用从 ansible win_disk_facts、
检索到的值替换它起始盘号需要从2开始,因为0号盘,1号盘已经被消耗了,能否在下面提到的循环中包含facts中的盘号?
- name: Perform Partition of disks
win_partition:
drive_letter: "{{item.value.name}}"
partition_size: -1
disk_number: "{{item.value.disknum}}"
loop: "{{ lookup('dict', disks) }}"
我找到了解决这两种情况的方法
1.increase索引值(withindexed_items)
- 调试: msg: "磁盘号是 {{item.0 +2}} " 与_indexed_items: - “{{查找('dict',磁盘)}}”
2.use 分区中的索引值 (loop_control)
- name: 执行磁盘分区 win_partition: drive_letter: "{{item.value.name}}" partition_size:-1 disk_number: "{{ 2 + my_idx|int }}" 循环:“{{查找('dict',磁盘)}}” loop_control: index_var: my_idx