Pep Guardiola will coach Bayern Munich against former club Barcelona in a friendly in July, the two clubs have confirmed.