We are given the differential equation:
\[
\left( \frac{2 + \sin x}{1 + y} \right) \frac{dy}{dx} = -\cos x
\]
Step 1: Separate the variables
Multiply both sides by \( 1 + y \):
\[
\frac{dy}{dx} = -\cos x \cdot \frac{1 + y}{2 + \sin x}
\]
Rewriting and separating:
\[
\frac{dy}{1 + y} = -\frac{\cos x}{2 + \sin x} dx
\]
Step 2: Integrate both sides
Left-hand side:
\[
\int \frac{dy}{1 + y} = \ln|1 + y|
\]
Right-hand side:
Let \( u = 2 + \sin x \Rightarrow \frac{du}{dx} = \cos x \Rightarrow dx = \frac{du}{\cos x} \), but more cleanly:
\[
\int \frac{-\cos x}{2 + \sin x} dx
\]
Let \( u = 2 + \sin x \Rightarrow du = \cos x \, dx \Rightarrow dx = \frac{du}{\cos x} \)
So:
\[
\int \frac{-\cos x}{u} dx = -\int \frac{1}{u} du = -\ln|u| = -\ln|2 + \sin x|
\]
Thus:
\[
\ln|1 + y| = -\ln|2 + \sin x| + C
\Rightarrow \ln|1 + y| + \ln|2 + \sin x| = C
\Rightarrow \ln| (1 + y)(2 + \sin x) | = C
\]
Take exponentials:
\[
(1 + y)(2 + \sin x) = A \quad \text{where \( A = e^C \)}
\]
Step 3: Apply initial condition \( y(0) = 2 \)
At \( x = 0 \), \( \sin 0 = 0 \Rightarrow 2 + \sin 0 = 2 \)
\[
(1 + 2)(2) = A \Rightarrow A = 6
\]
So the general solution is:
\[
(1 + y)(2 + \sin x) = 6
\Rightarrow 1 + y = \frac{6}{2 + \sin x}
\Rightarrow y = \frac{6}{2 + \sin x} - 1
\]
Step 4: Evaluate \( y\left( \frac{\pi}{2} \right) \)
\[
\sin\left( \frac{\pi}{2} \right) = 1
\Rightarrow y = \frac{6}{2 + 1} - 1 = \frac{6}{3} - 1 = 2 - 1 = \boxed{1}
\]