Created
August 6, 2017 17:25
-
-
Save irvingpop/801593c2a500f71f444c3617cb3eaff1 to your computer and use it in GitHub Desktop.
Bit of systemd chef code to have clients automatically remove themselves on shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a systemd service that runs at shutdown to remove one's node and client from the chef server, | |
# useful in AutoScale and Terraform-managed scenarios | |
# not useful in cases where you may want to shutdown (but not terminate) a node | |
systemd_unit 'chef-cleanup.service' do | |
content('Unit' => { | |
'Description' => 'Delete my own Chef node and client objects at shutdown/termination', | |
'DefaultDependencies' => 'no', | |
'Before' => 'shutdown.target halt.target', | |
}, | |
'Service' => { | |
'Type' => 'oneshot', | |
'ExecStart' => "/opt/chef/bin/knife node delete #{node.name} -y -c /etc/chef/client.rb && /opt/chef/bin/knife client delete #{node.name} -y -c /etc/chef/client.rb", | |
}, | |
'Install' => { | |
'WantedBy' => 'halt.target shutdown.target', | |
}) | |
action [:create, :enable] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I try this code with Ubuntu 18.04 LTS on AWS, and my node is not unregister.
Do you have an idea ?