Let $\mathbf{1}_n$ denote the $n\times n$ matrix with all entries equal to one and $E_n$ denote the $n\times n$ identity matrix. Then
$$
A_n = b\mathbf 1_n + (a-b)E_n = b\mathbf 1_n -nbE_n
$$
and
$$
B_n = A_n + \frac{1}{n}\mathbf 1_n = \left(b+\frac{1}{n}\right)\mathbf 1_n - nbE_n.
$$
In general, for a matrix $X_n=\alpha \mathbf 1_n + \beta E_n$, that is
$$
X =
\begin{pmatrix}
\alpha+\beta & \alpha & \alpha & \cdots & \alpha \\
\alpha & \alpha+\beta & \alpha & \cdots & \alpha \\
\alpha & \alpha & \alpha+\beta & \cdots & \alpha \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
\alpha & \alpha & \alpha & \cdots & \alpha+\beta
\end{pmatrix},
$$
we can calculate the determinant by first subtracting the second row from the first to get
$$
\det X_n = \det
\begin{pmatrix}
\beta & -\beta & 0 & \cdots & 0 \\
\alpha & \alpha+\beta & \alpha & \cdots & \alpha \\
\alpha & \alpha & \alpha+\beta & \cdots & \alpha \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
\alpha & \alpha & \alpha & \cdots & \alpha+\beta
\end{pmatrix},
$$
and then Laplace expand with respect to the first row to obtain
$$
\det X_n =
\beta
\det X_{n-1} + \beta
\det
\begin{pmatrix}
\alpha & \alpha & \cdots & \alpha \\
\alpha & \alpha+\beta & \cdots & \alpha \\
\vdots & \vdots & \ddots & \vdots \\
\alpha & \alpha & \cdots & \alpha+\beta
\end{pmatrix}.
$$
For the second matrix, subtract the first row from all others to get
$$
\det X_n =
\beta
\det X_{n-1} + \beta
\det
\begin{pmatrix}
\alpha & \alpha & \cdots & \alpha \\
0 & \beta & \cdots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \cdots & \beta
\end{pmatrix}
=
\beta \det X_{n-1} + \alpha \beta^{n-1}
$$
Since $\det X_1=\alpha+\beta$, this recursion yields $$\det X_n=n\alpha\beta^{n-1} +\beta^n=\beta^{n-1}(n\alpha+\beta).$$
Thus, $X_n$ is invertible if and only if $\beta\neq 0$ and $n\alpha+\beta\neq 0$. In this case, we may guess that (or consider the adjugate to see that) $X^{-1}$ is of the form $X^{-1} = \gamma \mathbf 1 + \delta E_n$ as well and work out that
$$
X^{-1} = -\frac{\alpha}{\beta(n\alpha+\beta)} \mathbf 1_n + \frac{1}{\beta} E_n.
$$
In the example at hand,
$$
\det B_n = (-nb)^{n-1}(n\left(b+\frac{1}{n}\right)-nb)= (-nb)^{n-1}
$$
which is non-zero if and only if $b$ is non-zero. And
$$
B_n^{-1} = \frac{nb+1}{n^2b} \mathbf 1_n - \frac{1}{nb} E_n.
$$
However, to check that $AB^{-1}A=A$ is satisfied it is enough to show $A^2=AB$, since all matrices of the given form commute.