Gauge theories in curved spacetimes: (Anomalous) Ward identities and the underlying L ∞ algebra