Two men have been jailed after cannabis worth "nearly £2m" was grown inside a former primary school in West Wales.