2. The inequality
$$
\sin ^{2} x+a \cos x+a^{2} \geqslant 1+\cos x
$$

holds for all $x \in \mathbf{R}$. Then the range of the real number $a$ is
$\qquad$ .
2. $a \geqslant 1$ or $a \leqslant-2$.

From the problem, we have
$$
\cos ^{2} x+(1-a) \cos x-a^{2} \leqslant 0
$$

for any $x \in \mathbf{R}$.
$$
\begin{array}{l}
\text { Let } f(t)=t^{2}+(1-a) t-a^{2}(-1 \leqslant t=\cos x \leqslant 1) . \\
\text { Then }\left\{\begin{array}{l}
f(1) \leqslant 0, \\
f(-1) \leqslant 0
\end{array}\right. \\
\Rightarrow\left\{\begin{array}{l}
1+(1-a)-a^{2} \leqslant 0, \\
1-(1-a)-a^{2} \leqslant 0
\end{array}\right. \\
\Rightarrow a \leqslant-2 \text { or } a \geqslant 1 .
\end{array}
$$