Patch maas url with port addition

 * Check for actual case

Change-Id: I820fe1710da8903822ef5951f0bfd0cb0e968589
Related-prod: PROD-30209
diff --git a/config-drive/master_config.yaml b/config-drive/master_config.yaml
index f19cc73..e8baa4a 100644
--- a/config-drive/master_config.yaml
+++ b/config-drive/master_config.yaml
@@ -33,7 +33,10 @@
 master_config:
   - &master_config |
     function _post_maas_cfg() {
-      sed -i 's/API_SERVER=.*/API_SERVER=localhost:5240/g' /var/lib/maas/.maas_login.sh
+      # In newer maas version, apache2 disabled, so API avaible on direct service port only
+      if [[ ! $(systemctl is-active --quiet apache2) ]] ; then
+        sed -i 's/API_SERVER=.*/API_SERVER=localhost:5240/g' /var/lib/maas/.maas_login.sh
+      fi
       source /var/lib/maas/.maas_login.sh
       # disable backports for maas enlist pkg repo. Those operation enforce maas
       # to re-create sources.list and drop [source] fetch-definition from it.