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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ If patching was blocked, the task will report similar to below:
Error: Task exited : 100
Patching blocked
```
A summary of the patch run is also written to `/etc/os_patching/run_history`, the last line of which is used by the `os_patching.last_run` fact.
A summary of the patch run is also written to `/var/cache/os_patching/run_history`, the last line of which is used by the `os_patching.last_run` fact.

```bash
2018-08-07T14:47:24+10:00|No patches to apply|Success|false|false|
Expand All @@ -266,20 +266,20 @@ A summary of the patch run is also written to `/etc/os_patching/run_history`, th
2018-08-08T07:53:59+10:00|Patching blocked |100|||
```

### `/etc/os_patching` directory
### `/var/cache/os_patching` directory

This directory contains the various control files needed for the fact and task to work correctly. They are managed by the manifest.

* `/etc/os_patching/blackout_windows` : contains name, start and end time for all blackout windows
* `/etc/os_patching/package_updates` : a list of all package updates available, populated by `/usr/local/bin/os_patching_fact_generation.sh`, triggered through cron
* `/etc/os_patching/security_package_updates` : a list of all security_package updates available, populated by `/usr/local/bin/os_patching_fact_generation.sh`, triggered through cron
* `/etc/os_patching/run_history` : a summary of each run of the `os_patching::patch_server` task, populated by the task
* `/etc/os_patching/reboot_override` : if present, overrides the `reboot=` parameter to the task
* `/etc/os_patching/patch_window` : if present, sets the value for the fact `os_patching.patch_window`
* `/etc/os_patching/reboot_required` : if the OS can determine that the server needs to be rebooted due to package changes, this file contains the result. Populates the fact reboot.reboot_required.
* `/etc/os_patching/apps_to_restart` : a list of processes (PID and command line) that haven't been restarted since the packages they use were patched. Sets the fact reboot.apps_needing_restart and .reboot.app_restart_required.
* `/var/cache/os_patching/blackout_windows` : contains name, start and end time for all blackout windows
* `/var/cache/os_patching/package_updates` : a list of all package updates available, populated by `/usr/local/bin/os_patching_fact_generation.sh`, triggered through cron
* `/var/cache/os_patching/security_package_updates` : a list of all security_package updates available, populated by `/usr/local/bin/os_patching_fact_generation.sh`, triggered through cron
* `/var/cache/os_patching/run_history` : a summary of each run of the `os_patching::patch_server` task, populated by the task
* `/var/cache/os_patching/reboot_override` : if present, overrides the `reboot=` parameter to the task
* `/var/cache/os_patching/patch_window` : if present, sets the value for the fact `os_patching.patch_window`
* `/var/cache/os_patching/reboot_required` : if the OS can determine that the server needs to be rebooted due to package changes, this file contains the result. Populates the fact reboot.reboot_required.
* `/var/cache/os_patching/apps_to_restart` : a list of processes (PID and command line) that haven't been restarted since the packages they use were patched. Sets the fact reboot.apps_needing_restart and .reboot.app_restart_required.

With the exception of the run_history file, all files in /etc/os_patching will be regenerated after a puppet run and a run of the os_patching_fact_generation.sh script, which runs every hour by default. If run_history is removed, the same information can be obtained from PDB, apt/yum and syslog.
With the exception of the run_history file, all files in /var/cache/os_patching will be regenerated after a puppet run and a run of the os_patching_fact_generation.sh script, which runs every hour by default. If run_history is removed, the same information can be obtained from PDB, apt/yum and syslog.

## Limitations

Expand Down
2 changes: 1 addition & 1 deletion files/os_patching_fact_generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case $(facter osfamily) in
;;
esac

DATADIR='/etc/os_patching'
DATADIR='/var/cache/os_patching'
UPDATEFILE="$DATADIR/package_updates"
SECUPDATEFILE="$DATADIR/security_package_updates"

Expand Down
4 changes: 2 additions & 2 deletions lib/facter/os_patching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
warnings = {}

if Facter.value(:kernel) == 'Linux'
os_patching_dir = '/etc/os_patching'
os_patching_dir = '/var/cache/os_patching'
elsif Facter.value(:kernel) == 'windows'
os_patching_dir = 'C:\ProgramData\PuppetLabs\puppet\cache'
os_patching_dir = 'C:\ProgramData\os_patching'
end

chunk(:updates) do
Expand Down
14 changes: 9 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
fail('The patch window can only contain alphanumerics, space, underscore and dash')
}


if ( $::kernel != 'Linux' ) { fail('Unsupported OS') }

if ( $::osfamily == 'RedHat' and $manage_delta_rpm) {
Expand All @@ -159,6 +158,11 @@
}

file { '/etc/os_patching':
ensure => absent,
force => true,
}

file { '/var/cache/os_patching':
ensure => $ensure_dir,
owner => 'root',
group => 'root',
Expand Down Expand Up @@ -210,7 +214,7 @@
true => 'file',
default => 'absent'
}
file { '/etc/os_patching/patch_window':
file { '/var/cache/os_patching/patch_window':
ensure => $patch_window_ensure,
owner => 'root',
group => 'root',
Expand All @@ -228,7 +232,7 @@
false: { $reboot_override_value = 'never' }
default: { $reboot_override_value = $reboot_override }
}
file { '/etc/os_patching/reboot_override':
file { '/var/cache/os_patching/reboot_override':
ensure => $reboot_override_ensure,
owner => 'root',
group => 'root',
Expand Down Expand Up @@ -259,15 +263,15 @@
true => 'file',
default => 'absent'
}
file { '/etc/os_patching/blackout_windows':
file { '/var/cache/os_patching/blackout_windows':
ensure => $blackout_windows_ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => epp("${module_name}/blackout_windows.epp", {
'blackout_windows' => pick($blackout_windows, {}),
}),
require => File['/etc/os_patching'],
require => File['/var/cache/os_patching'],
notify => Exec[$fact_upload_exec],
}

Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/blackout__setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
sh /testcase/spec/acceptance/setup.sh
puppet apply /testcase/examples/init.pp
# mark the next ~day as a blackout
cat << END > /etc/os_patching/blackout_windows
cat << END > /var/cache/os_patching/blackout_windows
test blackout,$(date --iso-8601=seconds),$(date --iso-8601=seconds --date "09:00 tomorrow")
END
END
12 changes: 6 additions & 6 deletions spec/acceptance/init.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@test "/etc/os_patching removed" {
test -d /etc/os_patching
@test "/var/cache/os_patching removed" {
test -d /var/cache/os_patching
}

@test "/usr/local/bin/os_patching_fact_generation.sh installed" {
Expand All @@ -15,17 +15,17 @@
}

@test "reboot_override set to smart" {
grep smart '/etc/os_patching/reboot_override'
grep smart '/var/cache/os_patching/reboot_override'
}

@test "patch_window set to Week3" {
grep Week3 '/etc/os_patching/patch_window'
grep Week3 '/var/cache/os_patching/patch_window'
}

@test "end of year blackout saved" {
grep "End of year change freeze,2018-12-15T00:00:00+10:00,2019-01-15T23:59:59+10:00" /etc/os_patching/blackout_windows
grep "End of year change freeze,2018-12-15T00:00:00+10:00,2019-01-15T23:59:59+10:00" /var/cache/os_patching/blackout_windows
}

@test "end of DST blackout saved" {
grep "End of DST,2019-04-07T00:00:00+10:00,2019-04-08T23:59:59+10:00" /etc/os_patching/blackout_windows
grep "End of DST,2019-04-07T00:00:00+10:00,2019-04-08T23:59:59+10:00" /var/cache/os_patching/blackout_windows
}
10 changes: 5 additions & 5 deletions spec/acceptance/uninstall.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

@test "/etc/os_patching removed" {
! test -d /etc/os_patching
@test "/var/cache/os_patching removed" {
! test -d /var/cache/os_patching
}

@test "/usr/local/bin/os_patching_fact_generation.sh removed" {
Expand All @@ -16,9 +16,9 @@
}

@test "blackout_windows_file removed" {
! test -f /etc/os_patching/blackout_windows
! test -f /var/cache/os_patching/blackout_windows
}

@test "reboot_override file removed" {
! test -f '/etc/os_patching/reboot_override'
}
! test -f '/var/cache/os_patching/reboot_override'
}
2 changes: 1 addition & 1 deletion tasks/patch_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Function to write out the history file after patching
def history(dts, message, code, reboot, security, job)
historyfile = '/etc/os_patching/run_history'
historyfile = '/var/cache/os_patching/run_history'
open(historyfile, 'a') do |f|
f.puts "#{dts}|#{message}|#{code}|#{reboot}|#{security}|#{job}"
end
Expand Down