If we have an extension of groups (say algebraic groups or group schemes) $1\to F\to P\to G\to 1$, then $P$ is a principal $F$-bundle over $G$ (is it locally trivial?). How about going in the opposite direction?

Question.Let $F$ and $G$ be groups. $P$ be a principal $F$-bundle over $G$. When does $P$ carry a structure of a group such that $1\to F\to P\to G\to 1$ is an extension? How to classify all such structures?

Sounds connected with (some kind of) group cohomology of $G$ with coefficients in $F$, but I can't figure out what exactly this group is. Does the obstruction lie in some $H^2$, which is only a pointed set, and if it vanishes then the structures are classified by the corresponding $H^1$? The fact that the principal bundle itself corresponds to an element of $H^1(G, F)$ confuses me a bit.

For example, if $G$ is an abelian variety and $L$ a line bundle on it, then we have the corresponding principal $F=\mathbb G_m$-bundle $P_L$. When does it give an extension of $G$ by $\mathbb G_m$?