ansible-collections / ansible-consul

:satellite: Ansible role for Hashicorp Consul clusters
https://galaxy.ansible.com/ansible-community/consul/
BSD 2-Clause "Simplified" License
446 stars 310 forks source link

Issues on ipv6-only hosts #447

Open iojcde opened 2 years ago

iojcde commented 2 years ago

I'm having issues setting up consul on ipv6-only hosts.

TASK [ansible-consul : Expose advertise_address(_wan) datacenter and node_role as facts] **********************************************************************************
fatal: [dfw-master-2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {{ consul_bind_address }}: {% if ansible_system == 'FreeBSD' %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_'+ consul_iface ]['ipv4'][0]['address'], true) }}{% elif ansible_os_family == 'Windows'  %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_ip_addresses'][0], true) }}{% else %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_'+ consul_iface | replace('-', '_')]['ipv4']['address'], true) }}{% endif %}: 'dict object' has no attribute 'ipv4'\n\nThe error appears to be in '/home/jcde/teardrop/provisioning/ansible/roles/ansible-consul/tasks/nix.yml': line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Expose advertise_address(_wan) datacenter and node_role as facts\n  ^ here\n"}
fatal: [dfw-master-0]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {{ consul_bind_address }}: {% if ansible_system == 'FreeBSD' %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_'+ consul_iface ]['ipv4'][0]['address'], true) }}{% elif ansible_os_family == 'Windows'  %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_ip_addresses'][0], true) }}{% else %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_'+ consul_iface | replace('-', '_')]['ipv4']['address'], true) }}{% endif %}: 'dict object' has no attribute 'ipv4'\n\nThe error appears to be in '/home/jcde/teardrop/provisioning/ansible/roles/ansible-consul/tasks/nix.yml': line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Expose advertise_address(_wan) datacenter and node_role as facts\n  ^ here\n"}
fatal: [dfw-master-1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {{ consul_bind_address }}: {% if ansible_system == 'FreeBSD' %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_'+ consul_iface ]['ipv4'][0]['address'], true) }}{% elif ansible_os_family == 'Windows'  %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_ip_addresses'][0], true) }}{% else %}{{ lookup('env','CONSUL_BIND_ADDRESS') | default(hostvars[inventory_hostname]['ansible_'+ consul_iface | replace('-', '_')]['ipv4']['address'], true) }}{% endif %}: 'dict object' has no attribute 'ipv4'\n\nThe error appears to be in '/home/jcde/teardrop/provisioning/ansible/roles/ansible-consul/tasks/nix.yml': line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Expose advertise_address(_wan) datacenter and node_role as facts\n  ^ here\n"}```

I've specified consul_iface in the playbook, but it doesn't seem to work for some reason.

---
# File: site.yml - Example nomad site playbook
- name: Assemble Consul cluster
  hosts: masters
  any_errors_fatal: true
  become: true
  become_user: root
  roles:
    - ansible-consul
  vars:
    consul_group_name: masters
    consul_iface: eth0
    consul_node_role: server 
    consul_bootstrap_expect: true

I'm very new to ansible, so it might be something I did wrong.

iojcde commented 2 years ago

If I'm understanding correctly, shouldn't consul_bind_address be configured to the address of the interface in consul_iface by default?

Edit: seems like #40 is kinda related

bpbp-boop commented 1 year ago

Just ran across this, the project hard-codes 'ipv4' in its default for consul_bind_address. You can define your own address instead eg

    consul_bind_address: "{{ ansible_facts['ens18']['ipv6'][0]['address'] }}"