We have a three server cluster using AlwaysOn technology, and have created an Availability Group for the SSISDB catalog.
How would you change the code to only execute on the primary server?
If you're talking about accessing the primary replica (and the Availability Group database on the primary replica) at all times, this is where the Availability Group Listener comes into play.
See this quote from BOL on the topic:
So instead of referencing a particular server, by using the Listener you can be pointing at the current primary replica of the AG.
Edit: As per Aaron's comment below, you may be looking for more specifics surrounding the particular catalog DB (as opposed to generic handling as above). You can find more information regarding this on the MSDN SSIS blog here. If both of these points explained in this answer do not clear up your question, please clarify what exactly you're looking to do.