Consider the Lie group $S^1$. Recall that the associated Lie algebra is $\mathbb{R}$.
Let $M$ be a manifold. Consider the second de-Rham cohomology group $H^2(M,\mathbb{R})$.
Let $\Omega\in H^2(M,\mathbb{R})$ be an integral cohomology class; that is, it is image of an element of $H^2(M,\mathbb{Z})$ under the natural map $H^2(M,\mathbb{Z})\rightarrow H^2(M,\mathbb{R})$. Then, we know that we can construct a principal $S^1$-bundle $P\rightarrow M$ over the manifold $M$, a connection $1$-form $\omega$ on the manifold $P$ such that, the associated curvature form (which is a $2$-form on $P$, but can be projected uniquely to a $2$-form on $M$) is precisely the $2$-form $\Omega$ that we have started with.
Question : How far can we go relaxing the condition that the structure group is abelian?
Question : Let $G$ be a Lie group and $\mathfrak{g}$ be its Lie algebra. Let $M$ be a manifold and $\Omega$ be a $\mathfrak{g}$-valued $2$-form on $M$. Under what conditions, can we find a principal $G$ bundle over the manifold $M$, and a connection on $P(M,G)$ whose curvature is $\Omega$?