0

I want to only run the parted operation if no partitions currently exist on that device. Said parts could have been made previously or manually outside of ansible in the past and in that case should not be changed and the task skip.

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

However currently when running this even if a partition already exists then changes are being made and an error similar to below is printed by tower suggesting it is making changes (after a reboot the system became unbootable)

"_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",

I was hoping it can be achieved with a when condition getting an ansible_fact similar to below?

when: ansible_facts.device.xvdf is not defined

but I can't find the correct fact or syntax for this idea?

from documentation I was hoping the parted module was idempotent enough to recognize if a partition already exists and not change, but I think if the specified config is in anyway different it tries to apply it

The target system is a AWS EC2 running RHEL7 and the attached disk is a secondary (non-root) encrypted EBS Volume

hat
  • 3
  • 1

1 Answers1

0

Try to play with this to see it helps you:

  tasks:
  - name: Debug
    debug:
      msg: "No xvdf1"
    when: ansible_devices.xvdf.partitions.xvdf1 is not defined
  • Thankyou! I have been using when: "'/dev/xvdf1' not in ansible_facts.lvm.pvs" but this one might be cleaner! – hat May 31 '22 at 09:17