Skip to content
This repository was archived by the owner on Sep 13, 2019. It is now read-only.
Open
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
27 changes: 17 additions & 10 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@
config['region'],
config['package']['version'],
value_for_platform_family('rhel' => 'linux_amd64',
'debian' => 'debian_amd64'),
'amazon' => 'linux_amd64',
'debian' => 'debian_amd64',
'windows' => 'windows_amd64'),
value_for_platform_family('rhel' => 'amazon-ssm-agent.rpm',
'debian' => 'amazon-ssm-agent.deb')
'amazon' => 'amazon-ssm-agent.rpm',
'debian' => 'amazon-ssm-agent.deb',
'windows' => 'AmazonSSMAgentSetup.exe')
)

# Path where the package is downloaded to
# @since 0.1.0
config['package']['path'] = ::File.join(
Chef::Config['file_cache_path'],
value_for_platform_family('rhel' => 'amazon-ssm-agent.rpm',
'debian' => 'amazon-ssm-agent.deb')
'amazon' => 'amazon-ssm-agent.rpm',
'debian' => 'amazon-ssm-agent.deb',
'windows' => 'AmazonSSMAgentSetup.exe')
)

# Checksum of the package
Expand All @@ -39,12 +45,13 @@
# '5052f18e58'
# )

# Name of the agent service
# set agent on windows
# @since 0.1.0
config['service']['name'] = 'amazon-ssm-agent'

# Actions to set the agent to
# * Note: We set this to disable / start to provide faster boot times
# @since 0.1.0
config['service']['actions'] = %w(disable start)
if node['platform'] == 'windows'
config['service']['name'] = 'AmazonSSMAgent'
config['service']['actions'] = %w(enable start)
else
config['service']['name'] = 'amazon-ssm-agent'
config['service']['actions'] = %w(enable start)
end
end
27 changes: 27 additions & 0 deletions files/default/install_win_ssm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Clear-Host
$Name = "AmazonSSMAgent"
$Service = Get-Service -display $Name -ErrorAction SilentlyContinue
If (-Not $Service) {
If (Test-Path -Path C:\chef\cache\EC2Install) {
Remove-item C:\chef\cache\EC2*.*
Remove-item C:\chef\cache\EC2Install -recurse
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
Invoke-WebRequest -Uri https://s3.amazonaws.com/ec2-downloads-windows/EC2Config/EC2Install.zip -UseBasicParsing -OutFile C:\chef\cache\EC2Install.zip
Unzip C:\chef\cache\EC2Install.zip C:\chef\cache\EC2Install
$Name = "Ec2Config"
$Service = Get-Service -display $Name -ErrorAction SilentlyContinue
If (-Not $Service) {
C:\chef\cache\EC2Install\EC2Install.exe /install /quiet /norestart
} else {
C:\chef\cache\EC2Install\EC2Install.exe /repair /quiet /norestart
}
}
Else {
'SSM Agent Service exists'
}
37 changes: 35 additions & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
include_recipe "#{cookbook_name}::install"
include_recipe "#{cookbook_name}::logrotate"
# deploy ssm agent on Linux or windows. Cosmin 07.2017

if node['platform'] == 'windows'
include_recipe 'windows'
include_recipe 'chef_handler'
script_path = win_friendly_path(File.join(Chef::Config[:file_cache_path],'install_win_ssm.ps1'))
install_ssm = 'install_win_ssm.ps1'
execute install_ssm do
command "powershell -ExecutionPolicy ByPass -File \"#{script_path}\""
action :nothing
end
cookbook_file script_path do
source 'install_win_ssm.ps1'
action :create
notifies :run, "execute[#{install_ssm}]", :immediately
end
else
include_recipe "#{cookbook_name}::logrotate"
remote_file 'amazon-ssm-agent' do
path node['ssm_agent']['package']['path']
source node['ssm_agent']['package']['url']
checksum node['ssm_agent']['package']['checksum']
mode 0644
end
package 'amazon-ssm-agent' do
source node['ssm_agent']['package']['path']
provider value_for_platform_family(
'rhel' => Chef::Provider::Package::Yum,
'amazon' => Chef::Provider::Package::Yum,
'debian' => Chef::Provider::Package::Dpkg)
end
service node['ssm_agent']['service']['name'] do
action node['ssm_agent']['service']['actions']
end
end
24 changes: 0 additions & 24 deletions recipes/install.rb

This file was deleted.