This tactic is against the rules. The ref will give a yellow card and indirect free kick. Here is the quote from the FIFA laws of the game (in bold):
Cautions for unsporting behaviour
There are different circumstances when a player must be cautioned for unsporting behaviour, e.g. if a player:
• commits in a reckless manner one of the seven offences that incur a direct free kick
• commits a foul for the tactical purpose of interfering with or breaking up a promising attack
• holds an opponent for the tactical purpose of pulling the opponent away from the ball or preventing the opponent from getting to the ball
• handles the ball to prevent an opponent gaining possession or developing an attack (other than the goalkeeper within his own penalty area)
• handles the ball in an attempt to score a goal (irrespective of whether or not the attempt is successful).
• attempts to deceive the referee by feigning injury or pretending to have been fouled (simulation)
• changes places with the goalkeeper during play or without the referee’s permission
• acts in a manner which shows a lack of respect for the game
• plays the ball when he is walking off the field of play after being granted permission to leave the field of play
• verbally distracts an opponent during play or at a restart
• makes unauthorised marks on the field of play
• uses a deliberate trick while the ball is in play to pass the ball to his own goalkeeper with his head, chest, knee, etc. in order to circumvent the Law, irrespective of whether the goalkeeper touches the ball with his hands or not. The offence is committed by the player in attempting to circumvent both the letter and the spirit of Law 12 and play is restarted with an indirect free kick
• uses a deliberate trick to pass the ball to his own goalkeeper to circumvent the Law while he is taking a free kick (after the player is cautioned, the free kick must be retaken)