Skip to content

Instantly share code, notes, and snippets.

@miticojo
Created January 23, 2018 09:02
Show Gist options
  • Save miticojo/47ae5193abf3a64ddc590fcdcd2a0de5 to your computer and use it in GitHub Desktop.
Save miticojo/47ae5193abf3a64ddc590fcdcd2a0de5 to your computer and use it in GitHub Desktop.
RHEL/CentOS/Fedora - Report pending update with ansible
- name: check for updates
hosts: all
gather_facts: true
become: yes
tasks:
- name: check for updates (yum)
yum: list=updates update_cache=true
register: updates
when: ansible_distribution_major_version|int < 22
- name: check for updates (dnf)
dnf: list=updates
register: updates
when: ansible_distribution_major_version|int > 21
- name: generate report
local_action: template src=./report.csv.j2 dest=./report.csv
- name: print summary results
debug: msg="{{updates.results|count}} pending updates"
hostname,name,version,release,arch,repo
{% for elem in updates.results %}
{{ansible_fqdn}},{{elem.name}},{{elem.version}},{{elem.release}},{{elem.arch}},{{elem.repo}}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment