This is somewhat similar to the question about using an indefinite article with "water". In English, we often use the indefinite article with an uncountable noun as a short cut to mean "one portion/serving of [noun]."
That's what the usage "take a shit" does - it uses the indefinite article to say that the person doing the action is going to create one "portion" of shit from beginning to end, just like "I'd like a coffee" says that you want one cup of coffee, even though the noun coffee is normally uncountable.
In your example, the speaker is using "a shit" to emphasize that it is one entire piece of shit of the size that a person would usually produce in one, um, sitting. This makes the literary effect more vivid than just saying "some shit," which could be a little smear or a small amount. Instead, this definite article is telling you that someone apparently performed a full and entire excretory activity directly into the ashtray.
I do believe that this particular usage of "a shit" is more common in British English than in American English - your excerpt reminds me of an Irvine Welsh novel. In American English, as mentioned in the comments, it would be more usual to refer to the object as "a turd" or something like that.