forked from awslabs/lambda-chef-node-cleanup
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
I don't know why it happens, but every week we have a few nodes that don't get deleted. The logs:
=Instance does not appear to be Chef Server managed.=
The code that prints that message is:
def handle(event, _context):
"""Lambda Handler"""
log_event(event)
# If you're using a self signed certificate change
# the ssl_verify argument to False
with chef.ChefAPI(CHEF_SERVER_URL, get_pem(), USERNAME, ssl_verify=VERIFY_SSL):
instance_id = get_instance_id(event)
try:
search = chef.Search('node', 'ec2_instance_id:' + instance_id)
except ChefServerNotFoundError as err:
LOGGER.error(err)
return False
if len(search) != 0:
for instance in search:
node = chef.Node(instance.object.name)
client = chef.Client(instance.object.name)
try:
node.delete()
LOGGER.info('===Node Delete: SUCCESS===')
client.delete()
LOGGER.info('===Client Delete: SUCCESS===')
return True
except ChefServerNotFoundError as err:
LOGGER.error(err)
return False
else:
LOGGER.info('=Instance does not appear to be Chef Server managed.=')
return TrueThe above implies len(search) == 0, which means the node cannot be found. But it's there...
Metadata
Metadata
Assignees
Labels
No labels