Comparing two hosts with ansible (installed packages and configuration files)

558 views
Skip to first unread message

Elb Isna

unread,
Feb 10, 2020, 2:45:39 PM2/10/20
to Ansible Project
How can I use ansible to check out the software differences (installed packages and configuration files) between two debian hosts?

Vladimir Botka

unread,
Feb 10, 2020, 3:16:12 PM2/10/20
to Elb Isna, ansible...@googlegroups.com
Collect the list of installed packages with "package_facts"
https://docs.ansible.com/ansible/latest/modules/package_facts_module.html#package-facts-package-information-as-facts
and use "Set theory filters" to find the differences
https://docs.ansible.com/ansible/devel/user_guide/playbooks_filters.html#set-theory-filters

For example the playbook below shall list the packages installed in
host1 but missing in host2

- hosts: host1:host2
tasks:
- package_facts:
- debug:
msg: "{{ hostvars.host1.ansible_facts.packages|
difference(hostvars.host2.ansible_facts.packages) }}"
run_once: true

HTH,

-vlado

Elb Isna

unread,
Feb 13, 2020, 11:15:41 AM2/13/20
to Ansible Project
Thank you very much for your answer.
Reply all
Reply to author
Forward
0 new messages