GUANTANAMO BAY, Cuba — On a rare visit to the home of the U.S. military’s prison for terror suspects, Defense Secretary Jim Mattis offered a pep talk Thursday to American troops — and urged them to always be ready for war.

“I need you to be at the top of your game,” he told an assembly of several hundred troops, citing their roles both as a fighting force and as a positive example to a politically divided America of how to work together.

The unannounced visit was the first by a defense secretary since Donald H. Rumsfeld came here in January 2002 shortly after the first prisoners arrived from Afghanistan.

Mattis did not discuss the Trump administration’s plans for the detention center, nor did he visit it. But he stressed the importance of keeping the Navy base as a U.S. toehold in southeastern Cuba. He said it will not be abandoned, regardless of the future of the prison.

“We need this base badly,” he said, as a strategic spot to conduct humanitarian relief and other naval operations, as it had before the Sept. 11, 2001, attacks.

Mattis spoke to three groups of troops, offering holiday greetings and thanks for their service. He also fielded their questions as he stood in a warm sun, and found that the prospect of war with North Korea was on their minds.

Mattis said international efforts to compel North Korea to give up its nuclear weapons are focused for now on diplomacy. He also emphasized that effective diplomacy must be backed by a credible threat of military force.

“We need to keep this in a diplomatic framework for solution,” he said,. But he added that in the event diplomacy fails, “you all have to be ready to go.”

Speaking to a few dozen Marines at a rifle range, Mattis described North Korea as a “not yet imminent but a direct threat to the United States.”

At another point, at an outdoor movie theater where troops and civilian staff had gathered, Mattis said that during the Cold War, U.S. leaders had been confident that Russia and China did not want to start a nuclear war.

“That may be an assumption we cannot make” with North Korean leader Kim Jong Un, he said.

Mattis was asked if the U.S. has worked out planning for a post-war Korean Peninsula, including the issue of reunifying the North and South. He answered indirectly by saying, “We’re probably not where we need to be” in such discussions with Russia, China and others.

Mattis arrived at Guantanamo Wednesday night and was accompanied by an Associated Press reporter. His overnight stop at Guantanamo comes amid uncertainty over the Trump administration’s policy on continued use of the military prison.

Later Mattis was flying to Mayport Naval Station in Florida, and planned on Friday to visit Camp Lejeune and Fort Bragg in North Carolina.

President Donald Trump hasn’t released any Guantanamo prisoners or added any to the list of men who have been officially cleared to go home or to a third country for resettlement.

Forty-one prisoners remain in detention. Ten have been charged by a military commission. Five have been cleared to leave, but their status is in doubt under the current administration.

That leaves 26 in indefinite confinement, though some eventually could be cleared for release, too, or prosecuted. Prisoners’ lawyers are considering filing new challenges, arguing that a policy of no releases means the detainees’ confinement no longer can be legally justified as a temporary wartime measure.

President Barack Obama tried to close the detention center, but was thwarted by Congress. Lawmakers objected to transferring detainees to confinement facilities in the United States.

Mattis has said little publicly about Guantanamo Bay since taking office in January.

The subject wasn’t raised in his Senate confirmation hearing.

In response to written questions submitted to him before that hearing, he said: “I believe that we should develop a repeatable detainee policy that is appropriate for enemy combatants taken prisoner under such circumstances.”

Asked whether the U.S. should keep detainees without trial, he said: “Long-term detention is appropriate when an unprivileged enemy belligerent poses a continuing significant threat to the security of the United States.”