Former Barcelona coach Luis Enrique has signed a two-year deal to take charge of Spain.