The relationship between the topology of a network and specific types of dynamics unfolding on it has been extensively studied in network science. One type of dynamics that has attracted increasing attention because of its several implications is opinion formation. A phenomenon of particular importance that is known to take place in opinion formation is the appearance of echo chambers, also known as social bubbles. In the present work, we approach this phenomenon, with emphasis on the influence of contrarian opinions, by considering an adaptation of the Sznajd dynamics of opinion formation performed on several network models (Watts-Strogatz, Erdos-Renyi, Barabasi-Albert, Random geometric graph, and Stochastic Block Model). In order to take into account real-world social dynamics, we implement a reconnection scheme where agents can reconnect their contacts after changing their opinion. We analyse the relationship between topology and opinion dynamics by considering two measurements: opinion diversity and network modularity. Two specific situations have been considered:(i) the agents can reconnect only with others sharing the same opinion; and (ii) same as in the previous case, but with the agents reconnecting only within a limited neighborhood. Several interesting results have been obtained, including the identification of cases characterized not only by high diversity/high modularity, but also by low diversity/high modularity. We also found that the restricted reconnection case reduced the chances of echo chamber formation and also led to smaller echo chambers.