commit 65534b2c476c4fe1711d2ce29887f7173a404310 Author: ace Date: Wed May 8 19:27:42 2024 +0300 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a9ecc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.galaxy_install_info +roles diff --git a/README.md b/README.md new file mode 100644 index 0000000..7b5407a --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# Setup VictoriaMetrics 1.101.1 cluster + +## Install ansible and requirements in virtualenv + + mkvirtualenv ansible-9.5.1 + pip install -r requirements.txt + deactivate + workon ansible-9.5.1 + +## Install roles + + ansible-playbook ansible-roles.yaml + +## Install Patroni + + ansible-playbook -i inventory/hosts victoriametrics.yaml -u almalinux + + +## Example hosts file: + + [victoriametrics:children] + vmstorage + vminsert + vmselect + vmauth + vmagent + + [vmstorage] + vm-1 + vm-2 + vm-3 + + [vminsert] + vm-1 + vm-2 + vm-3 + + [vmselect] + vm-1 + vm-2 + vm-3 + + [vmauth] + vm-1 + vm-2 + vm-3 + + [vmagent] + vm-1 + vm-2 + vm-3 + +Example group_vars: + + victoriametrics_vmauth_reloadAuthKey: reload-auth-key + victoriametrics_vmauth_users: + - id: "1" + username: "foobar" + password: "foobar" + + victoriametrics_vmagent_prometheus_config: + global: + scrape_interval: '1m' + scrape_timeout: '1m' + scrape_configs: + - job_name: 'rgw' + stream_parse: true + static_configs: + - targets: ['127.0.0.1:9242'] + diff --git a/ansible-roles.yaml b/ansible-roles.yaml new file mode 100644 index 0000000..cdabefb --- /dev/null +++ b/ansible-roles.yaml @@ -0,0 +1,6 @@ +- hosts: localhost + gather_facts: false + tasks: + - name: Install roles + local_action: ansible.builtin.command ansible-galaxy install -r requirements.yaml -p roles + diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..2411b14 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,13 @@ +[defaults] +timeout = 300 +jinja2_native = True +host_key_checking = False +pipelining = True +callbacks_enabled = timer, profile_tasks +forks = 50 +roles_path = roles +interpreter_python = auto_silent + +[ssh_connection] +pipelining = True +ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null diff --git a/inventory/group_vars/all.yaml b/inventory/group_vars/all.yaml new file mode 100644 index 0000000..bb7354a --- /dev/null +++ b/inventory/group_vars/all.yaml @@ -0,0 +1,4 @@ +victoriametrics_vmauth_users: + - id: "1" + username: "foobar" + password: "foobar" diff --git a/inventory/hosts b/inventory/hosts new file mode 100644 index 0000000..7a596ff --- /dev/null +++ b/inventory/hosts @@ -0,0 +1,36 @@ +[all] +vm-1 ansible_host=192.168.79.84 +vm-2 ansible_host=192.168.79.69 +vm-3 ansible_host=192.168.79.80 + +[victoriametrics:children] +vmstorage +vminsert +vmselect +vmauth +vmagent + +[vmstorage] +vm-1 +vm-2 +vm-3 + +[vminsert] +vm-1 +vm-2 +vm-3 + +[vmselect] +vm-1 +vm-2 +vm-3 + +[vmauth] +vm-1 +vm-2 +vm-3 + +[vmagent] +vm-1 +vm-2 +vm-3 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..510016c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +ansible==9.5.1 +ansible-core==2.16.6 +cffi==1.16.0 +cryptography==42.0.7 +Jinja2==3.1.4 +MarkupSafe==2.1.5 +packaging==24.0 +pycparser==2.22 +PyYAML==6.0.1 +resolvelib==1.0.1 diff --git a/requirements.yaml b/requirements.yaml new file mode 100644 index 0000000..ef06600 --- /dev/null +++ b/requirements.yaml @@ -0,0 +1,7 @@ +--- +- src: https://gitea.geekhome.org/ansible-galaxy/hosts.git + scm: git + name: hosts +- src: https://gitea.geekhome.org/ansible-galaxy/victoriametrics.git + scm: git + name: victoriametrics diff --git a/vars/victoriametrics.yaml b/vars/victoriametrics.yaml new file mode 100644 index 0000000..e69de29 diff --git a/victoriametrics.yaml b/victoriametrics.yaml new file mode 100644 index 0000000..9e2d6b8 --- /dev/null +++ b/victoriametrics.yaml @@ -0,0 +1,42 @@ +- hosts: localhost + gather_facts: false + tasks: + - name: Print Ansible version + debug: + msg: "{{ ansible_version }}" + +- hosts: victoriametrics + gather_facts: false + tasks: + - name: Wait 300 seconds + ansible.builtin.wait_for_connection: + timeout: 300 + +- hosts: victoriametrics + tasks: + - name: Include Patroni vars + ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml" + - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml" + - "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - victoriametrics.yaml + paths: + - "vars" + +- hosts: victoriametrics + gather_facts: true + become: true + tasks: + - name: Set hostname + ansible.builtin.hostname: + name: "{{ inventory_hostname }}" + - import_role: + name: hosts + - import_role: + name: victoriametrics