I have below ansible tasks which compares list of packages against register output obtained from yum module.
- hosts: localhost
vars:
pkgs: [ 'git', 'rsync', 'python36' ]
tasks:
- name: stats for installed pkgs
yum:
state: installed
register: installed
- name: Compare against register
set_fact:
unwanted_pkgs: >-
[
{% for value in installed.results %}
{% for pkg in pkgs %}
{% if value.name | regex_search(pkg) %}
" {{ value.name }}",
{% endif %}
{% endfor %}
{% endfor %}
]
- name: print
debug:
msg: "{{ unwanted_pkgs }}"
Upon executing above playbook, debug task print output as :
git
git-core
git-core-doc
python36
python36-devel
While executing the task it prints additional packages (eg: git-core, git-core-doc and python36-devel which I have not defined in pkgs variable). How this can be avoided ?