I tried to implement a new YML to list and give me the common packages in my 60 plus servers.
Here is the draft:
- name: Save list of common packages
hosts: all
gather_facts: false
tasks:
- name: Get list of installed packages
shell: dpkg-query -W -f="\${Package} \${Version}\n" | sort
register: packages
- name: Set fact for list of installed packages
set_fact:
installed_packages: "{{ packages.stdout_lines }}"
- name: Add installed packages to group_vars
add_host:
name: "{{ inventory_hostname }}"
installed_packages: "{{ installed_packages }}"
- name: Get list of installed packages across all servers
shell: "grep installed_packages group_vars/* | cut -d: -f3- | sort -u | xargs -n 1 echo | sort | uniq -c | grep '^\s*{{ groups['all'][0] }}' | awk '{$1=\"\"; print $0}'"
register: common_packages
delegate_to: localhost
- name: Print list of common packages
debug:
var: common_packages.stdout_lines
- name: Save list of common packages to file
copy:
content: "{{ common_packages.stdout }}"
dest: "/resultdpkg/result.txt"
delegate_to: localhost
It seems to work but nothing displayed in the file result. Can you help?
List all commons dpkg
in all my servers and print / save the result in a file in the "bastion".