-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
redis
server as a multihost sync example
Co-authored-by: Petr Šplíchal <psplicha@redhat.com>
- Loading branch information
Showing
8 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- hosts: all | ||
vars: | ||
- version: "{{ ansible_distribution_version }}" | ||
tasks: | ||
- import_tasks: tasks/redis.yml | ||
- import_tasks: tasks/redis_variables.yml | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
- name: setup syncing redis server | ||
package: name={{ item }} state=present | ||
with_items: | ||
- redis | ||
- firewalld | ||
become: true | ||
|
||
- name: bind to all interfaces | ||
ansible.builtin.lineinfile: | ||
path: /etc/redis/redis.conf | ||
regexp: '^bind ' | ||
line: "bind 0.0.0.0 -::0" | ||
become: true | ||
|
||
- name: remove protected mode | ||
ansible.builtin.lineinfile: | ||
path: /etc/redis/redis.conf | ||
regexp: '^protected-mode' | ||
line: "protected-mode no" | ||
become: true | ||
|
||
|
||
- name: Start redis service, if not started | ||
ansible.builtin.service: | ||
name: redis | ||
state: restarted | ||
enabled: yes | ||
become: true | ||
|
||
|
||
- name: Start firewalld service, if not started | ||
ansible.builtin.service: | ||
name: firewalld | ||
state: started | ||
enabled: yes | ||
become: true | ||
|
||
- name: add sshd to firewalld | ||
ansible.posix.firewalld: | ||
service: ssh | ||
permanent: yes | ||
state: enabled | ||
immediate: true | ||
become: true | ||
|
||
- name: add redis to firewalld | ||
ansible.posix.firewalld: | ||
service: redis | ||
permanent: yes | ||
state: enabled | ||
immediate: true | ||
become: true | ||
|
||
- name: add redis-sentinel to firewall | ||
ansible.posix.firewalld: | ||
service: redis-sentinel | ||
permanent: yes | ||
state: enabled | ||
immediate: true | ||
become: true | ||
|
||
# redis-cli -h $GUEST set variable value | ||
# redis-cli -h $GUEST get variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- name: Set variables into redis database | ||
ansible.builtin.shell: | | ||
redis-cli set key value1 | ||
args: | ||
executable: /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
description: | | ||
This is an example how to use redis for data synchronization | ||
between guests | ||
|
||
how to send data to server: | ||
redis-cli -h $GUEST set variable value | ||
|
||
how to get data from server: | ||
redis-cli -h $GUEST get variable | ||
|
||
If you need more features like waiting for events or atomic | ||
commands or deleting keys see doc for redis commands | ||
https://redis.io/commands/ | ||
|
||
discover: | ||
- how: fmf | ||
where: | ||
- guest | ||
|
||
provision: | ||
- how: virtual | ||
role: server | ||
image: fedora | ||
connection: system | ||
- how: virtual | ||
role: guest | ||
image: fedora | ||
connection: system | ||
|
||
prepare: | ||
- how: ansible | ||
playbook: | ||
- ansible/setup_server.yml | ||
extra-args: '-vvv' | ||
where: | ||
- server | ||
- how: install | ||
package: redis | ||
where: | ||
- guest | ||
|
||
execute: | ||
how: tmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
summary: This is an example of the redis sync | ||
test: ./test.sh | ||
framework: shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
. "$TMT_TOPOLOGY_BASH" | ||
# verify that TOPLOGY to be defined to be able to run the tests. | ||
test -z "${TMT_ROLES[server]}" && exit 125 | ||
|
||
SERVER=${TMT_GUESTS[${TMT_ROLES[server]}.hostname]} | ||
redis-cli -h $SERVER get key | grep value1 |