How to get the installed apt packages with Ansible

2019-08-26 18:57发布

问题:

I am trying to list all installed packages on my Debian 7/8/9 machines. There are easy ways dealing with it using apt or dpkg but I could not find a proper way to do this with ansible out of the box.

Is there a nice and smooth way to do this?

For RHEL machines I found this Post: How to get the installed yum packages with Ansible?

回答1:

It doesn't look like Ansible provides any modules that would support this. You'll have to use shell or command.

- name: Get packages
  shell: dpkg-query -f '${binary:Package}\n' -W
  register: packages

- name: Print packages
  debug:
    msg: "{{ packages.stdout_lines }}"