From 2955d7cd1ba710f9051c0b11ba2500c1adfe33d1 Mon Sep 17 00:00:00 2001 From: Yunge Zhu <37337818+yungezz@users.noreply.github.com> Date: Thu, 6 Sep 2018 08:04:09 +0800 Subject: [PATCH] add publish url in webapp facts output (#45131) * add publish url in webapp facts output * update name * fix test --- .../cloud/azure/azure_rm_webapp_facts.py | 46 ++++++++++++++++++- .../targets/azure_rm_webapp/tasks/main.yml | 12 +++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_webapp_facts.py b/lib/ansible/modules/cloud/azure/azure_rm_webapp_facts.py index a9e5739cd73..787cfdce0ec 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_webapp_facts.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_webapp_facts.py @@ -126,6 +126,10 @@ webapps: outbound_ip_addresses: description: Outbound ip address of the web app. type: str + ftp_publish_url: + description: Publishing url of the web app when depeloyment type is FTP. + type: str + sample: ftp://xxxx.ftp.azurewebsites.windows.net state: description: State of the web app. eg. running. type: str @@ -275,6 +279,34 @@ class AzureRMWebAppFacts(AzureRMModuleBase): self.fail('Error getting web app {0} publishing credentials - {1}'.format(request_id, str(ex))) return response + def get_webapp_ftp_publish_url(self, resource_group, name): + import xmltodict + + self.log('Get web app {0} app publish profile'.format(name)) + + url = None + try: + content = self.web_client.web_apps.list_publishing_profile_xml_with_secrets(resource_group_name=resource_group, name=name) + if not content: + return url + + full_xml = '' + for f in content: + full_xml += f.decode() + profiles = xmltodict.parse(full_xml, xml_attribs=True)['publishData']['publishProfile'] + + if not profiles: + return url + + for profile in profiles: + if profile['@publishMethod'] == 'FTP': + url = profile['@publishUrl'] + + except CloudError as ex: + self.fail('Error getting web app {0} app settings'.format(name)) + + return url + def get_curated_webapp(self, resource_group, name, webapp): pip = self.serialize_obj(webapp, AZURE_OBJECT_CLASS) @@ -282,15 +314,23 @@ class AzureRMWebAppFacts(AzureRMModuleBase): site_config = self.list_webapp_configuration(resource_group, name) app_settings = self.list_webapp_appsettings(resource_group, name) publish_cred = self.get_publish_credentials(resource_group, name) + ftp_publish_url = self.get_webapp_ftp_publish_url(resource_group, name) except CloudError as ex: pass return self.construct_curated_webapp(webapp=pip, configuration=site_config, app_settings=app_settings, deployment_slot=None, + ftp_publish_url=ftp_publish_url, publish_credentials=publish_cred) - def construct_curated_webapp(self, webapp, configuration=None, app_settings=None, deployment_slot=None, publish_credentials=None): + def construct_curated_webapp(self, + webapp, + configuration=None, + app_settings=None, + deployment_slot=None, + ftp_publish_url=None, + publish_credentials=None): curated_output = dict() curated_output['id'] = webapp['id'] curated_output['name'] = webapp['name'] @@ -346,6 +386,10 @@ class AzureRMWebAppFacts(AzureRMModuleBase): if deployment_slot: curated_output['deployment_slot'] = deployment_slot + # ftp_publish_url + if ftp_publish_url: + curated_output['ftp_publish_url'] = ftp_publish_url + # curated publish credentials if publish_credentials and self.return_publish_profile: curated_output['publishing_username'] = publish_credentials.publishing_user_name diff --git a/test/integration/targets/azure_rm_webapp/tasks/main.yml b/test/integration/targets/azure_rm_webapp/tasks/main.yml index af4890fd37e..309cf824fc4 100644 --- a/test/integration/targets/azure_rm_webapp/tasks/main.yml +++ b/test/integration/targets/azure_rm_webapp/tasks/main.yml @@ -316,3 +316,15 @@ - name: Assert the web app was created assert: that: output.changed + +- name: Get facts with publish profile + azure_rm_webapp_facts: + resource_group: "{{ resource_group }}" + name: "{{ win_app_name }}13" + no_log: true + register: facts + +- name: Assert publish profile returned + assert: + that: + - facts.webapps[0].ftp_publish_url != '' \ No newline at end of file