For the example you posted there (two masses connected by a light inextensible rope over a frictionless pulley):
Consider the Lagrangian <br />
L_1(x_1,x_2,\dot x_1, \dot x_2) = \tfrac12(m_1 \dot x_1^2 + m_2 \dot x_2^2) + m_1gx_1 + m_2gx_2 - T(x_1 + x_2 - l), where x_1 and x_2 are measured vertically downwards from the center of the pulley, l is the length of the rope less half the circumference of the pulley, and T is a Lagrange multiplier. Obtaining the Euler-Lagrange equations shows that T takes the role of a force directed vertically upwards and acting on both masses, which in this physical context must be the tension in the rope.
Alternatively, consider <br />
\begin{split}<br />
L_2(x_1, \dot x_1) &= L_1(x_1, l - x_1, \dot x_1, -\dot x_1) \\<br />
&=\tfrac12 (m_1 + m_2) \dot x_1^2 + m_1gx_1 + m_2g(l - x_1),\end{split} which is the result of eliminating x_2 and \dot x_2 from L_1 using the constraint. Note that T does not appear in L_2.
If you want to find the tension, then you have two unknowns: the tension and the acceleration of one of the masses. Starting from L_1, obtaining the Euler-Lagrange equations for x_1 and x_2, and only then imposing the constraint x_1 + x_2 = l gives you the two equations necessary to solve for T and \ddot x_1 = -\ddot x_2. Starting from L_2 only gives you a single Euler-Lagrange equation from which you can find \ddot x_1.