ABSTRACT Binary neutron-stars mergers widely accepted as potential progenitors of short gamma-ray bursts. After the remnant of the merger has collapsed to a black hole, a jet is powered and may breakout from the the matter expelled during the collision and the subsequent wind emission. The interaction of the jet with the ejecta may affect its dynamics and the resulting electromagnetic counterparts. We here examine how an inhomogeneous and anisotropic distribution of ejecta affects such dynamics, dictating the properties of the jet-ejecta cocoon and of the afterglow radiated by the jet upon deceleration. More specifically, we carry out general-relativistic hydrodynamical simulations of relativistic jets launched within a variety of geometrically inhomogeneous and anisotropic distributions of ejected matter. We find that different anisotropies impact the variance of the afterglow light curves as a function of the jet luminosity and ejected mass. A considerable amount of the jet energy is deposited in the cocoon through the jet-ejecta interaction with a small but important dependence on the properties of the ejecta. Furthermore, all configurations show a two-component behaviour for the polar structure of the jet, with a narrow core at large energies and Lorentz factors and a shallow segment at high latitudes from the jet axis. Hence, afterglows measured on off-axis lines of sight could be used to deduce the properties of the ejected matter, but also that the latter need to be properly accounted for when modelling the afterglow signal and the jet-launching mechanisms.