vkhitrin / ansible-libguestfs-collection

Ansible collection for libguestfs modules
https://galaxy.ansible.com/vkhitrin/libguestfs
GNU General Public License v3.0
7 stars 3 forks source link

Unable to locate package #7

Closed Drehmini closed 6 months ago

Drehmini commented 6 months ago

Thanks for creating this collection!

I'm having a bit of trouble with adding a package to an ubuntu cloud image. Ubuntu cloud image: lunar-server-cloudimg-amd64.img

My task:

- name: "Install qemu-guest-agent into ubuntu {{ ubuntu_version_and_arch }}"
      vkhitrin.libguestfs.guestfs_package:
        image: "{{ local_image_path }}"
        name: qemu-guest-agent
        state: present

Error: FAILED! => {"changed": false, "msg": "sh_lines: E: Unable to locate package qemu-guest-agent"}

However, whenever I add the package manually using the command virt-customize -a /mnt/pve/repo/template/iso/lunar-server-cloudimg-amd64.img --install qemu-guest-agent I'm able to successfully install the package:

[   0.0] Examining the guest ...
[   3.8] Setting a random seed
virt-customize: warning: random seed could not be set for this type of
guest
[   3.9] Setting the machine ID in /etc/machine-id
[   3.9] Installing packages: qemu-guest-agent
[  20.7] Finishing off

I'm not sure why the task fails.

EDIT: Some more information I left out.

Ansible version:

ansible --version
ansible [core 2.15.8]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Ansible collection version:

ansible-galaxy collection list

# /home/user/.ansible/collections/ansible_collections
Collection                    Version
----------------------------- -------
vkhitrin.libguestfs           1.1.3

Host python version

python --version
Python 3.11.2

Edit 2: I've discovered I'm able to install packages so it seems limited to just the qemu-guest-agent package :

- name: "Install qemu-guest-agent into ubuntu {{ ubuntu_version_and_arch }}"
      vkhitrin.libguestfs.guestfs_package:
        image: "{{ local_image_path }}"
        name:
          - liburing2
        state: present

TASK [Install qemu-guest-agent into ubuntu lunar amd64] **************************************************************** changed: [host] I'm not really sure how to debug this further.

vkhitrin commented 6 months ago

Hey @Drehmini, apologies for the delayed response.

It is an oversight on my part. While working on this module, most of my use cases were for yum and dnf, which automatically update the package list.

When using virt-customize ... --install, it also performs apt update before installing the package thus you can install qemu-guest-agent.

Here is an example from a verbose log:

virt-customize --debug --verbose -a lunar-server-cloudimg-amd64.img --install qemu-guest-agent

running command:
exec >>'/tmp/builder.log' 2>&1

        export DEBIAN_FRONTEND=noninteractive
        apt_opts='-q -y -o Dpkg::Options::=--force-confnew'
        apt-get $apt_opts update
        apt-get $apt_opts install 'qemu-guest-agent'

Running a task on a newly downloaded image, I can reproduce the same issue:

PLAY [localhost] ****************************************************************************************************************************************************

TASK [Install qemu-guest-agent into ubuntu 23.04] *******************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "sh_lines: E: Unable to locate package qemu-guest-agent"}

If we were to add an apt update task, this would pass:

- hosts: localhost
  gather_facts: false
  tasks:
    - name: "Install qemu-guest-agent into ubuntu 23.04"
      vkhitrin.libguestfs.guestfs_command:
        image: "lunar-server-cloudimg-amd64.img"
        command: "sudo apt update"
    - name: "Install qemu-guest-agent into ubuntu 23.04"
      vkhitrin.libguestfs.guestfs_package:
        image: "lunar-server-cloudimg-amd64.img"
        name:
          - qemu-guest-agent
        state: present
PLAY [localhost] ****************************************************************************************************************************************************

TASK [Install qemu-guest-agent into ubuntu 23.04] *******************************************************************************************

changed: [localhost]

TASK [Install qemu-guest-agent into ubuntu 23.04] *******************************************************************************************

changed: [localhost]

PLAY RECAP **********************************************************************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

I will update the module to perform an update behind the scenes.

Drehmini commented 6 months ago

Hey @vkhitrin ,

No need to apologize! Glad it was easy to debug. I'll implement your work around and wait for a new release!

Thanks again.

vkhitrin commented 6 months ago

Hey @Drehmini, I have published a fix https://galaxy.ansible.com/ui/repo/published/vkhitrin/libguestfs/?version=1.1.4

Please feel free to update the collection locally and let me know if you are facing any issues :)