Skip to content

Instantly share code, notes, and snippets.

@mmaridev
Last active November 23, 2019 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmaridev/6b7cb4b40b978e582dd5fec2eda727f2 to your computer and use it in GitHub Desktop.
Save mmaridev/6b7cb4b40b978e582dd5fec2eda727f2 to your computer and use it in GitHub Desktop.
Ansible playbook to upgrade a Windows client
# Copyright (c) 2019 Marco Marinello <me@marcomarinello.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# This playbook is intended to update a MS workstation
---
- name: Update a Windows client
hosts: all
tasks:
- name: Search for updates
win_updates:
state: searched
register: search
- name: Tell searched categories
debug: var=search
- name: Define upgrades to be installed
set_fact:
up_cats: "{{ search.filtered_updates.values() | map(attribute='categories') | list }}"
- name: Say what we're installing
debug: var=up_cats[0]
- name: Run Windows Update
win_updates:
category_names: "{{ up_cats[0] }}"
reboot: yes
register: up
- name: Tell how many udates were installed
debug: var=up
- block:
- name: "Create log directory"
file:
path: "winlog"
state: directory
changed_when: false
- name: "Write changes to logfile"
copy:
content: "{{ up }}"
dest: "winlog/dist-upgrade_{{ ansible_date_time.iso8601 }}.log"
changed_when: false
when: updated is defined
connection: local
[win]
192.168.10.1
[win:vars]
ansible_shell_type = powershell
ansible_connection = ssh
ansible_user = ansibleadmin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment