ansible-aur icon indicating copy to clipboard operation
ansible-aur copied to clipboard

Setting `name` to an empty list

Open pmav99 opened this issue 3 years ago • 1 comments

Hi

When you specify an empty list to name, then a error is raised. E.g.:

---

- name: "install aur packages"
  hosts: "localhost"
  connection: "local"
  become: True

  vars:
    # aur_pkgs: []    # This fails with an explicit fail message
    aur_pkgs:      # This raises an exception

roles:
    - name: "Install AUR packages"
      kewlfft.aur.aur:
        name: "{{ aur_pkgs }}"
        use: "yay"
        state: "present"
      become_user: "aur_builder"

Obviously, not a huge issue, but this behavior is different from what e.g. ansible.builtin.package does. so i was a bit surprised by it.

FWIW, my use case is having a playbook template which contains something like this:

  vars:
    remove_pkgs:
    pkgs:
    aur_pkgs:

  tasks:
    - name: "Uninstall packages"
      ansible.builtin.package:
        name: "{{ remove_pkgs }}"
        state: "absent"

    - name: "Install packages"
      ansible.builtin.package:
        name: "{{ pkgs }}"
        state: "present"

    - name: "Install AUR packages"
      kewlfft.aur.aur:
        name: "{{ aur_pkgs }}"
        use: "yay"
        state: "present"
      become_user: "aur_builder"

and where I fill in the variables with values as necessary. As it is, I need to comment out the AUR stuff. Again, not a huge deal, but I don't really see why the playbook should fail.

I could make a PR if you agree with this behavior change

Related commit: https://github.com/kewlfft/ansible-aur/commit/95aa8f3047e3c13cd094bf88d407a7ec9410fd0c

pmav99 avatar Nov 08 '21 10:11 pmav99

I haven't looked into it into details but in general I agree to follow the behavior of ansible.builtin.package OK with the PR and if you can clarify how it will react after vs before the PR

kewlfft avatar Nov 08 '21 11:11 kewlfft