> Also I noticed that the "Read device information (always use unit when probing) " isn't being used. So I removed it. That's too bad, because its output is exactly what we need to know why the next bit is failing. It also contains the information you need to know whether the "Add new partition…" steps need to execute. But if we get those steps expressed idempotently it really shouldn't matter. Would be informative to see the output of that for both data_volume and pgsql_volume. I'd also be interested to see what /etc/fstab entry/entries you've got for these devices.
I'm assuming the error you quoted is from either the "Add new partition "{{ pgsql_volume }}" (/pgsql)" step or the "Add new partition "{{ data_volume }}" (/data)" step, but I don't know which. I understand the desire to keep posts brief, but leaving out step output headers, values of variables, etc. makes us have to guess or scroll back through the thread and piece it back together. In the mean time, something's changed, etc. It could be that the one little breaking detail is something you're writing off as insignificant — otherwise you would have fixed it already! *[aside: I've been doing a lot of Ansible support in the last couple of weeks in forums like this, and nearly half the exchanges have been requests for information that was left out - presumably for my/our convenience - from prior posts.]* At any rate, the "Add new partition…" steps are not behaving idempotently: the partition you are declaring already exists. There must be some way to express that so that the community.general.parted module doesn't run "/usr/sbin/parted -s -m -a optimal /dev/nvme2n1 -- unit KiB mklabel msdos mkpart primary ext4 0% 100%", which we know is doomed to fail if there's already a partition on /dev/nvme2n1. (Or is there? Could be a raw device?) On Monday, December 6, 2021 at 9:17:04 PM UTC-5 drum....@gmail.com wrote: > On Tue, 7 Dec 2021 at 13:26, Todd Lewis <uto...@gmail.com> wrote: > >> I was able to get your playbook to work repeatedly on an external >> thumdrive. It shows up as /dev/sda, so the full partition - after >> changing to "number: 1" is /dev/sda1. My significant changes are bolded >> below. Note that dev: and src: in the last two steps are a concatenation >> of data_volume and number. For an nvme device like /dev/nvme2n1 you'd >> need to insert a "p" before the partition number: "{{ data_volume }}p{{ >> number }}". >> >> - hosts: localhost >> vars: >> *data_volume: /dev/sda* >> *number: 1* >> tasks: >> - name: Read device information (always use unit when probing) >> *community.general.parted:* >> device: "{{ data_volume }}" >> unit: MiB >> register: sdb_info >> >> - name: Add new partition "{{ data_volume }}" >> run_once: true >> *community.general.parted:* >> device: "{{ data_volume }}" >> *number: "{{ number }}"* >> fs_type: ext4 >> state: present >> >> - name: Create a ext4 filesystem on "{{ data_volume }}" (/data) >> run_once: true >> community.general.filesystem: >> fstype: ext4 >> *dev: "{{ data_volume }}{{ number }}"* >> >> - name: Mount /data >> ansible.posix.mount: >> path: /data >> *src: "{{ data_volume }}{{ number }}"* >> fstype: ext4 >> state: mounted >> opts: defaults >> >> If you do get all the nuances worked out, post back to let us know what >> you ended up with. Good luck. >> > > Thanks for your reply. > > I tried using your suggestions, but I get this error: > fatal: [localhost]: FAILED! => {"changed": false, "err": "Error: > Partition(s) on /dev/nvme2n1 are being used.\n", "msg": "Error while > running parted script: /usr/sbin/parted -s -m -a optimal /dev/nvme2n1 -- > unit KiB mklabel msdos mkpart primary ext4 0% 100%", "out": "", "rc": 1} > > It works if I unmount the volume, though. > > This is the code I'm using: > > - name: Add new partition "{{ pgsql_volume }}" (/pgsql) > run_once: true > community.general.parted: > device: "{{ data_volume }}" > number: "{{ number }}" > fs_type: ext4 > state: present > when: prod and not awsbau and not slave > > - name: Create a ext4 filesystem on "{{ pgsql_volume }}" (/pgsql) > run_once: true > community.general.filesystem: > fstype: ext4 > dev: "{{ pgsql_volume }}p{{ number }}" > when: prod and not awsbau and not slave > > - name: Unomunt /data > ansible.posix.mount: > path: /data > state: unmounted > > - name: Add new partition "{{ data_volume }}" (/data) > run_once: true > community.general.parted: > device: "{{ data_volume }}" > number: "{{ number }}" > fs_type: ext4 > state: present > > - name: Create a ext4 filesystem on "{{ data_volume }}" (/data) > run_once: true > community.general.filesystem: > fstype: ext4 > dev: "{{ data_volume }}p{{ number }}" > > - name: Mount /pgsql > ansible.posix.mount: > path: /pgsql > src: "{{ pgsql_volume }}{{ number }}" > fstype: ext4 > state: mounted > opts: defaults > > - name: Mount /data > ansible.posix.mount: > path: /data > src: "{{ data_volume }}{{ number }}" > fstype: ext4 > state: mounted > opts: defaults > > Also I noticed that the "Read device information (always use unit when > probing) " isn't being used. So I removed it. > > Lucas > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/39fd95b9-85be-433c-b8fb-086892c91e36n%40googlegroups.com.