sky-uk / clusterverse

Full-lifecycle cloud infrastructure cluster management, using Ansible
BSD 3-Clause "New" or "Revised" License
15 stars 8 forks source link

[BUG] unsupported operand type(s) for +: 'NoneType' and 'str' in _dependencies/tasks/main.yml: 33 #117

Closed emmett08 closed 2 years ago

emmett08 commented 2 years ago

TASK [clusterverse/dynamic_inventory : dynamic_inventory | Add hosts to dynamic inventory (add only powered-on hosts)] *** task path: ~/Desktop/jenkins-ansible/roles/clusterverse/dynamic_inventory/tasks/main.yml:20 Wednesday 27 April 2022 14:18:27 +0100 (0:00:05.843) 0:01:11.295 * fatal: [localhost]: FAILED! => { "msg": "An unhandled exception occurred while templating '{{ query('dig', _bastion_host, errors='ignore') | map('ipaddr', _local_cidr) | select() | list | length > 0 }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Unexpected templating type error occurred on ({{ query('dig', _bastion_host, errors='ignore') | map('ipaddr', _local_cidr) | select() | list | length > 0 }}): unsupported operand type(s) for +: 'NoneType' and 'str'" }

When no bastion host query('dig', _bastion_host, errors='ignore') is None type.

dseeley commented 2 years ago

Hm, I use it mostly without a bastion host... I can't reproduce... Are you running on macos or linux (some mac libs differ, although I don't recall these doing so)?

emmett08 commented 2 years ago

Hi @dseeley - I'm running on a MacOS in a virtual environment. The thing is it worked once on Tuesday so I suspect it is a local environment issue. Thought I had resolved it by reinstalling ansible using brew but that didn't work. Clearing down the artefacts in AWS did nothing either. Changing ansible executable location, python version and ansible version did nothing so I thought that changing the vars query would bypass these environmental discrepancies.

ansible [core 2.12.5] config file = ~/Desktop/jenkins-ansible/ansible.cfg configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = ~/Library/Caches/pypoetry/virtualenvs/jenkins-infra-Re02nw8l-py3.10/lib/python3.10/site-packages/ansible ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections executable location = ~/Library/Caches/pypoetry/virtualenvs/jenkins-infra-Re02nw8l-py3.10/bin/ansible python version = 3.10.2 (main, Feb 2 2022, 08:42:42) [Clang 13.0.0 (clang-1300.0.29.3)] jinja version = 3.1.1 libyaml = False

waqarsky commented 2 years ago

This is due to a bug in ansibles ansible_default_ipv4.netmask builtin. When on VPN it returns the IP address as the netmask.

ok: [localhost] => {“ansible_facts”: {“_local_cidra”: {“address”: “10.109.188.206", “broadcast”: “0xffffe000", “device”: “utun3", “flags”: [“UP”, “POINTOPOINT”, “RUNNING”, “NOARP”, “MULTICAST”], “interface”: “utun3", “macaddress”: “unknown”, “mtu”: “1390", “netmask”: “10.109.188.206", “network”: “10.109.188.206", “options”: [“PERFORMNUD”, “DAD”], “type”: “unknown”}}, “changed”: false}

Which is used in https://github.com/sky-uk/clusterverse/blob/master/dynamic_inventory/tasks/main.yml#L20 on line 32.

_local_cidr: "{{ (ansible_default_ipv4.network+'/'+ansible_default_ipv4.netmask) | ipaddr('network/prefix') }}"

As a workaround to just get it to deploy, you can hardcode the IP address of your local machine

_local_cidr: "10.109.188.206/19"

JamalSky commented 2 years ago

https://github.com/ansible/ansible/pull/79121 PR raised for fix for this issue.

JamalSky commented 2 years ago

This has now been resolved 🙌🏽