diff --git a/salt/_states/consul.py b/salt/_states/consul.py index 75f67466..759258df 100644 --- a/salt/_states/consul.py +++ b/salt/_states/consul.py @@ -1,15 +1,16 @@ def external_service(name, datacenter, node, address, port, token=None): ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} - if token is None: - token = __pillar__['consul']['acl']['tokens']['default'] - - # Determine if the cluster is ready + # Determine if the cluster is ready first, before trying to get token if not __salt__["consul.cluster_ready"](): ret["result"] = True ret["comment"] = "Consul cluster is not ready." return ret + # Get token after confirming cluster is ready + if token is None: + token = __pillar__['consul']['acl']['tokens']['default'] + # Determine if the node we're attempting to register exists if __salt__["consul.node_exists"](node, address, dc=datacenter): # Determine if the service we're attempting to register exists diff --git a/salt/consul/init.sls b/salt/consul/init.sls index b97865df..c819c0f5 100644 --- a/salt/consul/init.sls +++ b/salt/consul/init.sls @@ -127,4 +127,5 @@ consul-external-{{ service.service }}: - port: {{ service.port }} - require: - pkg: python-requests + - service: consul {% endfor %}