digitalocean / navigators-guide

Book and code examples that help to build infrastructure on DigitalOcean
76 stars 9 forks source link

CH04 ansible-haproxy : configure haproxy service fails #47

Closed ful09003 closed 6 years ago

ful09003 commented 6 years ago

Replicated a few times now: TASK [ansible-haproxy : configure haproxy service] ***** fatal: [142.93.83.70]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible_eth0_2' is undefined"} fatal: [142.93.83.63]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible_eth0_2' is undefined"}

PLAY RECAP ***** 142.93.83.63 : ok=35 changed=33 unreachable=0 failed=1 142.93.83.64 : ok=1 changed=0 unreachable=0 failed=0 142.93.83.69 : ok=1 changed=0 unreachable=0 failed=0 142.93.83.70 : ok=35 changed=33 unreachable=0 failed=1 142.93.90.3 : ok=1 changed=0 unreachable=0 failed=0 159.89.220.217 : ok=1 changed=0 unreachable=0 failed=0

Looks like ansible_eth0_2 really isn't defined: ansible -i /usr/local/bin/terraform-inventory all -m setup --tree /tmp/facts > /tmp/ansible-debug grep -C 3 ansible_eth0_2 /tmp/ansible-debug (empty) grep -C 3 ansible_eth0_1 /tmp/ansible-debug (lots of hits for Droplet private IPs)

Steps to replicate:

  1. Proceed through navguide to this part of ch04
  2. Attempt to run the suggested ansible-playbook -i /usr/local/bin/terraform-inventory site.yml
  3. Observe failure
ful09003 commented 6 years ago

Adding another task in roles/ansible-haproxy/tasks/main.yml to register the Droplet's Anchor IP from the DigitalOcean metadata service, and using that in the jinja template will resolve this, and allows us to continue through the chapter.

ful09003 commented 6 years ago

Seeing this in ch05 as well (task for ansible-galera-lb : configure haproxy service for galera)

ful09003 commented 6 years ago

Re-tested with Ansible 2.5.8, and can confirm this behavior still exists:

ansible-playbook --version
ansible-playbook 2.5.8 (stable-2.5 36fd4a2255) last updated 2018/08/29 16:48:46 (GMT +000)
  config file = /root/navigators-guide/example-code/02-scale/ch04/haproxy_loadbalancer/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/ansible/lib/ansible
  executable location = /root/ansible/bin/ansible-playbook
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
TASK [ansible-haproxy : configure haproxy service] *********************************************************************************************************************************************************
fatal: [104.248.64.120]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible_eth0_2' is undefined"}
fatal: [142.93.87.190]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible_eth0_2' is undefined"}

Looking back through facts that Ansible is learning, it appears the anchor IP is exposed as ansible_eth0_1 versus ansible_eth0_2. Instead of needing to add a new task, should just need a template update.

jonschwenn commented 6 years ago

Can you test on an older Droplet if you happen to have one to see if it reports ansible_eth0_2? I'm curious if something changed with the image/deployments on our side.

ful09003 commented 6 years ago

Was able to test on Debian 9.3, still reported as eth0_1. I'll make a PR to just update the jinja template.

cmndrsp0ck commented 6 years ago

adjusted defaults/main.yml and templates/haproxy.cfg.j2 7bf7820

passed test. closing