JM1 / ansible-collection-jm1-libvirt

Ansible Collection for using libvirt https://galaxy.ansible.com/jm1/libvirt
GNU General Public License v3.0
7 stars 2 forks source link

Rocky/Alma/Enterprise linux compatibility? #8

Open vphan13 opened 2 months ago

vphan13 commented 2 months ago

This doesn't seem to work with the above flavors. I'm aware of the missing package, but running the setup bombs out any packages installations are attempted

    - name: Install software required by jm1.libvirt's roles and modules
      import_role:
        name: jm1.libvirt.setup
      tags: libvirt_role

Here is the output of the error

TASK [jm1.pkg.setup : Load tasks specific to OS (fails if OS is unsupported)] ******************************************************************************************************************************
task path: /home/user/virter_config/collections/ansible_collections/jm1/pkg/roles/setup/tasks/main.yml:6
fatal: [drago-lt.bootes]: FAILED! => {
    "msg": "['{{ ansible_facts.distribution }}', \"{{ ansible_facts.distribution_version if ansible_facts.distribution == 'Ubuntu' else ansible_facts.distribution_major_version }}\"]: 'dict object' has no attribute 'distribution'. 'dict object' has no attribute 'distribution'. ['{{ ansible_facts.distribution }}', \"{{ ansible_facts.distribution_version if ansible_facts.distribution == 'Ubuntu' else ansible_facts.distribution_major_version }}\"]: 'dict object' has no attribute 'distribution'. 'dict object' has no attribute 'distribution'"

I created a setup-Rocky-9.yml file under the same directory as the other setup- files, but this does not resolve the issue

ansible -m setup localhost | grep distribution
        "ansible_distribution": "Rocky",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/etc/redhat-release",
        "ansible_distribution_file_variety": "RedHat",
        "ansible_distribution_major_version": "9",
        "ansible_distribution_release": "Blue Onyx",
        "ansible_distribution_version": "9.3",
JM1 commented 2 months ago

What version of Ansible are you using? Do you gather facts before running the role?

vphan13 commented 1 month ago

I do perform a gather fact. My ansible version is ansible 2.14.14

JM1 commented 1 month ago

The error says 'dict object' has no attribute 'distribution', so distribution is not part of ansible_facts in your case. But it should, also in Ansible 2.14. Could you please put this in front of your import_role: and show the output of both tasks, please?

- ansible.builtin.debug:
    var: ansible_facts
vphan13 commented 1 month ago

I think I have figure it out. I needed to create a symlink from setup-CentOS.yml to setup-Rocky-9.yml in the following two directories

/home/user/.ansible/collections/ansible_collections/jm1/libvirt/roles/setup/tasks /home/user/.ansible/collections/ansible_collections/jm1/pkg/roles/setup/tasks

I think the same needs to be done for alma linux

JM1 commented 1 month ago

Rocky Linux and AlmaLinux try to clone RHEL and CentOS as close as possible, so it might be an option for you to define distribution_id as ['CentOS', '9'] or similar in your Ansible inventory (example). This will override the role defaults, releaving you from having to add all those symlinks.

But depending on your Ansible code, it might make sense to skip the roles in jm1.libvirt and jm1.pkg entirely and simply use the Ansible modules only. For example, role jm1.libvirt.server is simply meant as an example of how to use the Ansible modules in that collection, but in production I use different roles (see jm1.cloudy).

vphan13 commented 1 month ago

Ok that makes sense and I will do that but Is there any reason you couldn't add the symlinks into the role? The package names should be the same for Rocky/Alma/CentOS, so I don't think there will be any issues.

JM1 commented 1 month ago

It is certainly possible but a tedious and boring chore. For example, I recently added support for Fedora and that took quite some effort, simply because there are a lot of collections, roles and places to change.

vphan13 commented 1 month ago

Thank you for your support on this. I will make the changes on my end as you suggested. Feel free to close out this ticket or reach out if you need me to test any changes you make