Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pdkignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
/.yardopts
/spec/
/.vscode/
/html/
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

## [0.11.2](https://github.com/albatrossflavour/puppet_os_patching/tree/0.11.2) (2019-06-04)
[Full Changelog](https://github.com/albatrossflavour/puppet_os_patching/compare/0.11.1...0.11.2)

**Fixed bugs:**

- Travis tests taking too long [\#138](https://github.com/albatrossflavour/puppet_os_patching/issues/138)
- Version 0.11.1 of module cannot be installed on Windows \(via Agent\) [\#136](https://github.com/albatrossflavour/puppet_os_patching/issues/136)
- Unable to run task os\_patching::patch\_server Windows 2012r2 with puppet enterprise agent 6.4.2 [\#133](https://github.com/albatrossflavour/puppet_os_patching/issues/133)
- \#138 - fix travis issues [\#139](https://github.com/albatrossflavour/puppet_os_patching/pull/139) ([albatrossflavour](https://github.com/albatrossflavour))

**Merged pull requests:**

- \#136 add html to the pdkignore [\#137](https://github.com/albatrossflavour/puppet_os_patching/pull/137) ([albatrossflavour](https://github.com/albatrossflavour))
- Issue/133 eventlog puppet agent 6.4.2 [\#134](https://github.com/albatrossflavour/puppet_os_patching/pull/134) ([nathangiuliani](https://github.com/nathangiuliani))

## [0.11.1](https://github.com/albatrossflavour/puppet_os_patching/tree/0.11.1) (2019-05-07)
[Full Changelog](https://github.com/albatrossflavour/puppet_os_patching/compare/0.11.0...0.11.1)

Expand All @@ -13,6 +28,7 @@

**Merged pull requests:**

- V0.11.1 release to master [\#132](https://github.com/albatrossflavour/puppet_os_patching/pull/132) ([albatrossflavour](https://github.com/albatrossflavour))
- Updated ReadMe [\#131](https://github.com/albatrossflavour/puppet_os_patching/pull/131) ([nathangiuliani](https://github.com/nathangiuliani))
- \#129 restrictions on stdlib are too tight [\#130](https://github.com/albatrossflavour/puppet_os_patching/pull/130) ([albatrossflavour](https://github.com/albatrossflavour))

Expand Down Expand Up @@ -289,4 +305,4 @@



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ This shows there are no updates which can be applied to this server and the serv
}
```

Where it shows 6 packages with available updates, along with an array of the package names. None of the packges are tagged as security related (requires Debian, a subscription to RHEL or a Windows system). There are no blockers to patching and the blackout window defined is not in effect.
Where it shows 6 packages with available updates, along with an array of the package names. None of the packages are tagged as security related (requires Debian, a subscription to RHEL or a Windows system). There are no blockers to patching and the blackout window defined is not in effect.

The reboot_required flag is set to true, which means there have been changes to packages that require a reboot (libc, kernel etc) but a reboot hasn't happened. The apps_needing_restart shows the PID and command line of applications that are using files that have been upgraded but the process hasn't been restarted.

Expand Down Expand Up @@ -308,11 +308,11 @@ As Windows includes no native command line tools to manage update installation,

#### Supported Windows Versions

Windows Server 2008 (x86 and x64) through to 2019 have been tested. The code should also function on the equivelant client versions of Windows (e.g. Vista and newer), however this has not been thoroughly tested.
Windows Server 2008 (x86 and x64) through to 2019 have been tested. The code should also function on the equivalent client versions of Windows (e.g. Vista and newer), however this has not been thoroughly tested.

#### Configuration of Windows Update

This module does *not* handle the configuration of the update source or any of the other Windows Update settings - it simply triggers a search (fact generation) or searc, download and install (patch_server task). It is recommended to use the [puppetlabs wsus_client module](https://forge.puppet.com/puppetlabs/wsus_client) to configure the followng options:
This module does *not* handle the configuration of the update source or any of the other Windows Update settings - it simply triggers a search (fact generation) or search, download and install (patch_server task). It is recommended to use the [puppetlabs wsus_client module](https://forge.puppet.com/puppetlabs/wsus_client) to configure the following options:

* WSUS server if you are using one (although this is not strictly required)
* Set the mode to automatically download updates and notify for install (`AutoNotify`)
Expand All @@ -335,7 +335,7 @@ class { 'wsus_client':

* If updates or packages are installed outside of this script (e.g. by a user or another automated process), the results will not be captured in the facts.

* On Windows systems, the timeout parameter of the `patch_server` task is implemented as a maintenace window end time (e.g. start time + timeout). This is used by doing a calculation prior to installing each update. If there is insufficient available, the update run will stop. However, at this stage each update is estimated to take 5 minutes to install. This will be improved in a future release to perform an estimation based on update size or type (e.g. an SCCM-like 5 minutes for hotfix, 30 minutes for cumulative update).
* On Windows systems, the timeout parameter of the `patch_server` task is implemented as a maintenance window end time (e.g. start time + timeout). This is used by doing a calculation prior to installing each update. If there is insufficient available, the update run will stop. However, at this stage each update is estimated to take 5 minutes to install. This will be improved in a future release to perform an estimation based on update size or type (e.g. an SCCM-like 5 minutes for hotfix, 30 minutes for cumulative update).

## Development

Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
{
schedule => daily,
start_time => "01:${patch_cron_min}",
minutes_interval => '60',
minutes_interval => '720',
},
{
schedule => 'boot',
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "albatrossflavour-os_patching",
"version": "0.11.1",
"version": "0.11.2",
"author": "Tony Green",
"summary": "Perform OS level patching through tasks and report on patch levels through facts",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/os_patching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class { 'os_patching':
expect(file(cache_dir + '/blackout_windows')).not_to be_file
expect(file(cache_dir + '/patch_window')).not_to be_file
expect(file('/usr/local/bin/os_patching_fact_generation.sh')).to be_file
if host_inventory['facter']['os']['name'] == 'CentOS' && host_inventory['facter']['os']['release']['major'] == '7'
if host_inventory['facter']['os']['name'] == 'Ubuntu'
run_bolt_task('os_patching::patch_server')
end
if host_inventory['facter']['os']['name'] == 'CentOS' || host_inventory['facter']['os']['name'] == 'Ubuntu'
Expand Down
67 changes: 14 additions & 53 deletions tasks/patch_server.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,5 @@
#!/opt/puppetlabs/puppet/bin/ruby

# windows logging class
class WinLog
def initialize
require 'win32/eventlog'

# log to send events to
windows_log = 'Application'

# source of event shown in event log
@event_source = 'os_patching'

# add event source if needed
# we probably should generate and register an mc file, but the events still show without it
Win32::EventLog.add_event_source(:source => windows_log, :key_name => @event_source)

# create logger
@logger = Win32::EventLog.new
end

# match SysLog::Logger event types

def debug(data)
@logger.report_event(:event_type => Win32::EventLog::INFO_TYPE, :data => "Debug: #{data}", :source => @event_source)
end

def error(data)
@logger.report_event(:event_type => Win32::EventLog::ERROR_TYPE, :data => data, :source => @event_source)
end

def fatal(data)
@logger.report_event(:event_type => Win32::EventLog::ERROR_TYPE, :data => "FATAL: #{data}", :source => @event_source)
end

def info(data)
@logger.report_event(:event_type => Win32::EventLog::INFO_TYPE, :data => data, :source => @event_source)
end

def unknown(data)
@logger.report_event(:event_type => Win32::EventLog::INFO_TYPE, :data => "Unknown: #{data}", :source => @event_source)
end

def warn(data)
@logger.report_event(:event_type => Win32::EventLog::WARN_TYPE, :data => data, :source => @event_source)
end
end

require 'rbconfig'
require 'open3'
require 'json'
Expand All @@ -59,8 +13,9 @@ def warn(data)

if IS_WINDOWS
# windows
# create windows event logger
log = WinLog.new
# use ruby file logger
require 'logger'
log = Logger.new('C:/ProgramData/os_patching/os_patching_task.log', 'monthly')
# set paths/commands for windows
fact_generation_script = 'C:/ProgramData/os_patching/os_patching_fact_generation.ps1'
fact_generation_cmd = "#{ENV['systemroot']}/system32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -file #{fact_generation_script}"
Expand Down Expand Up @@ -220,11 +175,17 @@ def err(code, kind, message, starttime)
shortmsg = messagesplitfirst.chomp

history(starttime, shortmsg, exitcode, '', '', '')
log = if IS_WINDOWS
WinLog.new
else
Syslog::Logger.new 'os_patching'
end
if IS_WINDOWS
# windows
# use ruby file logger
require 'logger'
log = Logger.new('C:/ProgramData/os_patching/os_patching_task.log', 'monthly')
else
# not windows
# create syslog logger
require 'syslog/logger'
log = Syslog::Logger.new 'os_patching'
end
log.error "ERROR : #{kind} : #{exitcode} : #{message}"
exit(exitcode.to_i)
end
Expand Down
75 changes: 17 additions & 58 deletions tasks/refresh_fact.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,20 @@
#!/opt/puppetlabs/puppet/bin/ruby

# windows logging class
class WinLog
def initialize
require 'win32/eventlog'

# log to send events to
windows_log = 'Application'

# source of event shown in event log
@event_source = 'os_patching'

# add event source if needed
# we probably should generate and register an mc file, but the events still show without it
Win32::EventLog.add_event_source(:source => windows_log, :key_name => @event_source)

# create logger
@logger = Win32::EventLog.new
end

# match SysLog::Logger event types

def debug(data)
@logger.report_event(:event_type => Win32::EventLog::INFO_TYPE, :data => "Debug: #{data}", :source => @event_source)
end

def error(data)
@logger.report_event(:event_type => Win32::EventLog::ERROR_TYPE, :data => data, :source => @event_source)
end

def fatal(data)
@logger.report_event(:event_type => Win32::EventLog::ERROR_TYPE, :data => "FATAL: #{data}", :source => @event_source)
end

def info(data)
@logger.report_event(:event_type => Win32::EventLog::INFO_TYPE, :data => data, :source => @event_source)
end

def unknown(data)
@logger.report_event(:event_type => Win32::EventLog::INFO_TYPE, :data => "Unknown: #{data}", :source => @event_source)
end

def warn(data)
@logger.report_event(:event_type => Win32::EventLog::WARN_TYPE, :data => data, :source => @event_source)
end
end

require 'rbconfig'
require 'open3'
require 'json'
require 'time'
require 'timeout'

is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
IS_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

$stdout.sync = true

if is_windows
if IS_WINDOWS
# windows
# create windows event logger
log = WinLog.new
# use ruby file logger
require 'logger'
log = Logger.new('C:/ProgramData/os_patching/os_patching_refresh_fact_task.log', 'monthly')
# set paths/commands for windows
fact_generation_script = 'C:/ProgramData/os_patching/os_patching_fact_generation.ps1'
fact_generation_cmd = "#{ENV['systemroot']}/system32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -file #{fact_generation_script}"
Expand Down Expand Up @@ -105,13 +60,17 @@ def err(code, kind, message, starttime)
}

puts JSON.pretty_generate(json)
shortmsg = message.split("\n").first.chomp
history(starttime, shortmsg, exitcode, '', '', '')
log = if is_windows
WinLog.new
else
Syslog::Logger.new 'os_patching'
end
if IS_WINDOWS
# windows
# use ruby file logger
require 'logger'
log = Logger.new('C:/ProgramData/os_patching/os_patching_refresh_fact_task.log', 'monthly')
else
# not windows
# create syslog logger
require 'syslog/logger'
log = Syslog::Logger.new 'os_patching'
end
log.error "ERROR : #{kind} : #{exitcode} : #{message}"
exit(exitcode.to_i)
end
Expand All @@ -120,7 +79,7 @@ def err(code, kind, message, starttime)
refresh_out, stderr, status = Open3.capture3(fact_generation_cmd)

# make output more readable if on windows
refresh_out_log = if is_windows
refresh_out_log = if IS_WINDOWS
refresh_out.split("\n")
else
refresh_out
Expand Down