Sometimes you need to do some complex actions in a Salt Reactor in which case Python comes in handy.

The documentation is not very clear on how to write Python states. The main point is that Salt expects a structure that can be compiled to a Python dictionary. The run() function has to return a dictionary which resembles the state you would write with YAML.

Here’s an example to add a domain to route 53:


def run():
   '''Add domain name to route53'''

   full_name = data['name']

   subzone, name = full_name.split('.')
   zone = ""

       aws_query = __salt__['cloud.full_query']()['aws']['ec2'][full_name]['dnsName']
   except KeyError:
       dns_setup_hsd = {'setup-dns':
           {'local.test.nop': [
               {'tgt': ''},
       dns_setup_hsd = {'setup-dns':
           {'local.boto_route53.add_record': [
               {'tgt': ''},
               {'arg': [
                   '.'.join((name, zone)),

   return dns_setup_hsd