I want to get all installed and available packages using Ansible yum
module. I tried below snippet but it return empty result.
- name: print
yum:
list: installed,available
register: pkg
I want to get all installed and available packages using Ansible yum
module. I tried below snippet but it return empty result.
- name: print
yum:
list: installed,available
register: pkg
The list
parameter is a string, not a list, as pointed by the documentation, so, if you pass something else than the reserved words — installed
, updates
, available
or repos
— it will be considered as a packaged and will probably return your nothing.
We can also confirm this by Ansible code source, where the list
value is considered in an if .. elif .. else
:
if stuff == 'installed':
return [ pkg_to_dict(p) for p in sorted(is_installed(module, repoq, '-a', conf_file, qf=is_installed_qf)) if p.strip() ]
elif stuff == 'updates':
return [ pkg_to_dict(p) for p in sorted(is_update(module, repoq, '-a', conf_file, qf=qf)) if p.strip() ]
elif stuff == 'available':
return [ pkg_to_dict(p) for p in sorted(is_available(module, repoq, '-a', conf_file, qf=qf)) if p.strip() ]
elif stuff == 'repos':
return [ dict(repoid=name, state='enabled') for name in sorted(repolist(module, repoq)) if name.strip() ]
else:
return [ pkg_to_dict(p) for p in sorted(is_installed(module, repoq, stuff, conf_file, qf=is_installed_qf) + is_available(module, repoq, stuff, conf_file, qf=qf)) if p.strip() ]
You should be able to make a combined list of all of them using list concatenation and two yum
tasks:
- yum:
list: installed
register: installed_pkg
- yum:
list: available
register: available_pkg
- debug:
var: installed_pkg.results + available_pkg