The Template Based Config Changes document in Junos PyEZ walks you through this process and includes codes samples.