1

I'm working on Kubespray 2.16

At roles/kubernetes/preinstall/tasks/0070-system-packages.yml, there is a task "Install packages requirements"

- name: Install packages requirements
  package:
    name: "{{ required_pkgs | default([]) | union(common_required_pkgs|default([])) }}"
    state: present
  register: pkgs_task_result
  until: pkgs_task_result is succeeded
  retries: "{{ pkg_install_retries }}"
  delay: "{{ retry_stagger | random + 3 }}"
  when: not (ansible_os_family in ["Flatcar Container Linux by Kinvolk", "ClearLinux"] or is_fedora_coreos)
  tags:
    - bootstrap-os

According to the code, the package {{ required_pkgs | default([]) | union(common_required_pkgs|default([])) }} will be installed.

And I found the required_pkgs in roles/kubernetes/preinstall/vars/*.yml

In redhat.yml,

required_pkgs:
  - "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('libselinux-python','python3-libselinux') }}"
  - device-mapper-libs
  - nss
  - conntrack

In centos.yml,

required_pkgs:
  - "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('libselinux-python','python3-libselinux') }}"
  - device-mapper-libs
  - nss
  - conntrack

I think there is no process for Ansible to check my OS in "this task". Then how the Ansible set required_pkgs among a lot of YML files?

p.s. My OS is RedHat.

U880D
  • 8,601
  • 6
  • 24
  • 40
JAESANGPARK
  • 311
  • 3
  • 13

1 Answers1

3

By default, when Ansible first starts executing a play it will implicitly run the setup module on all the remote hosts involved in the play. This is called the "fact gathering" step, and is controlled by the gather_facts option in the play or the gathering option in ansible.cfg.

The facts gathered in this step include things like operating system flavor, release, information about interfaces and disks, and a variety of other host metadata. The variables are all all in the ansible_* namespace (e.g., ansible_distribution_major_version).

Kubespray is taking advantage of these automatically gathered facts to load the appropriate vars files.

For more information:

Etc.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks for your help. I got to know how the ansible gets the information of remote host. What if I change the name of file "redhat.yaml" to "HI.yaml"? Then the task "Install packages requirements" will fail? – JAESANGPARK Feb 10 '22 at 01:14
  • I would expect it to, yes, but the easiest way to answer that question is to try it and find out! – larsks Feb 10 '22 at 01:19
  • I will try thanks! – JAESANGPARK Feb 10 '22 at 06:17