I have created a simple example to create contacts between two blocks in apdl. It is well commented.
You can understand the basic procedure here and can further apply it to your model.
Also, please go through the help documentation for more reference on any commands used in the script.
block,0,1,0,1,0,1 !make two blocks touching each other
et,1,186 !define a solid element type
mp,ex,1,100 !define some elastic material properties
esize,0.2 !element size
vmesh,all !mesh all volumes
et,2,174 !create contact elements
keyopt,2,12,5 !bonded contact
r,2 !real number for this contact pair
et,3,170 !create target elements
asel,s,,,6 !select contact area
nsla,s,1 !select nodes attached to this area
esln !select elements attached to the selected nodes
type,2 !set contact type number
real,2 !set real number for contact pair - one real number for each contact pair
esurf !create contact elements on selected nodes
asel,s,,,11 !select target area
type,3 !set target element type number
real,2 !set real number for this contact pair
esurf !create target elements
nsel,s,loc,x,0 !constrain one end of block 1
nsel,s,loc,x,2 !apply displacement on other end of block 2
plnsol,u,x !plot disp x
You can also do this process via ANSYS Classic GUI using Contact wizard.
Hope this helps.