update patch report

This commit is contained in:
willtome
2022-03-23 16:33:14 -04:00
parent 69cdbae17a
commit 9e63477254
25 changed files with 51 additions and 20 deletions

View File

@@ -0,0 +1,3 @@
---
exclude_packages: []
allow_reboot: true

View File

@@ -0,0 +1,36 @@
---
- name: Scan packages
demo.patching.scan_packages:
os_family: "{{ ansible_os_family }}"
- name: Scan services
demo.patching.scan_services:
- name: upgrade packages (yum)
yum:
name: '*'
state: latest
exclude: "{{ exclude_packages }}"
when: ansible_pkg_mgr == "yum"
register: patchingresult_yum
- name: upgrade packages (dnf)
ansible.builtin.dnf:
name: '*'
state: latest
exclude: "{{ exclude_packages }}"
when: ansible_pkg_mgr == "dnf"
register: patchingresult_dnf
- name: Check to see if we need a reboot
ansible.builtin.command: needs-restarting -r
register: result
changed_when: result.rc == 1
failed_when: result.rc > 1
check_mode: no
- name: Reboot Server if Necessary
ansible.builtin.reboot:
when:
- result.rc == 1
- allow_reboot is true

View File

@@ -35,17 +35,17 @@
<td>{{hostvars[linux_host]['ansible_distribution_version']|default("none")}}</td>
<td>
<ul>
{% if hostvars[linux_host].patchingresult.changed|default("false",true) == true %}
{% for packagename in hostvars[linux_host].patchingresult.changes.updated|sort %}
{% if hostvars[linux_host].patchingresult_yum.changed|default("false",true) == true %}
{% for packagename in hostvars[linux_host].patchingresult_yum.changes.updated|sort %}
<li> {{ packagename[0] }} - {{ packagename[1] }} </li>
{% endfor %}
{% elif hostvars[linux_host].patchingresultdnf.changed|default("false",true) == true %}
{% for packagename in hostvars[linux_host].patchingresultdnf.results|sort %}
{% elif hostvars[linux_host].patchingresult_dnf.changed|default("false",true) == true %}
{% for packagename in hostvars[linux_host].patchingresult_dnf.results|sort %}
<li> {{ packagename }} </li>
{% endfor %}
{% elif hostvars[linux_host].patchingresultdnf.changed is undefined %}
{% elif hostvars[linux_host].patchingresult_dnf.changed is undefined %}
<li> Patching Failed </li>
{% elif hostvars[linux_host].patchingresult.changed is undefined %}
{% elif hostvars[linux_host].patchingresult_yum.changed is undefined %}
<li> Patching Failed </li>
{% else %}
<li> Compliant </li>
@@ -56,9 +56,7 @@
{% endfor %}
</tbody>
</table>
{% for host in ansible_play_hosts %}
<center><p>Created with Ansible on {{hostvars[host].ansible_date_time.iso8601}}</p></center>
{% endfor %}
<script type="text/javascript">
function tableToCSV() {

View File

@@ -5,30 +5,24 @@
report_server: node1
tasks:
- name: Ensure Unix/Linux platforms only
assert:
that: ansible_os_family != "Windows"
- name: Scan packages (Unix/Linux)
demo.patching.scan_packages:
os_family: "{{ ansible_os_family }}"
- name: Scan services (Unix/Linux)
demo.patching.scan_services:
- include_role:
name: demo.patching.patch_linux
- block:
- yum:
name: httpd
state: latest
check_mode: no
- service:
name: httpd
state: started
check_mode: no
- include_role:
name: demo.patching.build_report_linux
name: demo.patching.report_linux
- include_role:
name: demo.patching.build_report_linux_patch
name: demo.patching.report_linux_patch
delegate_to: "{{ report_server }}"
run_once: yes