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.
On Monday, December 6, 2021 at 3:00:52 PM UTC-5 drum....@gmail.com wrote:

> On Tue, 7 Dec 2021 at 06:27, Todd Lewis <uto...@gmail.com> wrote:
>
>> You're specifying partition 2 w/o a size. On a blank disk (in my testing 
>> at least) this produces a partition 1. Subsequent calls to the first task 
>> fail because partition 1 consumes the entire disk, and partition 2 cannot 
>> be created. However, changing "number: 2" to "number: 1" in the first task 
>> allows subsequent calls to succeed. Can you explain why you're using "2", 
>> and how are subsequent tasks expected to associate / operate on that 
>> partition?
>>
>
> There is only one partition in that disk. And TBH, I don't know why I put 
> "partition 2" there. I think it was a copy and paste. I'll change the 
> partition number from 2 to 1 and test again.
>  
>
>>
>> Also, it may be helpful if you tell us what value you have for 
>> data_volume.
>>
>
> data_volume is /dev/nvme2n1
> pgsql_volume is /dev/nvme1n1
>
> Those are variables, and I need to manually change them since even by 
> using aws_volume_attachment in terraform, it's not guaranteed that the 
> volume will have the same designation for every attachment. And I couldn't 
> find a way to check the disks by size.
>
> Cheers,
> 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/512da2e9-9233-444b-809e-e92608327389n%40googlegroups.com.

Reply via email to