feat: new playbook to manipulate services from portal

- update-service-state.yml
  service_state
    up
    down
    upgrade
master
Sven Ketelsen 4 years ago
parent 8baf07a85c
commit dc31119c05

@ -37,3 +37,4 @@ awx_job_templates:
- name: "remove-service"
- name: "restore-database-backup"
- name: "update-monitoring"
- name: "update-service-state"

@ -0,0 +1,15 @@
---
service_state_commands:
- key: up
command: "docker-compose up -d"
- key: down
command: "docker-compose down"
- key: upgrade
command: "docker-compose pull && docker-compose down && docker-compose up -d"
service_state_command: "{{ service_state_commands
| selectattr('key', 'match', service_state )
| map(attribute='command')
| list
| first }}"

@ -0,0 +1,17 @@
---
### tags:
- name: "Setting service state for <{{ service_id }}> to <{{ service_state }}>"
ansible.builtin.shell: "{{ service_state_command }}"
args:
chdir: '{{ service_base_path }}/{{ service_id }}'
register: service_state_command_output
- name: "Printing service state stdout_lines"
debug:
msg: "{{ service_state_command_output }}"
delegate_to: 127.0.0.1
become: false
when:
- debug

@ -469,7 +469,7 @@ Variables.userId(authenticatedUserId)</camunda:script>
<bpmn2:extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="progress_current">${1}</camunda:outputParameter>
<camunda:outputParameter name="progress_max">${6}</camunda:outputParameter>
<camunda:outputParameter name="progress_max">${3}</camunda:outputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_0r057gs</bpmn2:incoming>
@ -633,7 +633,7 @@ Variables.userId(authenticatedUserId)</camunda:script>
<bpmn2:extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="progress_current">${1}</camunda:outputParameter>
<camunda:outputParameter name="progress_max">${2}</camunda:outputParameter>
<camunda:outputParameter name="progress_max">${4}</camunda:outputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_1c39717</bpmn2:incoming>
@ -646,7 +646,7 @@ Variables.userId(authenticatedUserId)</camunda:script>
<camunda:outputParameter name="vorgang_status_text">Service gestartet</camunda:outputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_1xmeor7</bpmn2:incoming>
<bpmn2:incoming>Flow_00jy6ae</bpmn2:incoming>
<bpmn2:outgoing>Flow_1rv440f</bpmn2:outgoing>
</bpmn2:intermediateThrowEvent>
<bpmn2:callActivity id="Activity_1x3naca" name="Management Benachrichtigung senden" calledElement="smardigo-management-message">
@ -677,7 +677,26 @@ Variables.userId(authenticatedUserId)</camunda:script>
<bpmn2:linkEventDefinition id="LinkEventDefinition_0pzbq2j" name="Maintenance" />
</bpmn2:intermediateCatchEvent>
<bpmn2:sequenceFlow id="Flow_1yyd3eu" sourceRef="Event_00k19j1" targetRef="Activity_08ca2ix" />
<bpmn2:callActivity id="Activity_1ajfp6d" name="Backups wiederherstellen" calledElement="smardigo-management-action">
<bpmn2:callActivity id="Activity_1ajfp6d" name="Service stoppen" calledElement="smardigo-management-action">
<bpmn2:extensionElements>
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in variables="all" />
<camunda:in sourceExpression="update-service-state" target="smardigoManagementAction" />
<camunda:in sourceExpression="Service stoppen" target="comment" />
<camunda:inputOutput>
<camunda:inputParameter name="extraVariables">
<camunda:map>
<camunda:entry key="service_state">down</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:outputParameter name="progress_current">${progress_current + 1}</camunda:outputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_09id3fl</bpmn2:incoming>
<bpmn2:outgoing>Flow_1xmeor7</bpmn2:outgoing>
</bpmn2:callActivity>
<bpmn2:sequenceFlow id="Flow_1xmeor7" sourceRef="Activity_1ajfp6d" targetRef="Activity_0imh8ol" />
<bpmn2:callActivity id="Activity_0imh8ol" name="Backups wiederherstellen" calledElement="smardigo-management-action">
<bpmn2:extensionElements>
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in variables="all" />
@ -692,10 +711,29 @@ Variables.userId(authenticatedUserId)</camunda:script>
<camunda:outputParameter name="progress_current">${progress_current + 1}</camunda:outputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_09id3fl</bpmn2:incoming>
<bpmn2:outgoing>Flow_1xmeor7</bpmn2:outgoing>
<bpmn2:incoming>Flow_1xmeor7</bpmn2:incoming>
<bpmn2:outgoing>Flow_00a7lij</bpmn2:outgoing>
</bpmn2:callActivity>
<bpmn2:sequenceFlow id="Flow_1xmeor7" sourceRef="Activity_1ajfp6d" targetRef="Event_1t6u09w" />
<bpmn2:sequenceFlow id="Flow_00a7lij" sourceRef="Activity_0imh8ol" targetRef="Activity_1wksrnu" />
<bpmn2:callActivity id="Activity_1wksrnu" name="Service starten" calledElement="smardigo-management-action">
<bpmn2:extensionElements>
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in variables="all" />
<camunda:in sourceExpression="update-service-state" target="smardigoManagementAction" />
<camunda:in sourceExpression="Service starten" target="comment" />
<camunda:inputOutput>
<camunda:inputParameter name="extraVariables">
<camunda:map>
<camunda:entry key="service_state">up</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:outputParameter name="progress_current">${progress_current + 1}</camunda:outputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_00a7lij</bpmn2:incoming>
<bpmn2:outgoing>Flow_00jy6ae</bpmn2:outgoing>
</bpmn2:callActivity>
<bpmn2:sequenceFlow id="Flow_00jy6ae" sourceRef="Activity_1wksrnu" targetRef="Event_1t6u09w" />
</bpmn2:subProcess>
<bpmn2:boundaryEvent id="Event_007p32d" name="when vorgang_status == 30 (freigegeben)" attachedToRef="Activity_1wq2muu">
<bpmn2:outgoing>Flow_1n08t19</bpmn2:outgoing>
@ -1456,9 +1494,17 @@ Server bei Hetzner löschen
<bpmndi:BPMNShape id="Activity_1t8u7l0_di" bpmnElement="Activity_1t8u7l0" isExpanded="true">
<dc:Bounds x="3630" y="2900" width="2420" height="940" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_00jy6ae_di" bpmnElement="Flow_00jy6ae">
<di:waypoint x="4960" y="3340" />
<di:waypoint x="5692" y="3340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_00a7lij_di" bpmnElement="Flow_00a7lij">
<di:waypoint x="4800" y="3340" />
<di:waypoint x="4860" y="3340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1xmeor7_di" bpmnElement="Flow_1xmeor7">
<di:waypoint x="4640" y="3340" />
<di:waypoint x="5692" y="3340" />
<di:waypoint x="4700" y="3340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1yyd3eu_di" bpmnElement="Flow_1yyd3eu">
<di:waypoint x="3850" y="3338" />
@ -1656,6 +1702,12 @@ Server bei Hetzner löschen
<bpmndi:BPMNShape id="Activity_1ajfp6d_di" bpmnElement="Activity_1ajfp6d" bioc:stroke="#fb8c00" bioc:fill="#ffe0b2" color:background-color="#ffe0b2" color:border-color="#fb8c00">
<dc:Bounds x="4540" y="3300" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0imh8ol_di" bpmnElement="Activity_0imh8ol" bioc:stroke="#fb8c00" bioc:fill="#ffe0b2" color:background-color="#ffe0b2" color:border-color="#fb8c00">
<dc:Bounds x="4700" y="3300" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1wksrnu_di" bpmnElement="Activity_1wksrnu" bioc:stroke="#fb8c00" bioc:fill="#ffe0b2" color:background-color="#ffe0b2" color:border-color="#fb8c00">
<dc:Bounds x="4860" y="3300" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1mctiwx_di" bpmnElement="Activity_1mctiwx" bioc:stroke="#8e24aa" bioc:fill="#e1bee7" color:background-color="#e1bee7" color:border-color="#8e24aa">
<dc:Bounds x="3940" y="2450" width="100" height="80" />
</bpmndi:BPMNShape>

@ -0,0 +1,101 @@
---
# Parameters:
# playbook inventory
# stage := the type of the stage (e.g. dev, int, qa, prod)
# tenant_id := (unique key for the tenant, e.g. customer)
# cluster_name := (business name for the cluster, e.g. product, department )
# cluster_services_str := (services to setup, e.g. 'connect,wordpress')
# service_state := the state of the service (e.g. up, down, upgrade)
# smardigo message callback
# scope_id := (scope id of the management process)
# process_instance_id := (process instance id of the management process)
# smardigo_management_action := (smardigo management action anme of the management process)
#############################################################
# Creating inventory dynamically for given parameters
#############################################################
- hosts: localhost
gather_facts: false
connection: local
pre_tasks:
- name: "Check if ansible version is at least 2.10.x"
assert:
that:
- ansible_version.major >= 2
- ansible_version.minor >= 10
msg: "The ansible version has to be at least ({{ ansible_version.full }})"
- name: "Parsing cluster_services_str into cluster_services"
set_fact:
cluster_services: "{{ cluster_services_str | split(',') }}"
tasks:
- name: Add hosts
add_host:
name: "{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-01"
groups:
- "stage_{{ stage }}"
- "{{ cluster_service }}"
- "{{ item }}"
changed_when: False
with_items: "{{ cluster_services }}"
when: item in ['connect', 'connect_wordpress']
#############################################################
# Stop services for created inventory
#############################################################
- hosts: "stage_{{ stage }}"
serial: "{{ serial_number | default(1) }}"
remote_user: root
vars:
service_state: up
ansible_ssh_host: "{{ stage_server_domain }}"
pre_tasks:
- name: "Import autodiscover pre-tasks"
include_tasks: tasks/autodiscover_pre_tasks.yml
roles:
- role: service-state
vars:
service_id: "{{ connect_id }}"
when: "'connect' in group_names"
- role: service-state
vars:
service_id: "{{ wordpress_id }}"
when: "'connect_wordpress' in group_names"
#############################################################
# Sending smardigo management message to process
#############################################################
- hosts: "stage_{{ stage }}"
serial: "{{ serial_number | default(1) }}"
gather_facts: false
connection: local
run_once: true
tasks:
- name: "Sending smardigo management message <{{ smardigo_management_action }}> to <{{ scope_id }}/{{ process_instance_id }}>"
uri:
url: "{{ smardigo_management_url }}"
method: POST
body_format: json
body: "{{ lookup('template','smardigo-management-message.json.j2') }}"
headers:
accept: "*/*"
Content-Type: "application/json"
Smardigo-User-Token: "{{ smardigo_management_token }}"
status_code: [200]
retries: 5
delay: 5
delegate_to: 127.0.0.1
when:
- scope_id is defined
- process_instance_id is defined
- smardigo_management_action is defined
Loading…
Cancel
Save