Former US Secretary of Defence James Mattis has written about his departure from the Trump administration in a new memoir.

Mr Mattis served as defence secretary for nearly two years under Donald Trump, making him one of the longest-serving officials in the turbulent administration. In his new memoir, co-written with military author and former assistant secretary of defence Bing West, he says he was determined to make himself useful in the job, writing "I did as well as I could for as long as I could."

“In my view, when the president asks you to do something, you don’t play Hamlet on the wall, wringing your hands,” he writes in the new book, out next week. “To quote a great American athletic company’s slogan: ‘Just do it.’ So long as you are prepared, you say yes.”

Mr Mattis also admits that he left the administration when he felt the president was no longer taking his advice.

“When my concrete solutions and strategic advice, especially keeping faith with allies, no longer resonated, it was time to resign,” he writes, “despite the limitless joy I felt serving alongside our troops in defence of the constitution.”

The former secretary previously stated that the book would focus more on his career and how he ended up in the position than his futile relationship with the president, who had no prior military experience. That wish may not be met, as the memoir is already being scrutinised for insight into the Trump administration’s brash military action. Still, the book does touch on the former secretary’s role, particularly noting his surprise as being asked to serve at all.

“I figured that my strong support of Nato and my dismissal of the use of torture on prisoners would have the president-elect looking for another candidate,” he writes about his shock at the vice president elect Mike Pence calling him to discuss the job.

He then details an “amiable” meeting at the Trump National Golf Club in Bedminster, New Jersey during Thanksgiving in 2016, after comparing his role to taking oxygen mask during a plane crash he imagined on his cross-country flight to the club.

"On my flight out of Denver, the flight attendant’s standard safety briefing caught my attention: If cabin pressure is lost, masks will fall…Put your own mask on first, then help others around you," he writes, in an excerpt obtained by The Wall Street Journal. "In that moment, those familiar words seemed like a metaphor: To preserve our leadership role, we needed to get our own country’s act together first, especially if we were to help others."

Mr Mattis in fact had to be given a special waiver to serve as secretary of defence, having only been out of the military for three years; federal law dictates that the secretary must have seven years of distance from active duty. In his new book, he expresses surprise that he was asked to bypass this rule. He also maintains that he would have taken for either party's president.

"When it comes to the defence of our experiment in democracy and our way of life, ideology should have nothing to do with it," he writes. "Whether asked to serve by a Democratic or a Republican, you serve."

He resigned in December 2018, writing in his letter of resignation: “Because you have the right to have a Secretary of Defence whose views are better aligned with yours on these and other subjects, I believe it is right for me to step down from my position.”

In his new memoir, he declines to make those views clear, but does voice concern for the country’s current “internal divisiveness.”

“We are diving into hostile tribes cheering against each other, fuelled by emotion and a mutual disdain that jeopardizes our future, instead of rediscovering our common ground and finding solutions,” a passage reads.

It’s unclear what he is talking about.