Playbook #2

/root/kubeinit/ci/builds/6mbKNrxD/0/kubeinit/kubeinit/kubeinit-aux/kubeinit/playbook.yml

Report Status CLI Date Duration Controller User Versions Hosts Plays Tasks Results Files Records
29 Oct 2023 16:40:05 +0000 00:02:38.14 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 2 6 348 347 23 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_libvirt/tasks/gather_host_facts.yml

---
# Copyright kubeinit contributors
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Delegate to _param_gather_host
  block:

    - name: Confirm that we have ansible host connectivity
      ansible.builtin.ping:

    - name: Gather network facts
      ansible.builtin.gather_facts:
        gather_subset: "!all,network"
      register: _result_facts

    - name: Set distribution_family for CentOS
      ansible.builtin.set_fact:
        distribution_family: "CentOS"
        libvirt_qemu_user: "qemu"
        host_os: "centos"
        package_manager: auto
      when: _result_facts.ansible_facts.ansible_distribution == 'CentOS'

    - name: Set distribution_family for RedHat
      ansible.builtin.set_fact:
        distribution_family: "CentOS"
        libvirt_qemu_user: "qemu"
        host_os: "redhat"
        package_manager: auto
      when: _result_facts.ansible_facts.ansible_distribution == 'RedHat'

    - name: Set distribution_family for Fedora
      ansible.builtin.set_fact:
        distribution_family: "Fedora"
        libvirt_qemu_user: "qemu"
        host_os: "fedora"
        package_manager: auto
      when: _result_facts.ansible_facts.ansible_distribution == 'Fedora'

    - name: Set distribution_family for Debian
      ansible.builtin.set_fact:
        distribution_family: "Debian"
        libvirt_qemu_user: "libvirt-qemu"
        host_os: "debian"
        package_manager: apt
      when: _result_facts.ansible_facts.ansible_distribution == 'Debian'

    - name: Set distribution_family for Ubuntu
      ansible.builtin.set_fact:
        distribution_family: "Debian"
        libvirt_qemu_user: "libvirt-qemu"
        host_os: "ubuntu"
        package_manager: apt
      when: _result_facts.ansible_facts.ansible_distribution == 'Ubuntu'

    - name: Fails if OS is not supported
      ansible.builtin.assert:
        msg: "The host \"{{ _param_gather_host }}\" needs to be CentOS/RHEL, Fedora, or Debian/Ubuntu"
        that: hostvars[_param_gather_host]['distribution_family'] is defined

    - name: Set ssh_host_key_ecdsa
      ansible.builtin.set_fact:
        ssh_host_key_ecdsa: "{{ _result_facts.ansible_facts.ansible_ssh_host_key_ecdsa_public_keytype }} {{ _result_facts.ansible_facts.ansible_ssh_host_key_ecdsa_public }}"
      when: >
        _result_facts.ansible_facts.ansible_ssh_host_key_ecdsa_public_keytype is defined and
        _result_facts.ansible_facts.ansible_ssh_host_key_ecdsa_public is defined

    - name: Gather the package facts
      ansible.builtin.package_facts:
        manager: "{{ hostvars[_param_gather_host].package_manager }}"
      register: _result_packages

    - name: Set podman_is_installed
      ansible.builtin.set_fact:
        podman_is_installed: "{{ true if ('podman' in _result_packages.ansible_facts.packages) else false }}"

    - name: Gather the services facts
      ansible.builtin.service_facts:
      register: _result_services

    - name: Set _service_state to unknown
      ansible.builtin.set_fact:
        _service_state: 'unknown'
      delegate_to: "{{ inventory_hostname }}"

    - name: Set _service_state when firewalld is defined
      ansible.builtin.set_fact:
        _service_state: "{{ _result_services.ansible_facts.services['firewalld'].state }}"
      delegate_to: "{{ inventory_hostname }}"
      when: _result_services.ansible_facts.services['firewalld'] is defined

    - name: Set _service_state when firewalld.service is defined
      ansible.builtin.set_fact:
        _service_state: "{{ _result_services.ansible_facts.services['firewalld.service'].state }}"
      delegate_to: "{{ inventory_hostname }}"
      when: _result_services.ansible_facts.services['firewalld.service'] is defined

    - name: Set firewalld_is_active
      ansible.builtin.set_fact:
        firewalld_is_active: "{{ true if _service_state == 'running' else false }}"

    - name: Clear _service_state
      ansible.builtin.set_fact:
        _service_state: ''
      delegate_to: "{{ inventory_hostname }}"

    - name: Set _service_state when podman is defined
      ansible.builtin.set_fact:
        _service_state: "{{ _result_services.ansible_facts.services['podman'].state }}"
      delegate_to: "{{ inventory_hostname }}"
      when: _result_services.ansible_facts.services['podman'] is defined

    - name: Set _service_state when podman.service is defined
      ansible.builtin.set_fact:
        _service_state: "{{ _result_services.ansible_facts.services['podman.service'].state }}"
      delegate_to: "{{ inventory_hostname }}"
      when: _result_services.ansible_facts.services['podman.service'] is defined

    - name: Set podman_is_active
      ansible.builtin.set_fact:
        podman_is_active: "{{ true if _service_state == 'running' else false }}"

    - name: Set _service_state to unknown
      ansible.builtin.set_fact:
        _service_state: 'unknown'
      delegate_to: "{{ inventory_hostname }}"

    - name: Set _service_state when ovs-vswitchd is defined
      ansible.builtin.set_fact:
        _service_state: "{{ _result_services.ansible_facts.services['ovs-vswitchd'].state }}"
      delegate_to: "{{ inventory_hostname }}"
      when: _result_services.ansible_facts.services['ovs-vswitchd'] is defined

    - name: Set _service_state when ovs-vswitchd.service is defined
      ansible.builtin.set_fact:
        _service_state: "{{ _result_services.ansible_facts.services['ovs-vswitchd.service'].state }}"
      delegate_to: "{{ inventory_hostname }}"
      when: _result_services.ansible_facts.services['ovs-vswitchd.service'] is defined

    - name: Set ovs_is_active
      ansible.builtin.set_fact:
        ovs_is_active: "{{ true if _service_state == 'running' else false }}"

    - name: Add more facts to hostvars
      ansible.builtin.set_fact:
        ansible_default_ipv4_address: "{{ _result_facts.ansible_facts.ansible_default_ipv4.address }}"
      when: _result_facts.ansible_facts.ansible_default_ipv4.address is defined

    - name: Add more facts to hostvars
      ansible.builtin.set_fact:
        ssh_connection_address: "{{ _result_facts.ansible_facts.ansible_env['SSH_CONNECTION'].split(' ')[2] }}"
      when: _result_facts.ansible_facts.ansible_env['SSH_CONNECTION'] is defined

    - name: Add more facts to hostvars
      ansible.builtin.set_fact:
        os: "{{ hostvars[_param_gather_host].os if (hostvars[_param_gather_host].os is defined) else hostvars[_param_gather_host].host_os }}"
        remote_path: "{{ _result_facts.ansible_facts.ansible_env['PATH'] }}"
        remote_home: "{{ _result_facts.ansible_facts.ansible_env['HOME'] }}"
        runtime_path: "{{ _result_facts.ansible_facts.ansible_env['XDG_RUNTIME_DIR'] | default('') | string }}"

    - name: Clear results
      ansible.builtin.set_fact:
        ansible_facts: {}
        packages: {}
        services: {}
        _result_facts: {}
        _result_packages: {}
        _result_services: {}
        _service_state: ''

  delegate_to: "{{ _param_gather_host }}"
  delegate_facts: true