From 157f20c8e1ff6a2191b44f1e7ebe696846060618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bahad=C4=B1r=20Kandemir?= Date: Thu, 22 Oct 2015 22:29:19 +0300 Subject: [PATCH] Split state files --- consul/config.sls | 40 +++++++++ consul/init.sls | 212 +-------------------------------------------- consul/install.sls | 149 +++++++++++++++++++++++++++++++ consul/service.sls | 23 +++++ pillar.example | 6 ++ 5 files changed, 222 insertions(+), 208 deletions(-) create mode 100644 consul/config.sls create mode 100644 consul/install.sls create mode 100644 consul/service.sls diff --git a/consul/config.sls b/consul/config.sls new file mode 100644 index 0000000..1525cde --- /dev/null +++ b/consul/config.sls @@ -0,0 +1,40 @@ +{% from "consul/map.jinja" import consul with context %} + +consul-config: + file.managed: + - source: salt://consul/files/config.json + - template: jinja + - name: /etc/consul.d/config.json + {% if consul.service != False %} + - watch_in: + - service: consul + {% endif %} + - user: consul + - group: consul + - require: + - user: consul + +{% for script in consul.scripts %} +consul-script-install-{{ loop.index }}: + file.managed: + - source: {{ script.source }} + - name: {{ script.name }} + - template: jinja + - user: consul + - group: consul + - mode: 0755 +{% endfor %} + +consul-script-config: + file.managed: + - source: salt://consul/files/services.json + - name: /etc/consul.d/services.json + - template: jinja + {% if consul.service != False %} + - watch_in: + - service: consul + {% endif %} + - user: consul + - group: consul + - require: + - user: consul diff --git a/consul/init.sls b/consul/init.sls index 67f0d47..a04a2cd 100644 --- a/consul/init.sls +++ b/consul/init.sls @@ -1,210 +1,6 @@ {% from "consul/map.jinja" import consul with context %} -unzip: - pkg.installed - -/usr/local/bin: - file.directory: - - makedirs: True - -consul_user: - group.present: - - name: consul - user.present: - - name: consul - - createhome: false - - system: true - - groups: - - consul - - require: - - group: consul - -consul_config_dir: - file.directory: - - name: /etc/consul.d - - user: consul - - group: consul - -consul_runtime_dir: - file.directory: - - name: /var/consul - - user: consul - - group: consul - -consul_data_dir: - file.directory: - - name: /usr/local/share/consul - - user: consul - - group: consul - - makedirs: True - -# Consul agent -consul_download: - file.managed: - - name: /tmp/{{ consul.version }}_linux_amd64.zip - - source: https://dl.bintray.com/mitchellh/consul/{{ consul.version }}_linux_amd64.zip - - source_hash: sha1={{ consul.hash }} - - unless: test -f /usr/local/bin/consul-{{ consul.version }} - -consul_extract: - cmd.wait: - - name: unzip /tmp/{{ consul.version }}_linux_amd64.zip -d /tmp - - watch: - - file: consul_download - -consul_install: - file.rename: - - name: /usr/local/bin/consul-{{ consul.version }} - - source: /tmp/consul - - require: - - file: /usr/local/bin - - watch: - - cmd: consul_extract - -consul_clean: - file.absent: - - name: /tmp/{{ consul.version }}_linux_amd64.zip - - watch: - - file: consul_install - -consul_link: - file.symlink: - - target: consul-{{ consul.version }} - - name: /usr/local/bin/consul - - watch: - - file: consul_install - -# Consul template engine -consul_template_download: - file.managed: - - name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip - - source: https://github.com/hashicorp/consul-template/releases/download/v{{ consul.template_version }}/consul_template_{{ consul.template_version }}_linux_amd64.zip - - source_hash: sha1={{ consul.template_hash }} - - unless: test -f /usr/local/bin/consul-template-{{ consul.template_version }} - -consul_template_extract: - cmd.wait: - - name: unzip /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip -d /tmp - - watch: - - file: consul_template_download - -consul_template_install: - file.rename: - - name: /usr/local/bin/consul-template-{{ consul.template_version }} - - source: /tmp/consul-template - - require: - - file: /usr/local/bin - - watch: - - cmd: consul_template_extract - -consul_template_clean: - file.absent: - - name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip - - watch: - - file: consul_template_install - -consul_template_link: - file.symlink: - - target: consul-template-{{ consul.template_version }} - - name: /usr/local/bin/consul-template - - watch: - - file: consul_template_install - -# Consul UI -consul_ui_download: - file.managed: - - name: /tmp/{{ consul.ui_version }}_web_ui.zip - - source: https://dl.bintray.com/mitchellh/consul/{{ consul.ui_version }}_web_ui.zip - - source_hash: sha1={{ consul.ui_hash }} - - unless: test -d /usr/local/share/consul/ui-{{ consul.ui_version }} - -consul_ui_extract: - cmd.wait: - - name: unzip /tmp/{{ consul.ui_version }}_web_ui.zip -d /tmp/ - - watch: - - file: consul_ui_download - -consul_ui_install: - file.rename: - - name: /usr/local/share/consul/ui-{{ consul.ui_version }} - - source: /tmp/dist - - require: - - file: /usr/local/share/consul - - watch: - - cmd: consul_ui_extract - -consul_ui_clean: - file.absent: - - name: /tmp/{{ consul.ui_version }}_web_ui.zip - - watch: - - file: consul_ui_install - -consul_ui_link: - file.symlink: - - target: ui-{{ consul.ui_version }} - - name: /usr/local/share/consul/ui - - watch: - - file: consul_ui_install - -consul_init_script: - file.managed: - {% if salt['test.provider']('service') == 'upstart' %} - - source: salt://consul/files/consul.upstart - - name: /etc/init/consul.conf - - mode: 0644 - {% else %} - - source: salt://consul/files/consul.sysvinit - - name: /etc/init.d/consul - - mode: 0755 - {% endif %} - {% if consul.service != False %} - - watch_in: - - service: consul - {% endif %} - - -consul_config: - file.managed: - - source: salt://consul/files/config.json - - template: jinja - - name: /etc/consul.d/config.json - {% if consul.service != False %} - - watch_in: - - service: consul - {% endif %} - - user: consul - - group: consul - - require: - - user: consul - -{% for script in consul.scripts %} -consul_service_register_{{ loop.index }}: - file.managed: - - source: {{ script.source }} - - name: {{ script.name }} - - template: jinja - - user: consul - - group: consul - - mode: 0755 -{% endfor %} - -consul_service_register_config: - file.managed: - - source: salt://consul/files/services.json - - name: /etc/consul.d/services.json - - template: jinja - {% if consul.service != False %} - - watch_in: - - service: consul - {% endif %} - - user: consul - - group: consul - - require: - - user: consul - -{% if consul.service != False %} -consul_service: - service.running: - - name: consul -{% endif %} - +include: + - consul.install + - consul.config + - consul.service diff --git a/consul/install.sls b/consul/install.sls new file mode 100644 index 0000000..b305fbc --- /dev/null +++ b/consul/install.sls @@ -0,0 +1,149 @@ +{% from "consul/map.jinja" import consul with context %} + +unzip: + pkg.installed + +/usr/local/bin: + file.directory: + - makedirs: True + +# Create consul user +consul-user: + group.present: + - name: consul + user.present: + - name: consul + - createhome: false + - system: true + - groups: + - consul + - require: + - group: consul + +# Create directories +consul-config-dir: + file.directory: + - name: /etc/consul.d + - user: consul + - group: consul + +consul-runtime-dir: + file.directory: + - name: /var/consul + - user: consul + - group: consul + +consul-data-dir: + file.directory: + - name: /usr/local/share/consul + - user: consul + - group: consul + - makedirs: + +# Install agent +consul-download: + file.managed: + - name: /tmp/{{ consul.version }}_linux_amd64.zip + - source: https://dl.bintray.com/mitchellh/consul/{{ consul.version }}_linux_amd64.zip + - source_hash: sha1={{ consul.hash }} + - unless: test -f /usr/local/bin/consul-{{ consul.version }} + +consul-extract: + cmd.wait: + - name: unzip /tmp/{{ consul.version }}_linux_amd64.zip -d /tmp + - watch: + - file: consul-download + +consul-install: + file.rename: + - name: /usr/local/bin/consul-{{ consul.version }} + - source: /tmp/consul + - require: + - file: /usr/local/bin + - watch: + - cmd: consul-extract + +consul-clean: + file.absent: + - name: /tmp/{{ consul.version }}_linux_amd64.zip + - watch: + - file: consul-install + +consul-link: + file.symlink: + - target: consul-{{ consul.version }} + - name: /usr/local/bin/consul + - watch: + - file: consul-install + +# Install UI +consul-ui-download: + file.managed: + - name: /tmp/{{ consul.ui_version }}_web_ui.zip + - source: https://dl.bintray.com/mitchellh/consul/{{ consul.ui_version }}_web_ui.zip + - source_hash: sha1={{ consul.ui_hash }} + - unless: test -d /usr/local/share/consul/ui-{{ consul.ui_version }} + +consul-ui-extract: + cmd.wait: + - name: unzip /tmp/{{ consul.ui_version }}_web_ui.zip -d /tmp/ + - watch: + - file: consul-ui-download + +consul-ui-install: + file.rename: + - name: /usr/local/share/consul/ui-{{ consul.ui_version }} + - source: /tmp/dist + - require: + - file: /usr/local/share/consul + - watch: + - cmd: consul-ui-extract + +consul-ui-clean: + file.absent: + - name: /tmp/{{ consul.ui_version }}_web_ui.zip + - watch: + - file: consul-ui-install + +consul-ui-link: + file.symlink: + - target: ui-{{ consul.ui_version }} + - name: /usr/local/share/consul/ui + - watch: + - file: consul-ui-install + +# Install template renderer +consul-template-download: + file.managed: + - name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip + - source: https://github.com/hashicorp/consul-template/releases/download/v{{ consul.template_version }}/consul_template_{{ consul.template_version }}_linux_amd64.zip + - source_hash: sha1={{ consul.template_hash }} + - unless: test -f /usr/local/bin/consul-template-{{ consul.template_version }} + +consul-template-extract: + cmd.wait: + - name: unzip /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip -d /tmp + - watch: + - file: consul-template-download + +consul-template-install: + file.rename: + - name: /usr/local/bin/consul-template-{{ consul.template_version }} + - source: /tmp/consul-template + - require: + - file: /usr/local/bin + - watch: + - cmd: consul-template-extract + +consul-template-clean: + file.absent: + - name: /tmp/consul_template_{{ consul.template_version }}_linux_amd64.zip + - watch: + - file: consul-template-install + +consul-template-link: + file.symlink: + - target: consul-template-{{ consul.template_version }} + - name: /usr/local/bin/consul-template + - watch: + - file: consul-template-install diff --git a/consul/service.sls b/consul/service.sls new file mode 100644 index 0000000..afbfc38 --- /dev/null +++ b/consul/service.sls @@ -0,0 +1,23 @@ +{% from "consul/map.jinja" import consul with context %} + +consul-init-script: + file.managed: + {% if salt['test.provider']('service') == 'upstart' %} + - source: salt://consul/files/consul.upstart + - name: /etc/init/consul.conf + - mode: 0644 + {% else %} + - source: salt://consul/files/consul.sysvinit + - name: /etc/init.d/consul + - mode: 0755 + {% endif %} + {% if consul.service != False %} + - watch_in: + - service: consul + {% endif %} + +{% if consul.service != False %} +consul-service: + service.running: + - name: consul +{% endif %} diff --git a/pillar.example b/pillar.example index 03be44e..4fb85ef 100644 --- a/pillar.example +++ b/pillar.example @@ -1,16 +1,22 @@ consul: service: true + config: server: true bind_addr: 0.0.0.0 + enable_debug: true + datacenter: eu + encrypt: "RIxqpNlOXqtr/j4BgvIMEw==" + bootstrap_expect: 3 retry_interval: 15s retry_join: - 1.1.1.1 - 2.2.2.2 + register: - name: Redis checks: