Solution (source code)

= Solution

The <mass density> becomes $\rho=\mu(2+\cos\theta)$. Integrate it over the <sphere> using the <spherical polar coordinates> and <volume element> above:
$$
M=\mu\int_0^a r^2\,dr\int_0^{2\pi}d\phi\int_0^\pi(2+\cos\theta)\sin\theta\,d\theta.
$$
The angular <integral> is $4$, since $\int_0^\pi\cos\theta\sin\theta\,d\theta=0$. Therefore
$$
\boxed{M=\frac{8\pi\mu a^3}{3}.}
$$
The term proportional to $z/r$ contributes zero by reflection across the equatorial <plane>. Thus the answer is also the <volume> $4\pi a^3/3$ times the average <mass density> $2\mu$. The undefined direction at the origin affects a single point and has no effect on this <volume integral>.