我希望仅在该设备上当前不存在分区时运行 parted 操作。上述部分可能之前已制作或过去在 ansible 之外手动制作,在这种情况下不应更改并跳过任务。
name: "Add Disk" ## this needs amending to skip if any partition is already present on that device
become: true
parted:
device: /dev/xvdf
number: 1
state: present
flags: [ lvm ]
label: gpt
name: primary
但是目前运行此程序时即使分区已经存在也会进行更改,并且塔会打印类似下面的错误,表明正在进行更改(重新启动后系统无法启动)
"_ansible_no_log": false,
"err": "Error: Partition(s) 1 on /dev/xvdf have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.\n",
我希望可以通过当条件获得类似于下面的 ansible_fact 来实现?
when: ansible_facts.device.xvdf is not defined
但我找不到这个想法的正确事实或语法?
从文档中我希望 parted 模块具有足够的幂等性,能够识别分区是否已经存在并且不会改变,但我认为如果指定的配置有任何不同,它会尝试应用它
目标系统是运行 RHEL7 的 AWS EC2,附加磁盘是辅助(非根)加密 EBS 卷
答案1
尝试一下这个看看它是否能帮助你:
tasks:
- name: Debug
debug:
msg: "No xvdf1"
when: ansible_devices.xvdf.partitions.xvdf1 is not defined