Browse Source

Refactoring...

master
Sean Johnson 3 years ago
parent
commit
f05477015c
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 9FA15B87469EA850
  1. 5
      engines/logdna.sls
  2. 10
      reactors/hook_update_fileserver.sls
  3. 8
      saltbox/master.sls
  4. 25
      saltbox/orchestrator/templates/orch_update_fileserver.j2
  5. 26
      saltbox/orchestrator/templates/reactor_update_fileserver.j2
  6. 19
      saltbox/orchestrator/update_fileserver/init.sls
  7. 2
      top.sls

5
engines/logdna.sls

@ -1,6 +1,6 @@
---
/srv/engines/logdna.py:
{{ salt.pillar.get('engines:logdna:path') }}:
file.managed:
- source: {{ salt['pillar.get']('engines:logdna:source') }}
- source_hash: {{ salt['pillar.get']('engines:logdna:checksum') }}
@ -14,5 +14,4 @@
- enable: True
- restart: True
- onchanges:
- file: /srv/engines/logdna.py
- file: {{ salt.pillar.get('engines:logdna:path') }}

10
reactors/hook_update_fileserver.sls

@ -1,10 +0,0 @@
---
{{ salt['pillar.get']('reactors:update_fileserver:path') }}:
file.managed:
- source: salt://reactors/templates/update_fileserver.j2
- template: jinja
- makedirs: True
- mode: 0755
- user: root
- group: root

8
saltbox/master.sls

@ -13,3 +13,11 @@
- watch_in:
- service: salt-master
{% endfor %}
{% for directory in salt.pillar.get('saltbox:directories', []) -%}
{{ directory }}:
file.directory:
- user: root
- group: root
- makedirs: true
{% endfor %}

25
reactors/templates/update_fileserver.j2 → saltbox/orchestrator/templates/orch_update_fileserver.j2

@ -1,21 +1,16 @@
---
{{ '{% set secret_key = "' }}{{ salt.pillar.get('hooks:fileserver:secret') }}{{ '" %}' }}
{% set telegram = salt.pillar.get('telegram', {}) -%}
{% raw %}
{% set headers = data.get('headers', {}) %}
{% set update_git_pillar = data.get('post', {}).get('pillar', 'false').lower() == 'true' %}
{% set given_key = headers.get('X-Salt-Secret') %}
{% set project_trigger = headers.get('X-Salt-Project') %}
{% set last_commit_sha = headers.get('X-Salt-SHA') %}
---
{% set remote_addr = salt.pillar.get('remote_addr') %}
{% set project_trigger = salt.pillar.get('project_trigger') %}
{% set last_commit_sha = salt.pillar.get('last_commit_sha') %}
{% set update_git_pillar = salt.pillar.get('update_git_pillar') %}
{% set telegram = salt.pillar.get('telegram') %}
{% if given_key == secret_key %}
fire_update_event:
runner.event.send:
- tag: 'hook/fileserver/update/begin'
- data:
src_ip: '{{ headers.get("Remote-Addr") }}'
src_ip: '{{ remote_addr }}'
triggered_by:
project: '{{ project_trigger }}'
commit_sha: '{{ last_commit_sha }}'
@ -39,7 +34,7 @@ fire_pillar_update_event:
runner.event.send:
- tag: 'hook/git_pillar/update/begin'
- data:
src_ip: '{{ headers.get("Remote-Addr") }}'
src_ip: '{{ remote_addr }}'
triggered_by:
project: '{{ project_trigger }}'
commit_sha: '{{ last_commit_sha }}'
@ -54,8 +49,6 @@ refresh_pillar:
dc_telegram_notification:
local.telegram.post_message:
- message: "Fileserver update completed! Triggered by `{{ project_trigger }}` commit `{{ commit_sha }}`."
{%- endraw %}
- chat_id: {{ telegram.chat_id | yaml_squote }}
- token: {{ telegram.token | yaml_squote }}
{{ "{% endif %}" }}
{% endraw %}

26
saltbox/orchestrator/templates/reactor_update_fileserver.j2

@ -0,0 +1,26 @@
---
{{ '{% set secret_key = "' }}{{ salt.pillar.get('hooks:fileserver:secret') }}{{ '" -%}' }}
{% set telegram = salt.pillar.get('telegram', {}) -%}
{% raw %}
{% set given_key = headers.get('X-Salt-Secret') %}
{% set headers = data.get('headers', {}) %}
{% set update_git_pillar = data.get('post', {}).get('pillar', 'false').lower() == 'true' %}
{% set remote_addr = headers.get('Remote-Addr') %}
{% set project_trigger = headers.get('X-Salt-Project') %}
{% set last_commit_sha = headers.get('X-Salt-SHA') %}
{% if given_key == secret_key %}
{% endraw %}
orchestrate_update_fileserver:
runner.state.orchestrate:
- args:
- mods: orchestrate.update_fileserver
- pillar:
update_git_pillar: {{ '{{ update_git_pillar }}' }}
project_trigger: {{ '{{ project_trigger }}' }}
last_commit_sha: {{ '{{ last_commit_sha }}' }}
remote_addr: {{ '{{ remote_addr }}' }}
telegram: {{ telegram | json }}
{{ '{% endif %}' }}

19
saltbox/orchestrator/update_fileserver/init.sls

@ -0,0 +1,19 @@
---
{{ salt['pillar.get']('saltbox:orchestrator:update_fileserver:path') }}:
file.managed:
- source: salt://saltbox/orchestrate/templates/orch_update_fileserver.j2
- template: jinja
- makedirs: True
- mode: 0750
- user: root
- group: root
{{ salt['pillar.get']('saltbox:reactor:update_fileserver:path') }}:
file.managed:
- source: salt://saltbox/orchestrate/templates/reactor_update_fileserver.j2
- template: jinja
- makedirs: True
- mode: 0750
- user: root
- group: root

2
top.sls

@ -15,7 +15,7 @@ base:
'roles:salt_master':
- match: grain
- engines.logdna
- reactors.hook_update_fileserver
- saltbox.orchestrator.update_fileserver
- saltbox.master
'roles:docker_host':

Loading…
Cancel
Save