ansible-role-tailscale
ansible-role-tailscale copied to clipboard
The conditional check 'tailscale_original_distribution_major_version == \"NA\"' failed
Hi, when running the role using role_include it throws an error:
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'tailscale_original_distribution_major_version == \"NA\"' failed. The error was: error while evaluating conditional (tailscale_original_distribution_major_version == \"NA\"): {{ ansible_distribution_major_version }}: 'ansible_distribution_major_version' is undefined\n\nThe error appears to be in '/home/xxx/.ansible/roles/artis3n.tailscale/tasks/main.yml': line 42, 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: Install lsb_release\n ^ here\n"}
- name: Install Tailscale
include_role:
name: artis3n.tailscale
vars:
tailscale_authkey: "xxxx"
I have tried adding become: true and false wondering if its a user context thing but same error occurs.
Sorry I should add that using roles works fine, its just include_roles
this works:
- hosts: localhost
roles:
- role: artis3n.tailscale
vars:
tailscale_authkey: "xxxx"
I need to use roles_include rather than roles because the roles method doesnt seem to work with an include file and I dont want the tailscale playbook in the main playbook as I want to encrypt it using vault
What operating system distro are you targeting?
Any additional details you can provide would be helpful. The role works with include_role and that is part of the regularly run CI tests, e.g. https://github.com/artis3n/ansible-role-tailscale/blob/3adbf143a8b35b5888de69b4f0d8af6e4f8ac26c/molecule/state-absent/converge.yml#L12-L16
This failure is happening for me when Ansible can't gather facts or can't connect to a host.
I worked around it by tricking Ansible into coercing the value to something that is not undefined but still falsey. I threw the following line into my role's defaults:
# roles/{role_name}/defaults/main.yml
ansible_distribution_major_version: ansible_facts['ansible_distribution_major_version'] || false
I'm confused - if Ansible can't gather facts, then it won't know what distro's install instructions to use. But, particularly, if it can't connect to the host, then it can't do anything.
So far, situations I've encountered where ansible is unable to gather facts is due to missing lsb_release, so we install it here - https://github.com/artis3n/ansible-role-tailscale/blob/main/tasks/main.yml#L38 and then re-run a 'gather facts.'
Can you elaborate on what distro and situation you were in where Ansible failed to gather facts? We may want to improve this section.
I had gather_facts: no set. Once I enabled facts gathering it worked like a charm.