Peralta, who was set to be a free agent after the 2020 season, will now be under contract through 2022.
He hit .275 with 12 home runs and 57 RBIs in 99 games last season, which ended for him in August when he decided to undergo right shoulder surgery. The shoulder had been an issue throughout 2019, and Peralta had three stints on the injured list.
Peralta is expected to be ready for spring training.
He won a Gold Glove in 2019 and hit a career-high 30 homers in 2018.
Ray, who was an All-Star in 2017, has been one of Arizona's top pitchers over the past four seasons. He had a 12-8 record and a 4.34 ERA in 2019 and struck out a career-high 235 batters in 174⅓ innings.
Chafin and Andriese were both in the bullpen last season. Chafin is a durable lefty who appeared in at least 70 games in each of the past three seasons. He had a 3.76 ERA and 68 strikeouts in 52⅔ innings last year. Andriese appeared in 54 games out of the bullpen last season, finishing with a 5-5 record and a 4.71 ERA.
The 29-year-old Lamb was an All-Star in 2017, but he is trying to bounce back from two straight injury-plagued seasons. He hit just .193 last year with six homers in 78 games.
Shortstop Nick Ahmed and reliever Archie Bradley did not reach deals and are headed toward arbitration. Ahmed requested a salary of $6.95 million and was offered $6.6 million. Bradley asked for $4.1 million and was offered $3,625,000.
Information from the Associated Press was used in this report.