VictoriaMetrics / ansible-playbooks

Ansible Playbooks for Victoria Metrics monorepo
Apache License 2.0
103 stars 34 forks source link

AnsibleUndefinedVariable: 'dict object' has no attribute 'victoria_cluster' #14

Closed patsevanton closed 2 years ago

patsevanton commented 2 years ago

Hello! I try install and get error

Playbook:

---
- hosts: vmstorage,vminsert,vmselect
  collections:
    - victoriametrics.cluster
  become: true
  roles:
    - geerlingguy.docker
    - victoriametrics.cluster.victoria_cluster

Inventory:

[vmstorage]
vmstorage0 ansible_host=xxx
vmstorage1 ansible_host=xxx
vmstorage2 ansible_host=xxx
vmstorage3 ansible_host=xxx
[vminsert]
vminsert0 ansible_host=xxx
vminsert1 ansible_host=xxx
[vmselect]
vmselect0 ansible_host=xxx
vmselect1 ansible_host=xxx

[vmstorage:vars]
vm_role=victoria-storage

[vminsert:vars]
vm_role=victoria-insert

[vmselect:vars]
vm_role=victoria-select

[all:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=~/.ssh/id_rsa

Error:

TASK [victoriametrics.cluster.victoria_cluster : ensure victoria-storage unit file] ****************************************************************************************************
Wednesday 30 March 2022  14:47:39 +0600 (0:00:09.887)       0:04:26.940 *******
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'victoria_cluster'
fatal: [vminsert0]: FAILED! => changed=false
  msg: 'AnsibleUndefinedVariable: ''dict object'' has no attribute ''victoria_cluster'''
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'victoria_cluster'
fatal: [vminsert1]: FAILED! => changed=false
  msg: 'AnsibleUndefinedVariable: ''dict object'' has no attribute ''victoria_cluster'''
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'victoria_cluster'
fatal: [vmselect0]: FAILED! => changed=false
  msg: 'AnsibleUndefinedVariable: ''dict object'' has no attribute ''victoria_cluster'''
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'victoria_cluster'
fatal: [vmselect1]: FAILED! => changed=false
  msg: 'AnsibleUndefinedVariable: ''dict object'' has no attribute ''victoria_cluster'''
zekker6 commented 2 years ago

Unfortunately, I can't reproduce this issue locally. Could you try to run playbook in more verbose mode and share output?

patsevanton commented 2 years ago

Run ansible-playbook -vvvv -i host.ini playbook.yml

The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 1139, in do_template
    res = j2_concat(rf)
  File "<template>", line 54, in root
  File "/usr/local/lib/python3.8/dist-packages/jinja2/runtime.py", line 747, in _fail_with_undefined_error
    raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'victoria_cluster'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ansible/plugins/action/template.py", line 150, in run
    resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
  File "/usr/lib/python3/dist-packages/ansible/template/__init__.py", line 1176, in do_template
    raise AnsibleUndefinedVariable(e)
ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'victoria_cluster'
fatal: [vminsert0]: FAILED! => changed=false
  msg: 'AnsibleUndefinedVariable: ''dict object'' has no attribute ''victoria_cluster'''
zekker6 commented 2 years ago

Please add the following:

vmstorage_group=vmstorage

To your anisble vars. It is required to set vmstorage_group to name of the vmstorage nodes group in order to configure vmselect and vminsert connectoins to storage pool.

You can do this by either adding it into inventory:

[all:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=~/.ssh/id_rsa
vmstorage_group=vmstorage

Or adding into playbook directly:

- hosts: vmstorage,vminsert,vmselect
  collections:
    - victoriametrics.cluster
  become: true
  vars:
    vmstorage_group: vmstorage
  roles:
    - geerlingguy.docker
    - victoriametrics.cluster.victoria_cluster
patsevanton commented 2 years ago

vmstorage_group=vmstorage fixed issue. May be add vmstorage_group=vmstorage to default variable ?

zekker6 commented 2 years ago

I'm working on updating readme files for roles right now, will place a note about that for sure

patsevanton commented 2 years ago

vmstorage_group in https://github.com/VictoriaMetrics/ansible-playbooks/blob/master/inventory_example/group_vars/victoria_cluster.yml#L3 and in https://github.com/VictoriaMetrics/ansible-playbooks/blob/master/roles/cluster/defaults/main.yml#L27 is different

what is value correct?

patsevanton commented 2 years ago

Without variable vmstorage_group get error AnsibleUndefinedVariable: 'dict object' has no attribute 'cluster'.

With variable vmstorage_group.

May be change vmstorage_group in default.yml ?

zekker6 commented 2 years ago

Value for this variable depends on inventory format. Variable value should contain inventory group name for vmstorage hosts.

For inventory you've provided it should be vmstorage

patsevanton commented 2 years ago

Ok. May be add description about variable vmstorage to readme?

zekker6 commented 2 years ago

Yep, already put it into role readme here - https://github.com/VictoriaMetrics/ansible-playbooks/tree/master/roles/cluster#parameters

patsevanton commented 2 years ago

Great!