reconfigure winrm via ansible?

47 views
Skip to first unread message

J Hawkesworth

unread,
Sep 22, 2016, 6:24:15 AM9/22/16
to Ansible Project
Hi,

Has anyone managed to successfully reconfigure winrm remotely via a playbook?  I need to up some timeouts and increase the MaxMemoryPerShellMB

I know that reconfiguring winrm is one of the things that is specifically disallowed over winrm remoting, but I imagine a scheduled task could do it.  I'm aware you also have to restart winrm, but in my case I could happily wait through a win_reboot.  Reconfiguring it manually via RDP is not really an option - too many servers to change!

Many thanks,

Jon

J Hawkesworth

unread,
Sep 22, 2016, 10:57:23 AM9/22/16
to Ansible Project
Well it turns out you can.  Here's a hacky playbook to tweak the timeout

---
# This playbook is intended to modify winrm parameters
# this is involved because changing winrm properties isn't allowed over winrm
# so the play uses a scheduled task to do it


- hosts: windows-boxes
  gather_facts
: true
  tasks
:
   
- name: display current minute of the hour
      debug
:
         
var: ansible_date_time.minute


   
- name: fail if its near the top of the hour because I am too lazy to handle special case of trying to run in 1 minute after 15:59
      fail
: msg="re-run a couple of minutes its not a good time to run a scheduled task"
     
when: ansible_date_time.minute|int > 58


   
- name: fetch original configuration
      raw
: winrm get winrm/config
     
register: old_configuration


   
- name: show original configuration
      debug
:
         
var: old_configuration
   
- name: set time scheduled fact
      set_fact
:
        scheduled_time
: "{{ ansible_date_time.hour|string}}:{{ (1 + ansible_date_time.minute|int) |string}}"


   
- name: schedule the config change
      win_scheduled_task
: name="Configure winrm timeouts 1" execute="winrm" frequency="daily" time="{{ scheduled_time }}" description="fix up winrm timeouts 1" enable=yes state=present user=SYSTEM argument='set winrm/config @{MaxTimeoutms = "36000000"}'


   
- name: wait for 2 minutes for the scheduled task to run
      pause
: minutes=2


   
- name: reboot the box to pick up new configuration
      win_reboot
:


   
- name: disable and remove the scheduled task
      win_scheduled_task
: name="Configure winrm timeouts 1" execute="winrm" frequency="daily" time="{{ scheduled_time }}" description="fix up winrm timeouts 1" enable=no state=absent user=SYSTEM argument='set winrm/config @{MaxTimeoutms = "36000000"}'

   
- name: fetch updated configuration
      raw
: winrm get winrm/config
     
register: new_configuration


   
- name: show updated configuration
      debug
:
         
var: new_configuration

Reply all
Reply to author
Forward
0 new messages