NASHVILLE, Tenn. — The Yankees pursuit of Starlin Castro via a trade from the Cubs would be a huge upgrade for a shaky second-base situation.

Early Tuesday night, the Yankees and Cubs agreed to a deal for the infielder, though did not finalize it, after the Cubs signed Ben Zobrist to a four-year deal for $56 million. In exchange for Castro, the Cubs will get Adam Warren and a player to be named, possibly infielder Brendan Ryan.

With Castro, the Yankees are upgrading second base, which is occupied by unproven Rob Refsnyder and midseason acquisition Dustin Ackley. Neither instills confidence in the field or at the plate.

Earlier this offseason the Yankees insisted they wouldn’t trade outfielder Brett Gardner for Castro, but the Cubs have long liked Warren.

Castro has $37 million owed to him through the 2019 season, before a $16 million team
option in 2020 with a $1 million buyout.

Since Jim Hendry, one of general manager Brian Cashman’s top lieutenants, signed Castro in 2006 and brought him to the big leagues in 2010 when Hendry was the Cubs’ GM, the Yankees know the player very well.

Castro, 26 in March, had been a shortstop but moved to second base in mid-August and the move led to improvement at the plate and in the field.

Prior to the switch, Castro had a .570 OPS. After the move that improved to .961 and he played better defensively. For the season he batted .265 with 11 homers, 69 RBIs and .671 OPS.

The Cubs, who might lose Dexter Fowler to free agency, weren’t interested in Jacoby Ellsbury, who was drafted by the Cubs’ Theo Epstein and Jed Hoyer when they ran the Red Sox.

Talking before the deal on Tuesday, Joe Girardi described what he is looking for at second base and not about specifically about Castro who would be an upgrade over the platoon of Ackley and Refsnyder.

“You could be greedy. You look for outstanding defense and offensive production,’’ Girardi said of two areas Ackley and Refsnyder don’t qualify. “That’s the greedy part of it, that you can get a lot of production, too, offensively.’’

Castro also offers the option of playing short if Girardi wants to give Didi Gregorius a rest. That’s a position Ackley and Refsnyder can’t play.

Girardi pointed out that second base is the only position where a competition would be held.

“That’s the one spot that is probably open for competition more than anything,’’ said Girardi. “We would probably be trying to figure out a platoon system there possibly or if one guy took it and ran with it. But I think defense is really important.’’