mrlesmithjr / ansible-mariadb-galera-cluster

MIT License
135 stars 114 forks source link

[Help] ansible.vars.hostvars.HostVarsVars object has no attribute 'ansible_eth' #132

Closed perpi closed 2 years ago

perpi commented 2 years ago

Deployment dropped by this error:

fatal: [controller01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was:
{{ galera_cluster_bind_address }}: {{ hostvars[inventory_hostname]['ansible_' + galera_cluster_bind_interface]['ipv4']['address'] }}: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_eth-conf'
\n\nThe error appears to be in '/home/prd/roles/ansible-mariadb-galera-cluster/tasks/setup_cluster.yml': line 45, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.
\n\nThe offending line appears to be:\n\n  block:\n    - name: WSREP ist.recv_\n      ^ here\n"}

and I can't find which variable is still unconfigured. May you help me?

To Reproduce Steps to reproduce the behavior:

  1. Deploy the playbook.yml

*Server:**

eRadical commented 2 years ago

Hi @perpi,

Does it get over this line?

- name: ensure NIC specified in 'galera_cluster_bind_interface' exists

If you dump hostvars[inventory_hostname] do you see info for ansible_eth-conf?

eRadical commented 2 years ago

Duplicate #133

stefangweichinger commented 2 years ago

Let me pick this one up again, because I could need a working example.

I have this in my inventory "staging":

[galera_cluster_nodes]
mariadb-main-1-1    ansible_host=172.32.99.111 ansible_user=vagrant
mariadb-main-1-2    ansible_host=172.32.99.112 ansible_user=vagrant
mariadb-main-1-3    ansible_host=172.32.99.113 ansible_user=vagrant

[galera_cluster_nodes:vars]
galera_cluster_bind_interface=enp0s3
galera_cluster_nodes_group='galera_cluster_nodes'

I run "ansible-playbook playbook.yml -i staging -b -v" and get:

TASK [eradical.ansible_mariadb_galera_cluster : setup_cluster | configuring settings for mariadb and galera] ***************************************************************************************************************************
[..]
failed: [mariadb-main-1-3] (item=etc/mysql/conf.d/galera.cnf) => {"ansible_loop_var": "item", "changed": false, "item": "etc/mysql/conf.d/galera.cnf", "msg": "AnsibleFilterError: Mandatory variable 'ansible_enp0s3'  not defined."}

I think this is caused in this line: https://github.com/mrlesmithjr/ansible-mariadb-galera-cluster/blob/d25a718e3d126980b5f5962d9a055853ef1e1fe4/templates/etc/mysql/conf.d/galera.cnf.j2#L53

Maybe I define my vars in a wrong way. Interesting: I was able to deploy the test machines yesterday, now at my "do it again from scratch" run it fails.

stefangweichinger commented 2 years ago

This works as a test, I will try to add that to the template:

---
- hosts: all

  vars:
    - galera_cluster_bind_interface: enp0s3

  tasks:

    - name: syntax with loop
      debug:
        msg: "{{ hostvars[inventory_hostname]['ansible_%s' | format(item) ]['ipv4']['address'] }}"
      with_items: "{{ galera_cluster_bind_interface }}"

    - name: syntax without loop
      debug:
        msg: "{{ hostvars[inventory_hostname]['ansible_%s' | format(galera_cluster_bind_interface) ]['ipv4']['address'] }}"
stefangweichinger commented 2 years ago

This patch seems to work for me, but I am not sure if it is correct:

diff --git a/templates/etc/mysql/conf.d/galera.cnf.j2 b/templates/etc/mysql/conf.d/galera.cnf.j2
index abe4d9d..b231c75 100644
--- a/templates/etc/mysql/conf.d/galera.cnf.j2
+++ b/templates/etc/mysql/conf.d/galera.cnf.j2
@@ -50,7 +50,7 @@ wsrep_provider={{ galera_wsrep_provider }}
 wsrep_cluster_name="{{ galera_cluster_name }}"
 {% set _galera_cluster_node_addresses = [] %}
 {% for node in galera_cluster_nodes %}
-{%   set _ = _galera_cluster_node_addresses.append( hostvars[node]['galera_cluster_bind_address'] | default(hostvars[node]['ansible_' ~ galera_cluster_bind_interface]['ipv4']['address']) | mandatory ) %}
+{%   set _ = _galera_cluster_node_addresses.append( hostvars[node]['galera_cluster_bind_address'] | default(hostvars[inventory_hostname]['ansible_%s' | format(galera_cluster_bind_interface) ]['ipv4']['address']) | mandatory ) %}
 {% endfor %}
 wsrep_cluster_address="{{ 'gcomm://' ~ _galera_cluster_node_addresses | map('ipwrap') | list | join(',') }}"
 # To start failed cluster comment out above and uncomment below...Once cluster is started revert changes and restart mysql on main node where change was made

EDIT: This patch is WRONG ... it results in adding the same IP three times to that "gcomm://" address. Sorry for the noise.

eRadical commented 2 years ago

Changes should be done to the variables defined in: defaults/main.yml:

galera_cluster_bind_interface: "eth0"

This needs to be changed to the actual interface present in your machine.

galera_cluster_nodes_group: "galera-cluster-nodes"

Here you need to put the name of the group from the inventory.

galera_cluster_name: "vagrant-test"

I would also set the above to something specific so 2 or more clusters in the same network won't clash.

stefangweichinger commented 2 years ago

thanks @eRadical

editing defaults/main.yml and removing the var galera_cluster_bind_interface from my inventory also triggers that error:

# grep galera_cluster_bind_interface  defaults/main.yml 
galera_cluster_bind_interface: "enp0s3"

# running the playbook ->

"msg": "The NIC name \"eth0\" specified in \"galera_cluster_bind_interface\" does not exist on the target host. Available interfaces are: \"lo,enp0s3\"."

So somehow it isn't get read. I have no problem defining it in my inventory, just pointing it out.

EDIT: forgive me, I missed the fact that the role was read from ~/.ansible/roles while I edited ./defaults/main.yml in my gh checkout dir.

eRadical commented 2 years ago

Can you add more details:

stefangweichinger commented 2 years ago

Did you notice my EDIT: above?

Sure. Ansible-Controller: Fedora 36 workstation

ansible --version
ansible [core 2.13.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/sgw/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/sgw/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/sgw/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)]
  jinja version = 3.0.3
  libyaml = True

Unsure if you want to know all my collections?

ansible-galaxy collection list

# /home/sgw/.ansible/collections/ansible_collections
Collection           Version
-------------------- -------
ansible.posix        1.4.0  
community.crypto     2.5.0  
community.general    5.6.0  
community.libvirt    1.2.0  
community.mysql      3.5.1  
community.postgresql 2.2.0  
community.rabbitmq   1.2.2  
debops.debops        3.0.3  
debops.roles01       3.0.3  
debops.roles02       3.0.3  
debops.roles03       3.0.3  

# /home/sgw/.local/lib/python3.10/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    3.4.0  
ansible.netcommon             3.1.1  
ansible.posix                 1.4.0  
ansible.utils                 2.6.1  
ansible.windows               1.11.1 
arista.eos                    5.0.1  
awx.awx                       21.5.0 
azure.azcollection            1.13.0 
check_point.mgmt              2.3.0  
chocolatey.chocolatey         1.3.0  
cisco.aci                     2.2.0  
cisco.asa                     3.1.0  
cisco.dnac                    6.6.0  
cisco.intersight              1.0.19 
cisco.ios                     3.3.1  
cisco.iosxr                   3.3.1  
cisco.ise                     2.5.3  
cisco.meraki                  2.11.0 
cisco.mso                     2.0.0  
cisco.nso                     1.0.3  
cisco.nxos                    3.1.1  
cisco.ucs                     1.8.0  
cloud.common                  2.1.2  
cloudscale_ch.cloud           2.2.2  
community.aws                 3.5.0  
community.azure               1.1.0  
community.ciscosmb            1.0.5  
community.crypto              2.5.0  
community.digitalocean        1.21.0 
community.dns                 2.3.2  
community.docker              2.7.1  
community.fortios             1.0.0  
community.general             5.6.0  
community.google              1.0.0  
community.grafana             1.5.2  
community.hashi_vault         3.2.0  
community.hrobot              1.5.2  
community.libvirt             1.2.0  
community.mongodb             1.4.2  
community.mysql               3.5.1  
community.network             4.0.1  
community.okd                 2.2.0  
community.postgresql          2.2.0  
community.proxysql            1.4.0  
community.rabbitmq            1.2.2  
community.routeros            2.3.0  
community.sap                 1.0.0  
community.sap_libs            1.3.0  
community.skydive             1.0.0  
community.sops                1.4.0  
community.vmware              2.9.1  
community.windows             1.11.0 
community.zabbix              1.8.0  
containers.podman             1.9.4  
cyberark.conjur               1.2.0  
cyberark.pas                  1.0.14 
dellemc.enterprise_sonic      1.1.2  
dellemc.openmanage            5.5.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.19.0 
fortinet.fortimanager         2.1.5  
fortinet.fortios              2.1.7  
frr.frr                       2.0.0  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.8.2  
hpe.nimble                    1.1.4  
ibm.qradar                    2.1.0  
ibm.spectrum_virtualize       1.9.0  
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.3.0  
inspur.ispim                  1.0.1  
inspur.sm                     2.0.0  
junipernetworks.junos         3.1.0  
kubernetes.core               2.3.2  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.19.0
netapp.elementsw              21.7.0 
netapp.ontap                  21.23.0
netapp.storagegrid            21.11.0
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.3.1  
netbox.netbox                 3.7.1  
ngine_io.cloudstack           2.2.4  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.2  
openstack.cloud               1.9.1  
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   2.2.3  
purestorage.flasharray        1.13.0 
purestorage.flashblade        1.10.0 
purestorage.fusion            1.1.0  
sensu.sensu_go                1.13.1 
servicenow.servicenow         1.0.6  
splunk.es                     2.1.0  
t_systems_mms.icinga_director 1.31.0 
theforeman.foreman            3.6.0  
vmware.vmware_rest            2.2.0  
vultr.cloud                   1.1.0  
vyos.vyos                     3.0.1  
wti.remote                    1.0.4
eRadical commented 2 years ago

noe, didn't noticed the EDIT :)

stefangweichinger commented 2 years ago

noe, didn't noticed the EDIT :)

Great, thanks ;-) solved for now, I might come back with another issue later ... so far thanks for the role