0

We have a Kubernetes cluster, deployed using Kubespray. It was working fine. We are trying to add one more worker node, and getting below error only on all worker nodes.

ansible-playbook -i hosts.ini test.yaml -b -K -v

test.yaml

---
- hosts: masternode1 workernode1
  gather_facts: true
  tasks:
    - name: Gather host facts to get ansible_os_family
      ansible.builtin.setup:
        gather_subset: '!all'
        filter: ansible_*

    - name: Debug
      debug:
        var: ansible_os_family`

output of above:

PLAY [masternode1 workernode1] **********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [masternode1]
ok: [workernode1]

TASK [Gather host facts to get ansible_os_family] *******************************************************************************************************************************************************************************************
ok: [masternode1]
ok: [workernode1]

TASK [Debug] ********************************************************************************************************************************************************************************************************************************
ok: [masternode1] => {
    "ansible_os_family": "Debian"
}
ok: [workernode1] => {
    "ansible_os_family": "VARIABLE IS NOT DEFINED!: 'ansible_os_family' is undefined"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
masternode1                    : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
workernode1                    : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

debug: ansible_facts, missing below details on workernode

"distribution": "Ubuntu",
"distribution_file_parsed": true,
"distribution_file_path": "/etc/os-release",
"distribution_file_variety": "Debian",
"distribution_major_version": "20",
"distribution_release": "focal",
"distribution_version": "20.04",
"os_family": "Debian",
"pkg_mgr": "apt"

There is an error using -vvv option on workernode

UnboundLocalError("local variable \'datafile\' referenced before assignment")\r\nKeyError(\'ansible_os_family\')

Also tried ansible.builtin.setup, but worker nodes doesn't return os_family or any distribution* variables, while all master nodes are fine; gather_facts doesn't help.

Ansible version 2.12 (also tried version 2.10.6 but same issue) OS Ubuntu 20.04

coder
  • 1
  • 1
  • 3
    What does your playbook looks like? Are there tags involved? Please provide a [mre]. – β.εηοιτ.βε Feb 27 '23 at 10:17
  • While providing a minimal reproducible example, can you included the full output and debug messages of `gather_facts`? – U880D Feb 27 '23 at 10:45
  • Added into the question. – coder Feb 27 '23 at 11:45
  • Why adding an explicit `setup` since you have `gather_facts: true` on you play? You are gathering facts twice (even if the second gathering is a minimal subset). – Zeitounator Feb 27 '23 at 12:46
  • 2
    To go further in debugging, can you check if 1) `ansible_facts.os_family` exists on that host 2) `ansible.distribution` (and/or `ansible_facts.distribution`) exist on that host. Please do not answer in comments: [edit] your question. And as already asked by @U880D, please run the above with `-vvv` to check if there are any meaningfull debug messages while gathering facts. Thanks. – Zeitounator Feb 27 '23 at 13:10
  • Do you mind to provide the output of `debug: var: ansible_facts`? Was there anything gathered? And if gathering facts with verbose `-vvv` what are the messages there? – U880D Feb 27 '23 at 15:02
  • @Zeitounator where can we check ansible_facts* on host ? – coder Feb 27 '23 at 16:57
  • with -vvv generates very large logs (should i put it in question?) , i compared logs of both master and worker node and both seems to be the same. – coder Feb 27 '23 at 17:05
  • `where can I check ansible_facts* on host?` => debug the variable(s) in your playbook. – Zeitounator Feb 27 '23 at 17:08
  • I edited the question with missing variables on worker node with debug: ansible_facts and an error when using -vvv option on worker node. – coder Feb 27 '23 at 17:48
  • Did you declare any [custom facts](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html#adding-custom-facts) on that failing node? If yes, try to remove them and see if it fixes the issue. If it does then check what is wrong in there before putting them back. – Zeitounator Feb 27 '23 at 18:37
  • Does the statement "_`debug: ansible_facts`, missing below details on workernode_", that is the output how it should be, which is expected and is missing from the the workernode, or does it mean it is reported from the workernode? Do you mind to provide the output of `debug: var: ansible_facts`? from the worknode? Even if it doesnt show all output? – U880D Feb 28 '23 at 06:22
  • @Zeitounator We don't have any custom facts. – coder Feb 28 '23 at 08:49
  • @U880D "missing details" means those variables shows in output of masternode but missing in output of workernode. The output of debug: var: is very very large. Should I provide any specific variables or filter the output on anything ? – coder Feb 28 '23 at 08:57
  • For debugging purpose and to be able to narrow down the cause it will helpful if not necessary to provide the full output. You may omit sensitive data. The output and the structure will show what is actually gathered and what is left out, since we know already what you expect to be within. – U880D Feb 28 '23 at 09:07
  • 1
    For reference: https://github.com/ansible/ansible/issues/80105 – β.εηοιτ.βε Mar 02 '23 at 20:10

0 Answers0