How to get the installed apt packages with Ansible

2019-08-26 18:52发布

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条回答
Explosion°爆炸
2楼-- · 2019-08-26 19:10

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 }}" 
查看更多
登录 后发表回答