On 06/12/2021 10:50, Lucas Possamai wrote:
> On Mon, 6 Dec 2021 at 22:21, dulhaver via Ansible Project <
ansible...@googlegroups.com <mailto:
ansible...@googlegroups.com>> wrote:
>
> __
> I have seen something similar with re-running LVM operations and remember they mentioned to add a *force: yes* option (I don't recall the exact wording though) in oder the not fail on re-execution. Wondering whether something alike would help here too.
>
>
> Hmm that didn't help.
>
> This is working for me, but I think that's ugly.. there must be another way to achieve this:
>
> - name: Check if {{ data_volume }}is already mounted
> shell: df | grep {{ data_volume }}| wc -l
> with_items: "{{ data_volume }}"
> register: ebs_checked
>
Hello Lucas,
it is more efficient and less fragile to check "ansible_mounts" fact, e.g.
when: ansible_mounts | selectattr('fstype', 'equalto', 'ext4') | selectattr('mount', 'equalto', data_volume) | list | count > 1
(not tested).
Regards
Racke
> - name: Create a new ext4 primary partition for /data
> run_once: true
> community.general.parted:
> name: pg_data
> device: "{{ data_volume }}"
> number: 2
> state: present
> fs_type: ext4
> when: "{{item.stdout}} == 0"
> with_items: "{{ ebs_checked.results }}"
>
> - name: Create a ext4 filesystem on "{{ data_volume }}" (/data)
> run_once: true
> community.general.filesystem:
> fstype: ext4
> dev: "{{ data_volume }}"
> when: "{{item.stdout}} == 0"
> with_items: "{{ ebs_checked.results }}"
>
> - name: Mount /data
> ansible.posix.mount:
> path: /data
> src: "{{ data_volume }}"
> fstype: ext4
> state: mounted
> opts: defaults
>
> --
> 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-proje...@googlegroups.com <mailto:
ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAE_gQfUMJgDFKv0-x5Nyn109X7ZtS6qbwaO64VdadJBVx-2Q%2BQ%40mail.gmail.com <
https://groups.google.com/d/msgid/ansible-project/CAE_gQfUMJgDFKv0-x5Nyn109X7ZtS6qbwaO64VdadJBVx-2Q%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.