# Linux lun mount and format/filesystem

**URL:** <https://forum.ansible.com/t/linux-lun-mount-and-format-filesystem/33976>\
**Category:** Ansible Project\
**Created:** [October 6, 2020, 5:35pm UTC](https://forum.ansible.com/t/linux-lun-mount-and-format-filesystem/33976 "2020-10-06T17:35:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymus](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@anonymus](https://forum.ansible.com/u/anonymus)\
**Post date:** [October 6, 2020, 5:35pm UTC](https://forum.ansible.com/t/linux-lun-mount-and-format-filesystem/33976/1 "2020-10-06T17:35:06Z")

</div>

i am newbie on ansible  
i wanted to do the below task using ansible , is there any playbook for

1. Discovering an iscsi target
2. Login in
3. rescanning iscsi bus
4. formatting the newly discovered lun
5. creating filesystem on it.
6. updating /etc/fstab with newly mounted

---

<div class="post-metadata">

**Author:** ![Paul\_Martin1](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@Paul\_Martin1](https://forum.ansible.com/u/Paul_Martin1)\
**Post date:** [October 8, 2020, 4:04pm UTC](https://forum.ansible.com/t/linux-lun-mount-and-format-filesystem/33976/2 "2020-10-08T16:04:44Z")

</div>

Hi,  
I did this in the past for block storage, guessing something similar to this example, I’ve not formatted the devices as this was for mounting a clone

tasks:

# Rescan storage layer to pull in new devices to host

# Example here is for emulex hba

- name: Rescan HBA  
command: /usr/bin/rescan-scsi-bus.sh

- name: unmount filesystems by label  
mount:  
path: “{{ item }}”  
state: unmounted  
with\_items:

- /database

- /reports

- /logs

- name: Create Directory  
file:  
path: “{{ item }}”  
state: directory  
with\_items:

- /database

- /reports

- /logs

- name: Mount filesystems by label  
mount:  
path: “{{ item.mountpoint }}”  
src: LABEL=“{{ item.label }}”  
fstype: ext4  
state: mounted  
with\_items:

- { label: ‘database’, mountpoint: ‘/database’}

- { label: ‘reports’, mountpoint: ‘/reports’}

- { label: ‘logs’, mountpoint: ‘/logs’}

---

<div class="post-metadata">

**Author:** ![anonymus](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@anonymus](https://forum.ansible.com/u/anonymus)\
**Post date:** [October 18, 2020, 3:20pm UTC](https://forum.ansible.com/t/linux-lun-mount-and-format-filesystem/33976/3 "2020-10-18T15:20:05Z")

</div>

Thank you Paul.

---

<div class="post-metadata">

**Author:** ![Gajendra\_Gaikwad1](https://avatars.discourse-cdn.com/v4/letter/g/9de053/32.png) [@Gajendra\_Gaikwad1](https://forum.ansible.com/u/Gajendra_Gaikwad1)\
**Post date:** [October 21, 2020, 4:55pm UTC](https://forum.ansible.com/t/linux-lun-mount-and-format-filesystem/33976/4 "2020-10-21T16:55:17Z")

</div>

Hello,  
I have created below playbook, but i have not tested on live  
check if its work for you.
