need help on multipath

33 views
Skip to first unread message

rakesh boinapally

unread,
Jul 12, 2017, 10:37:20 AM7/12/17
to Ansible Project
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 

Kai Stian Olstad

unread,
Jul 14, 2017, 11:06:51 AM7/14/17
to ansible...@googlegroups.com
On 12. juli 2017 16:37, rakesh boinapally wrote:
> 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


> 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


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages