Ansible

ansible - 如何克服“衝突的行動聲明”錯誤?

  • October 6, 2021

我有一個用於創建和調整邏輯卷大小的 Ansible 劇本

# playbook lvol.yml
- hosts: step
 tasks:
 - name: 'create /dev/sdb1 -> 20GB (of 35GB)'
   community.general.parted:
   device: /dev/sdb
   number: 1
   state: present
#    fs_type: ext4


 - name: "resize vgsys by /dev/sdb1"
   community.general.lvg:
   vg: vgsys
   pvs: /dev/sdb1

 - name: "extend lv 'name' to 10GB from /dev/sdb (35GB)"
   community.general.lvol:
     vg: vgsys
     lv: name
     size: 10g

yaml 語法似乎很好(通過 onlineyamltools.com 檢查)但我在執行時收到此錯誤:

ERROR! conflicting action statements: community.general.parted, device

The error appears to be in '/path/to/lvol.yml': line 4, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

 tasks:
 - name: 'create /dev/sdb1 -> 20GB (of 35GB)'
   ^ here

如果我註釋掉第一個(community.general.parted)任務,第二個(lvol)任務會出現相同的錯誤。

任何人都可以為我指出如何克服這個問題的正確方向嗎?

您的 yaml 沒有正確縮進。

您需要將參數進一步縮進到一個模組:

- hosts: step
 tasks:
 - name: 'create /dev/sdb1 -> 20GB (of 35GB)'
   community.general.parted:
     device: /dev/sdb
     number: 1
     state: present
 #    fs_type: ext4

 - name: "resize vgsys by /dev/sdb1"
   community.general.lvg:
     vg: vgsys
     pvs: /dev/sdb1

您對lvol模組的任務已經正確。

線上驗證器無法檢測到這一點,因為它只能檢查語法正確的 yaml,而不是功能正確的鍵和值。

引用自:https://serverfault.com/questions/1079703