|
|
|
@ -158,6 +158,16 @@ options:
|
|
|
|
|
- Purge any existing application settings. Replace web app application settings with app_settings.
|
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
|
|
app_state:
|
|
|
|
|
description:
|
|
|
|
|
- Start/Stop/Restart the web app.
|
|
|
|
|
type: str
|
|
|
|
|
choices:
|
|
|
|
|
- started
|
|
|
|
|
- stopped
|
|
|
|
|
- restarted
|
|
|
|
|
default: started
|
|
|
|
|
|
|
|
|
|
state:
|
|
|
|
|
description:
|
|
|
|
|
- Assert the state of the Web App.
|
|
|
|
@ -410,6 +420,11 @@ class AzureRMWebApps(AzureRMModuleBase):
|
|
|
|
|
type='bool',
|
|
|
|
|
default=False
|
|
|
|
|
),
|
|
|
|
|
app_state=dict(
|
|
|
|
|
type='str',
|
|
|
|
|
choices=['started', 'stopped', 'restarted'],
|
|
|
|
|
default='started'
|
|
|
|
|
),
|
|
|
|
|
state=dict(
|
|
|
|
|
type='str',
|
|
|
|
|
default='present',
|
|
|
|
@ -450,6 +465,7 @@ class AzureRMWebApps(AzureRMModuleBase):
|
|
|
|
|
self.container_settings = None
|
|
|
|
|
|
|
|
|
|
self.purge_app_settings = False
|
|
|
|
|
self.app_state = 'started'
|
|
|
|
|
|
|
|
|
|
self.results = dict(
|
|
|
|
|
changed=False,
|
|
|
|
@ -595,6 +611,7 @@ class AzureRMWebApps(AzureRMModuleBase):
|
|
|
|
|
|
|
|
|
|
to_be_updated = True
|
|
|
|
|
self.to_do = Actions.CreateOrUpdate
|
|
|
|
|
self.site.tags = self.tags
|
|
|
|
|
|
|
|
|
|
# service plan is required for creation
|
|
|
|
|
if not self.plan:
|
|
|
|
@ -631,7 +648,7 @@ class AzureRMWebApps(AzureRMModuleBase):
|
|
|
|
|
|
|
|
|
|
self.log('Result: {0}'.format(old_response))
|
|
|
|
|
|
|
|
|
|
update_tags, old_response['tags'] = self.update_tags(old_response.get('tags', dict()))
|
|
|
|
|
update_tags, self.site.tags = self.update_tags(old_response.get('tags', None))
|
|
|
|
|
|
|
|
|
|
if update_tags:
|
|
|
|
|
to_be_updated = True
|
|
|
|
@ -693,8 +710,26 @@ class AzureRMWebApps(AzureRMModuleBase):
|
|
|
|
|
|
|
|
|
|
if self.to_do == Actions.CreateOrUpdate:
|
|
|
|
|
response = self.create_update_webapp()
|
|
|
|
|
|
|
|
|
|
self.results['id'] = response['id']
|
|
|
|
|
|
|
|
|
|
webapp = None
|
|
|
|
|
if old_response:
|
|
|
|
|
webapp = old_response
|
|
|
|
|
if response:
|
|
|
|
|
webapp = response
|
|
|
|
|
|
|
|
|
|
if webapp:
|
|
|
|
|
if (webapp['state'] != 'Stopped' and self.app_state == 'stopped') or \
|
|
|
|
|
(webapp['state'] != 'Running' and self.app_state == 'started') or \
|
|
|
|
|
self.app_state == 'restarted':
|
|
|
|
|
|
|
|
|
|
self.results['changed'] = True
|
|
|
|
|
if self.check_mode:
|
|
|
|
|
return self.results
|
|
|
|
|
|
|
|
|
|
self.set_webapp_state(self.app_state)
|
|
|
|
|
|
|
|
|
|
return self.results
|
|
|
|
|
|
|
|
|
|
# compare existing web app with input, determine weather it's update operation
|
|
|
|
@ -943,6 +978,29 @@ class AzureRMWebApps(AzureRMModuleBase):
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def set_webapp_state(self, appstate):
|
|
|
|
|
'''
|
|
|
|
|
Start/stop/restart web app
|
|
|
|
|
:return: deserialized updating response
|
|
|
|
|
'''
|
|
|
|
|
try:
|
|
|
|
|
if appstate == 'started':
|
|
|
|
|
response = self.web_client.web_apps.start(resource_group_name=self.resource_group, name=self.name)
|
|
|
|
|
elif appstate == 'stopped':
|
|
|
|
|
response = self.web_client.web_apps.stop(resource_group_name=self.resource_group, name=self.name)
|
|
|
|
|
elif appstate == 'restarted':
|
|
|
|
|
response = self.web_client.web_apps.restart(resource_group_name=self.resource_group, name=self.name)
|
|
|
|
|
else:
|
|
|
|
|
self.fail("Invalid web app state {0}".format(appstate))
|
|
|
|
|
|
|
|
|
|
self.log("Response : {0}".format(response))
|
|
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
except CloudError as ex:
|
|
|
|
|
request_id = ex.request_id if ex.request_id else ''
|
|
|
|
|
self.log("Failed to {0} web app {1} in resource group {2}, request_id {3} - {4}".format(
|
|
|
|
|
appstate, self.name, self.resource_group, request_id, str(ex)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
"""Main execution"""
|
|
|
|
|