Catalysis of the release of ammonia by the cleavage of a carbon-nitrogen bond or the reverse reaction with ammonia as a substrate.