Method IK bones
- Create an armature and create a bone for each object in the rig and put it in the right location. One bone for the Cylinder, one for the Piston, one for the Cylinder Arm (arm connected to the Cylinder), and one for the Piston Arm (arm connected to the Piston).
- Select the armature and go into Edit mode, and go to Properties > Bone Properties > Relations. Make both the Cylinder Arm Bone and the Piston Bone children of the Cylinder Bone. But uncheck the box Connected before doing so.
- Make the Piston Arm Bone a child of the Cylinder Arm Bone. In this case the Piston Arm Bone should be connected to its parent, so for this bone the box Connected should be checked.
- Parent each object to the corresponding bone. In Object Mode select an object, shift select the Armature, go to Pose Mode, select the bone, press Ctrl + P and choose Bone. Repeat for each object-bone pair.
- Go into Pose Mode, select the Piston Arm Bone and add an Inverse kinematics constraint. As a Target choose the Armature. Set the Chain Length to 2. As the Bone choose the Cylinder Bone. Now the Piston Arm Bone should snap to the Cylinder Bone (So the starting angle of the arm bones does not matter. But it does matter where you position the Cylinder Bone; its base should be where you want the end of the Piston Arm Bone to rotate around).
- You're done. In Pose Mode, move the Piston Bone along the Z-axis to move the Piston and the arms. Rotate the Cylinder Bone around the Z-axis to rotate the whole rig around the Z-axis.
Method Damped Track (does not allow for rotation around the Z axis)
It can also be done by using Constraints. However it does not allow for rotation around the Z axis, but I didn't realize that at first. I'll keep this part of the (initial) answer, just in case. : )
It is best before you active a Damped Track constraint (note the eye icon and how it is inactive), that the object that has the constraint is aligned with one of the main three dimensional axis.
It is also wise not to use the object you want to be the Damped Track target, but to use an Empty object parented to the intended target object and use that empty as the actual target instead. This can help focus the Damped Track at the right point, but will also limit unexpected and unwanted behavior due to the Damped Track recalculating positions.
However, with this simple setup there is limited control of the position of the joint where the arms meet. But it might suffice for small movements.