File tree Expand file tree Collapse file tree 12 files changed +321
-10
lines changed Expand file tree Collapse file tree 12 files changed +321
-10
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
19
19
20
20
| Name | Default Value | Description |
21
21
| -------------- | ------------- | -----------------------------------|
22
+ | ` cortex_all_in_one ` | true | Setup Cortex in all-in-one binary mode. |
23
+ | ` cortex_services ` | ` {} ` | Cortex services configurations. |
22
24
| ` cortex_web_listen_address ` | "0.0.0.0:9009" | Address on which cortex will listen |
23
25
| ` cortex_binary_local_dir ` | "" | Allows to use local packages instead of ones distributed on github. As parameter it takes a directory where ` cortex ` binaries are stored on host on which ansible is ran. This overrides ` cortex_version ` parameter |
24
26
| ` cortex_interface ` | "{{ ansible_default_ipv4.interface }}" | Network adapter that cortex will be using |
@@ -66,6 +68,34 @@ Use it in a playbook as follows:
66
68
roles :
67
69
- cloudalchemy.cortex
68
70
` ` `
71
+
72
+ ### Services mode
73
+
74
+ You can run the different Cortex modules as separate services by setting
75
+ ` cortex_services` as a module:config map and `cortex_all_in_one` to `false`.
76
+ ` ` ` yaml
77
+ - hosts: all
78
+ roles:
79
+ - cloudalchemy.cortex
80
+ vars:
81
+ cortex_all_in_one: false
82
+ cortex_services:
83
+ ingester:
84
+ server:
85
+ http_listen_port: 9009
86
+ ingester:
87
+ lifecycler:
88
+ join_after: 0
89
+ min_ready_duration: 0s
90
+ final_sleep: 0s
91
+ num_tokens: 512
92
+
93
+ ring:
94
+ kvstore:
95
+ store: inmemory
96
+ replication_factor: 1
97
+ ` ` `
98
+
69
99
# # Local Testing
70
100
71
101
The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/metacloud/molecule) (v2.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable to for your system.
Original file line number Diff line number Diff line change 1
1
---
2
+ cortex_version : 1.4.0
3
+ cortex_all_in_one : true
4
+
2
5
cortex_web_listen_address : " 0.0.0.0:9009"
3
6
cortex_binary_local_dir : ' '
4
7
cortex_skip_install : false
5
8
9
+ cortex_services : {}
10
+
6
11
cortex_interface : " {{ ansible_default_ipv4.interface }}"
7
12
8
13
cortex_config_file : ' cortex.yml.j2'
@@ -12,8 +17,6 @@ cortex_db_dir: /var/lib/cortex
12
17
cortex_system_user : " cortex"
13
18
cortex_system_group : " cortex"
14
19
15
- cortex_version : 1.4.0
16
-
17
20
cortex_auth_enabled : false
18
21
19
22
cortex_server :
Original file line number Diff line number Diff line change 1
1
---
2
- - name : restart cortex
2
+ - name : restart cortex all-in-one
3
3
become : true
4
4
systemd :
5
5
daemon_reload : true
6
6
name : cortex
7
7
state : restarted
8
- - name : reload cortex
8
+ listen : restart cortex
9
+ when : cortex_all_in_one
10
+ - name : restart cortex all-in-one
11
+ become : true
12
+ systemd :
13
+ daemon_reload : true
14
+ name : cortex@{{ item.key }}
15
+ state : restarted
16
+ listen : restart cortex
17
+ loop : " {{ cortex_services | dict2items }}"
18
+ - name : restart cortex all-in-one
19
+ set_fact :
20
+ _cortex_service_status : started
21
+ listen : restart cortex
22
+ - name : reload cortex all-in-one
9
23
become : true
10
24
systemd :
11
25
name : cortex
12
- state : reloaded
26
+ state : " {{ _cortex_service_status | default('reloaded') }}"
27
+ listen : reload cortex
28
+ when : cortex_all_in_one
29
+ - name : reload cortex services
30
+ become : true
31
+ systemd :
32
+ name : cortex@{{ item.key }}
33
+ state : " {{ _cortex_service_status | default('reloaded') }}"
34
+ listen : reload cortex
35
+ loop : " {{ cortex_services | dict2items }}"
Original file line number Diff line number Diff line change 1
- import pytest
2
1
import os
3
2
import testinfra .utils .ansible_runner
4
3
Original file line number Diff line number Diff line change
1
+ ---
2
+ dependency :
3
+ name : galaxy
4
+ driver :
5
+ name : docker
6
+ lint :
7
+ name : yamllint
8
+ platforms :
9
+ - name : bionic
10
+ image : quay.io/paulfantom/molecule-systemd:ubuntu-18.04
11
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
12
+ privileged : true
13
+ volumes :
14
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
15
+ - name : xenial
16
+ image : quay.io/paulfantom/molecule-systemd:ubuntu-16.04
17
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
18
+ privileged : true
19
+ volumes :
20
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
21
+ - name : stretch
22
+ image : quay.io/paulfantom/molecule-systemd:debian-9
23
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
24
+ privileged : true
25
+ volumes :
26
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
27
+ - name : buster
28
+ image : quay.io/paulfantom/molecule-systemd:debian-10
29
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
30
+ privileged : true
31
+ volumes :
32
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
33
+ - name : centos7
34
+ image : quay.io/paulfantom/molecule-systemd:centos-7
35
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
36
+ privileged : true
37
+ volumes :
38
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
39
+ - name : centos8
40
+ image : quay.io/paulfantom/molecule-systemd:centos-8
41
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
42
+ privileged : true
43
+ volumes :
44
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
45
+ groups :
46
+ - python3
47
+ - name : fedora
48
+ image : quay.io/paulfantom/molecule-systemd:fedora-30
49
+ docker_host : " ${DOCKER_HOST:-unix://var/run/docker.sock}"
50
+ privileged : true
51
+ volumes :
52
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
53
+ groups :
54
+ - python3
55
+ provisioner :
56
+ name : ansible
57
+ lint :
58
+ name : ansible-lint
59
+ playbooks :
60
+ create : ../default/create.yml
61
+ prepare : prepare.yml
62
+ converge : playbook.yml
63
+ destroy : ../default/destroy.yml
64
+ inventory :
65
+ group_vars :
66
+ python3 :
67
+ ansible_python_interpreter : /usr/bin/python3
68
+ scenario :
69
+ name : services
70
+ verifier :
71
+ name : testinfra
72
+ lint :
73
+ name : flake8
74
+ enabled : true
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Run role
3
+ hosts : all
4
+ any_errors_fatal : true
5
+ roles :
6
+ - ansible-cortex
7
+ vars :
8
+ cortex_config_dir : /cortex
9
+ cortex_db_dir : /cortexdb
10
+ cortex_system_user : " vortex"
11
+ cortex_system_group : " vortex"
12
+ cortex_all_in_one : false
13
+ cortex_services :
14
+ ingester :
15
+ server :
16
+ http_listen_port : 9009
17
+ ingester :
18
+ lifecycler :
19
+ join_after : 0
20
+ min_ready_duration : 0s
21
+ final_sleep : 0s
22
+ num_tokens : 512
23
+
24
+ ring :
25
+ kvstore :
26
+ store : inmemory
27
+ replication_factor : 1
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Prepare
3
+ hosts : all
4
+ gather_facts : false
5
+ tasks : []
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ import os
3
+ import yaml
4
+ import testinfra .utils .ansible_runner
5
+
6
+
7
+ testinfra_hosts = testinfra .utils .ansible_runner .AnsibleRunner (
8
+ os .environ ['MOLECULE_INVENTORY_FILE' ]).get_hosts ('all' )
9
+
10
+
11
+ @pytest .fixture ()
12
+ def AnsibleDefaults ():
13
+ with open ("../../defaults/main.yml" , 'r' ) as stream :
14
+ return yaml .load (stream )
15
+
16
+
17
+ @pytest .mark .parametrize ("dirs" , [
18
+ "/cortex" ,
19
+ "/cortex/rules" ,
20
+ "/cortexdb"
21
+ ])
22
+ def test_directories (host , dirs ):
23
+ d = host .file (dirs )
24
+ assert d .is_directory
25
+ assert d .exists
26
+
27
+
28
+ @pytest .mark .parametrize ("files" , [
29
+ "/cortex/cortex-ingester.yml" ,
30
+ "/etc/systemd/system/[email protected] " ,
31
+ "/usr/local/bin/cortex-linux-amd64" ,
32
+ ])
33
+ def test_files (host , files ):
34
+ f = host .file (files )
35
+ assert f .exists
36
+ assert f .is_file
37
+
38
+
39
+ def test_user (host ):
40
+ assert host .group ("vortex" ).exists
41
+ assert host .user ("vortex" ).exists
42
+
43
+
44
+ def test_service (host ):
45
+ s = host .service ("cortex@ingester" )
46
+ # assert s.is_enabled
47
+ assert s .is_running
48
+
49
+
50
+ def test_socket (host ):
51
+ s = host .socket ("tcp://0.0.0.0:9009" )
52
+ assert s .is_listening
Original file line number Diff line number Diff line change 1
1
---
2
2
- name : Copy the cortex systemd service file
3
3
template :
4
- src : cortex .service.j2
5
- dest : /etc/systemd/system/cortex .service
4
+ src : " {{ item }} .service.j2"
5
+ dest : /etc/systemd/system/{{ item }} .service
6
6
owner : root
7
7
group : root
8
8
mode : 0644
9
9
notify : restart cortex
10
+ loop : [cortex, cortex@]
10
11
11
12
- name : configure cortex
12
13
template :
18
19
mode : 0640
19
20
notify :
20
21
- reload cortex
22
+ when : cortex_all_in_one
23
+
24
+ - name : configure cortex targets
25
+ copy :
26
+ content : " {{ item.value | to_nice_yaml(indent=2) }}"
27
+ dest : " {{ cortex_config_dir }}/cortex-{{ item.key }}.yml"
28
+ force : true
29
+ owner : root
30
+ group : " {{ cortex_system_user }}"
31
+ mode : 0640
32
+ notify :
33
+ - reload cortex
34
+ loop : " {{ cortex_services | dict2items }}"
Original file line number Diff line number Diff line change 26
26
tags :
27
27
- cortex_configure
28
28
29
- - name : Ensure cortex is enabled on boot
29
+ - name : Ensure cortex all-in-one is enabled on boot
30
30
become : true
31
31
systemd :
32
32
daemon_reload : true
33
33
name : cortex
34
34
enabled : true
35
35
tags :
36
36
- cortex_run
37
+ when : cortex_all_in_one
37
38
38
- - name : ensure cortex service is started and enabled
39
+ - name : ensure cortex all-in-one service is started and enabled
39
40
become : true
40
41
systemd :
41
42
daemon_reload : true
42
43
name : cortex
44
+ state : " {% if cortex_all_in_one %}started{% else %}stopped{%endif%}"
45
+ enabled : " {{ cortex_all_in_one }}"
46
+ tags :
47
+ - cortex_run
48
+
49
+ - name : Ensure cortex services are disabled on boot
50
+ become : true
51
+ systemd :
52
+ daemon_reload : true
53
+ name : cortex@{{ item }}
54
+ enabled : false
55
+ tags :
56
+ - cortex_run
57
+ when : " item not in cortex_services"
58
+ loop : " {{ existing_cortex_units }}"
59
+
60
+ - name : Ensure cortex services are stopped
61
+ become : true
62
+ systemd :
63
+ daemon_reload : true
64
+ name : cortex@{{ item }}
65
+ state : " stopped"
66
+ enabled : false
67
+ tags :
68
+ - cortex_run
69
+ when : " item not in cortex_services"
70
+ loop : " {{ existing_cortex_units }}"
71
+
72
+ - name : Ensure cortex services are enabled on boot
73
+ become : true
74
+ systemd :
75
+ daemon_reload : true
76
+ name : cortex@{{ item.key }}
77
+ enabled : true
78
+ tags :
79
+ - cortex_run
80
+ loop : " {{ cortex_services | dict2items }}"
81
+
82
+ - name : ensure cortex services are started and enabled
83
+ become : true
84
+ systemd :
85
+ daemon_reload : true
86
+ name : cortex@{{ item.key }}
43
87
state : started
44
88
enabled : true
45
89
tags :
46
90
- cortex_run
91
+ loop : " {{ cortex_services | dict2items }}"
You can’t perform that action at this time.
0 commit comments