-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaos.yml
94 lines (81 loc) · 2.11 KB
/
chaos.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
- name: Run chaos experiments
become: true
become_method: sudo
hosts: all
tasks:
- name: Install chaos-tools
ansible.builtin.package:
name:
- stress-ng
- iproute2
- htop
- psmisc
state: latest
- name: Clear rules before making network errors
command: tc qdisc del dev {{ ansible_default_ipv4.interface }} root
ignore_errors: true
- name: Choose random host for every group
hosts: localhost
gather_facts: false
tasks:
- name: Network problems
add_host:
name: "{{ item }}"
groups: network
with_random_choice: "{{ groups.all }}"
- name: Etcd service stop
add_host:
name: "{{ item }}"
groups: etcd
with_random_choice: "{{ groups['etcd_cluster'] }}"
- name: Patroni service stop
add_host:
name: "{{ item }}"
groups: psql
with_random_choice: "{{ groups['postgres_cluster'] }}"
- name: Cpu load
add_host:
name: "{{ item }}"
groups: cpu
with_random_choice: "{{ groups.all }}"
- name: Ram load
add_host:
name: "{{ item }}"
groups: ram
with_random_choice: "{{ groups.all }}"
- name: IO load
add_host:
name: "{{ item }}"
groups: io
with_random_choice: "{{ groups.all }}"
- name: Checking hosts
hosts: all
gather_facts: false
tasks:
- debug: var=group_names
- name: Make chaos!!!
hosts: all
become: true
gather_facts: false
vars_files: vars.yml
roles:
- { role: network , when: "'network' in group_names and run_network == true" }
- { role: systemd , when: "'etcd' in group_names" , service: etcd}
- { role: systemd , when: "'psql' in group_names", service: patroni }
- { role: os , when: run_os == 'true' }
- name: Waiting "{{ chaos_timeout }}" seconds for system reaction
hosts: localhost
vars_files: vars.yml
gather_facts: false
tasks:
- pause:
seconds: "{{ chaos_timeout }}"
- name: Rollback chaos
become: true
gather_facts: false
hosts: all
vars_files: vars.yml
roles:
- role: rollback
tags: rollback