On Tue, 7 Dec 2021 at 13:26, Todd Lewis <[email protected]> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAE_gQfX-itrMu%3D93HwR-Vw8M60hB_jW%3DDk5b2C7%3Ds9UKFz8h5w%40mail.gmail.com.