# need help on multipath

**URL:** <https://forum.ansible.com/t/need-help-on-multipath/24964>\
**Category:** Ansible Project\
**Created:** [July 12, 2017, 2:37pm UTC](https://forum.ansible.com/t/need-help-on-multipath/24964 "2017-07-12T14:37:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rake](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rake](https://forum.ansible.com/u/rake)\
**Post date:** [July 12, 2017, 2:37pm UTC](https://forum.ansible.com/t/need-help-on-multipath/24964/1 "2017-07-12T14:37:19Z")

</div>

we usually perform lot of multipath tasks in our company.

On a server if i want to configure multipath for disk aliases

multipath -ll|egrep “dm-|size”|sed -e ‘s/]/ /g’|sed -e ‘N’ -e ‘s/\n/ /’|awk ‘{print $6,$2}’|sed -e ‘s/[size=//g’|sed -e ‘s/(//g’|sed -e ‘s/)//g’|sed -e ‘s/.0G/G/’|sort this displays output like below

size=100G 360060e8007dd94000030dd940000048e  
size=100G 360060e8007dd94000030dd940000048f  
size=200G 360060e8007dd94000030dd940000048d  
size=50G 360060e8007dd94000030dd9400000490  
size=5G 360060e8007dd94000030dd9400000491  
size=5G 360060e8007dd94000030dd9400000492  
size=5G 360060e8007dd94000030dd9400000493  
size=5G 360060e8007dd94000030dd9400000494  
size=5G 360060e8007dd94000030dd9400000495  
size=5G 360060e8007dd94000030dd9400000496  
size=5G 360060e8007dd94000030dd9400000497

once we have this output we usually copy this output into file like allluns and run a script like below test-create-multipath-conf.sh to

#!/usr/bin/ksh

> multipath.cfg  
> k=0  
> v=0  
> j=0  
> while read line  
> do  
> line1=`echo $line|awk '{print $1}'`  
> line2=`echo $line|awk '{print $2}'`  
> if [“$line1” = “size=100G”];then  
> j=`expr $j + 1`  
> echo " multipath {" \>\> multipath.cfg  
> echo " wwid $line2" \>\> multipath.cfg  
> echo " alias data$j" \>\> multipath.cfg  
> echo " }" \>\> multipath.cfg  
> elif [“$line1” = “size=5G”];then  
> v=`expr $v + 1`  
> echo " multipath {" \>\> multipath.cfg  
> echo " wwid $line2" \>\> multipath.cfg  
> echo " alias redo$v" \>\> multipath.cfg  
> echo " }" \>\> multipath.cfg  
> elif [“$line1” = “size=200G”];then  
> k=`expr $k + 1`  
> echo " multipath {" \>\> multipath.cfg  
> echo " wwid $line2" \>\> multipath.cfg  
> echo " alias fra$k" \>\> multipath.cfg  
> echo " }" \>\> multipath.cfg  
> fi

done \< allluns  
sed -i ‘$i}’ multipath.cfg

and it creates output like below

multipath {  
wwid 360060e8007dd94000030dd940000048e  
alias data1  
}  
multipath {  
wwid 360060e8007dd94000030dd940000048f  
alias data2  
}  
multipath {  
wwid 360060e8007dd94000030dd940000048d  
alias fra1  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000491  
alias redo1  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000492  
alias redo2  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000493  
alias redo3  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000494  
alias redo4  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000495  
alias redo5  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000496  
alias redo6  
}  
multipath {  
wwid 360060e8007dd94000030dd9400000497  
alias redo7  
}  
}

can any one help me with above requirement im trying to convert into ansible

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 14, 2017, 3:06pm UTC](https://forum.ansible.com/t/need-help-on-multipath/24964/2 "2017-07-14T15:06:30Z")

</div>

> we usually perform lot of multipath tasks in our company.
> 
> On a server if i want to configure multipath for disk aliases
> 
> multipath -ll|egrep "dm-|size"|sed -e 's/\]/ /g'|sed -e 'N' -e 's/\n/  
> /'|awk '{print $6,$2}'|sed -e 's/\[size=//g'|sed -e 's/(//g'|sed -e  
> 's/)//g'|sed -e 's/\.0G/G/'|sort this displays output like below

To register output in a variable from a module in Ansible you have register:  
[https://docs.ansible.com/ansible/playbooks\_variables.html#registered-variables](https://docs.ansible.com/ansible/playbooks_variables.html#registered-variables)

> once we have this output we usually copy this output into file like allluns  
> and run a script like below test-create-multipath-conf.sh to

To create files in Ansible where you can use the variable you have the template module.  
[https://docs.ansible.com/ansible/template\_module.html](https://docs.ansible.com/ansible/template_module.html)
