소스 검색

fix generation of config for newer versions of consul

Chris Mague 6 년 전
부모
커밋
860e7005e6
3개의 변경된 파일55개의 추가작업 그리고 2개의 파일을 삭제
  1. 43 0
      files/consul_cloud_setup_post_1.2
  2. 2 2
      tasks/binary_install.yml
  3. 10 0
      tasks/cloud_configure.yml

+ 43 - 0
files/consul_cloud_setup_post_1.2

@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+import json
+import urllib2
+import sys
+import re
+
+URL = 'http://169.254.169.254/latest/user-data'
+
+try:
+    data = json.load(urllib2.urlopen(URL))
+except:
+    print >> sys.stderr, 'Was not able to connect to the Amazon API'
+    sys.exit(2)
+
+# Python doesn't like a list of 1
+tags = []
+tags.append(data['role'])
+
+consul_settings = {
+                        'data_dir': '/opt/consul/data',
+                        'client_addr': '0.0.0.0',
+                        'datacenter': data['domain'],
+                        'domain': data['domain'],
+                        'log_level': "INFO",
+                        'enable_script_checks': True,
+                        'service': [
+                                        { 'name': data['role'], 'tags': tags, 'checks': [{'args': ['/bin/true'], 'interval': '2s'}] }
+                                        ]
+
+}
+
+if data['consul_master'] == '127.0.0.1':
+    consul_settings['bootstrap_expect'] = 1
+else:
+    consul_settings['retry_join'] = [data['consul_master']]
+
+if re.match('consul', data['role']) is not None:
+    consul_settings['server'] = True
+
+main_config = open("/opt/consul/etc/config.json", "w")
+main_config.write(json.dumps(consul_settings))
+main_config.close()

+ 2 - 2
tasks/binary_install.yml

@@ -27,7 +27,7 @@
     dest: "{{cloud_consul_download_dir}}/{{cloud_consul_version}}_web_ui.zip"
   tags:
     - install
-  when: ansible_distribution_version | version_compare('1.2', '<') 
+  when: cloud_consul_version | version_compare('1.2', '<') 
 
 - name: Ensure Consul Install Dir exists
   file:
@@ -68,7 +68,7 @@
     remote_src: True
   tags:
     - install
-  when: ansible_distribution_version | version_compare('1.2', '<')
+  when: cloud_consul_version | version_compare('1.2', '<')
 
 - name: ensures consul command has the right permissions
   file:

+ 10 - 0
tasks/cloud_configure.yml

@@ -6,7 +6,17 @@
     dest: /usr/local/bin/consul_cloud_setup
     owner: root
     group: root
+    mode: "0755" 
+  when: cloud_consul_version | version_compare('1.2', '<') 
+
+- name: Install the Consul Cloud Configure Script
+  copy:
+    src: consul_cloud_setup_post_1.2
+    dest: /usr/local/bin/consul_cloud_setup
+    owner: root
+    group: root
     mode: "0755"
+  when: cloud_consul_version | version_compare('1.2', '>=') 
 
 - name: Setup supervisor config
   copy: