Win patch (#11)

Add patching report for windows, cloud destroy VM, and Windows Full blueprint
This commit is contained in:
willtome
2022-03-30 11:03:08 -05:00
committed by GitHub
parent 8e56c5bbf6
commit 0ed4737985
48 changed files with 182 additions and 377 deletions

View File

@@ -22,7 +22,7 @@
- name: AWS| CREATE VM | save ami
set_fact:
aws_instance_ami: >
{{ amis.images | selectattr('name', 'defined') | sort(attribute='creation_date') | last }}
{{ (amis.images | selectattr('name', 'defined') | sort(attribute='creation_date'))[-2] }}
- name: AWS| CREATE VM | create instance
amazon.aws.ec2_instance:

View File

@@ -1,38 +0,0 @@
- name: Create HTML report
ansible.builtin.template:
src: report.j2
dest: "{{ file_path }}/windowspatch.html"
check_mode: no
- name: Copy CSS over
ansible.builtin.copy:
src: "css"
dest: "{{ file_path }}"
directory_mode: true
check_mode: no
- name: Copy logo over
ansible.builtin.copy:
src: "webpage_logo.png"
dest: "{{ file_path }}"
directory_mode: true
check_mode: no
- name: Display link to Patch report
ansible.builtin.debug:
msg: "Please go to http://{{ ansible_host }}/windowspatch.html"
- name: Send Report via E-mail
community.general.mail:
host: "{{ EMAIL_HOST }}"
username: "{{ EMAIL_USERNAME }}"
password: "{{ EMAIL_PASSWORD }}"
port: "{{ EMAIL_PORT }}"
subject: "Windows Patching Report"
body: "{{ lookup('template', 'report.j2') }}"
from: "{{ EMAIL_FROM }}"
to: "{{ EMAIL_TO }}"
subtype: html
delegate_to: localhost
become: false
check_mode: no

View File

@@ -0,0 +1,14 @@
---
win_update_categories:
- Application
- Connectors
- CriticalUpdates
- DefinitionUpdates
- DeveloperKits
- FeaturePacks Guidance
- SecurityUpdates
- ServicePacks
- Tools
- UpdateRollups
- Updates
allow_reboot: true

View File

@@ -0,0 +1,15 @@
---
- name: Scan packages
demo.patching.win_scan_packages:
check_mode: no
- name: Scan Services
demo.patching.win_scan_services:
check_mode: no
- name: Install Windows Updates
ansible.windows.win_updates:
category_names: "{{ win_update_categories | default(omit) }}"
reboot: "{{ allow_reboot }}"
state: installed
register: patchingresult

View File

@@ -24,4 +24,4 @@
- name: display link to inventory report
ansible.builtin.debug:
msg: "Please go to http://{{ ansible_host }}/reports/linux.html"
msg: "Please go to http://{{ hostvars[report_server]['ansible_host'] }}/reports/linux.html"

View File

@@ -20,7 +20,7 @@
- name: Display link to Linux patch report
ansible.builtin.debug:
msg: "Please go to http://{{ ansible_host }}/reports/linuxpatch.html"
msg: "Please go to http://{{ hostvars[report_server]['ansible_host'] }}/reports/linuxpatch.html"
#- name: Send Report via E-mail
# community.general.mail:

View File

@@ -0,0 +1,20 @@
---
- yum:
name: httpd
state: latest
check_mode: no
- file:
path: /var/www/html/reports/
state: directory
check_mode: no
- copy:
dest: /var/www/html/reports/.htaccess
content: Options +Indexes
check_mode: no
- service:
name: httpd
state: started
check_mode: no

View File

@@ -0,0 +1,23 @@
---
- name: Install IIS
ansible.windows.win_feature:
name: Web-Server
state: present
check_mode: no
- name: Start IIS service
ansible.windows.win_service:
name: W3Svc
state: started
check_mode: no
- name: Create Directory
ansible.windows.win_file:
path: C:\Inetpub\wwwroot\reports
state: directory
check_mode: no
- name: Enable Directory Browsing
ansible.windows.win_powershell:
script: |
"Set-WebConfigurationProperty -filter /system.webServer/directoryBrowse -name enabled -value true -PSPath 'IIS:\Sites\Default Web Site\reports'"

View File

@@ -1,16 +1,19 @@
---
- name: create HTML report
ansible.builtin.template:
ansible.windows.win_template:
src: report.j2
dest: "{{ file_path }}/windows.html"
check_mode: no
- name: copy CSS over
ansible.builtin.copy:
ansible.windows.win_copy:
src: "css"
dest: "{{ file_path }}"
directory_mode: true
check_mode: no
- name: copy logos over
ansible.builtin.copy:
ansible.windows.win_copy:
src: "{{ item }}"
dest: "{{ file_path }}"
directory_mode: true
@@ -18,7 +21,8 @@
- "webpage_logo.png"
- "redhat-ansible-logo.svg"
- "server.png"
check_mode: no
- name: display link to inventory report
ansible.builtin.debug:
msg: "Please go to http://{{ ansible_host }}/windows.html"
#- name: display link to inventory report
# ansible.builtin.debug:
# msg: "Please go to http://{{ host_vars[report_server]['ansible_host'] }}/reports/windows.html"

View File

@@ -75,7 +75,7 @@ collapsible: true
</tr>
</thead>
<tbody>
{% for windows_host in groups['tag_Windows']|sort %}
{% for windows_host in ansible_play_hosts |sort %}
<tr>
<td class="summary_info">
<div id="hostname">

View File

@@ -0,0 +1 @@
file_path: C:\Inetpub\wwwroot\reports

View File

@@ -0,0 +1,23 @@
- name: Create HTML report
ansible.windows.win_template:
src: report.j2
dest: "{{ file_path }}/windowspatch.html"
check_mode: no
- name: Copy CSS over
ansible.windows.win_copy:
src: "css"
dest: "{{ file_path }}"
directory_mode: true
check_mode: no
- name: Copy logo over
ansible.windows.win_copy:
src: "webpage_logo.png"
dest: "{{ file_path }}"
directory_mode: true
check_mode: no
- name: Display link to Patch report
ansible.builtin.debug:
msg: "Please go to http://{{ hostvars[report_server]['ansible_host'] }}/reports/windowspatch.html"

View File

@@ -27,16 +27,16 @@
</tr>
</thead>
<tbody>
{% for windows_host in groups['tag_Windows']|sort %}
{% for windows_host in ansible_play_hosts |sort %}
<tr>
<td>{{hostvars[windows_host]['inventory_hostname']}}</td>
<td>{{hostvars[windows_host]['ansible_distribution']|default("none")}}</td>
<td>
<ul>
{% if hostvars[windows_host].patchresult.updates is defined and hostvars[windows_host].patchresult.found_update_count|int > 0 %}
{% for update in hostvars[windows_host].patchresult.updates %}
{% set updatenum = hostvars[windows_host].patchresult.updates[update] %}
{% if hostvars[windows_host].patchingresult.updates is defined and hostvars[windows_host].patchingresult.found_update_count|int > 0 %}
{% for update in hostvars[windows_host].patchingresult.updates %}
{% set updatenum = hostvars[windows_host].patchingresult.updates[update] %}
<li>{{updatenum.title}}</li>
{% endfor %}
{% else %}
@@ -49,9 +49,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 %}
<center><p>Created with Ansible on {{hostvars[inventory_hostname].ansible_date_time.iso8601}}</p></center>
<script type="text/javascript">
function tableToCSV() {

View File

@@ -0,0 +1 @@
file_path: C:\Inetpub\wwwroot\reports