Ansible - using with_items and when conditional to

前端 未结 2 679
轮回少年
轮回少年 2021-02-01 02:10

I have a bunch of servers that have four physical drives on them (/dev/sda, sdb, sdc, and sdd). sda has the OS installed on it.

I need to format each drive except sda. I

2条回答
  •  不要未来只要你来
    2021-02-01 02:15

    Your tasks can be as simple as this...

    - stat:
        path: /dev/{{item}}1
      with_items: ansible_devices.keys()
      when: item != 'sda'
      register: stats
    - command: /sbin/parted -s /dev/{{item.item}} mklabel gpt
      with_items: stats.results
      when: item.stat | default(false) and item.stat.exists
    

提交回复
热议问题