Tutorial: Scale apps in Azure App Service using Ansible
Important
Ansible 2.7 (or later) is required to run the sample playbooks in this article.
Azure App Service enables you to build and host code. This code can be in the form of web apps, mobile backends, and RESTful APIs. Using App Service, you can develop you code using the programming language of your choice without managing infrastructure. App Service supports both Windows and Linux. Automated deployments from any Git repo are supported, including GitHub and Azure DevOps.
In this article, you learn how to:
- Get facts of an existing App Service plan
- Scale up the App Service plan to S2 with three workers
Prerequisites
- Azure subscription: If you don't have an Azure subscription, create a free account before you begin.
Install Ansible: Do one of the following options:
- Install and configure Ansible on a Linux virtual machine
- Configure Azure Cloud Shell and - if you don't have access to a Linux virtual machine - create a virtual machine with Ansible.
- Azure App Service app - If you don't have an Azure App Service app, configure an app in Azure App Service using Ansible.
Scale up an app
There are two workflows for scaling: scale up and scale out.
Scale up: To scale up means to acquire more resources. These resources include CPU, memory, disk space, VMs, and more. You scale up an app by changing the pricing tier of the App Service plan to which the app belongs. Scale out: To scale out means to increase the number of VM instances that run your app. Depending on your App Service plan pricing tier, you can scale out to as many as 20 instances. Autoscaling allows you to scale instance count automatically based on predefined rules and schedules.
The playbook code in this section defines following operation:
- Get facts of an existing App Service plan
- Update the App service plan to S2 with three workers
Save the following playbook as webapp_scaleup.yml
:
- hosts: localhost
connection: local
vars:
resource_group: myResourceGroup
plan_name: myAppServicePlan
location: eastus
tasks:
- name: Get facts of existing App service plan
azure_rm_appserviceplan_facts:
resource_group: "{{ resource_group }}"
name: "{{ plan_name }}"
register: facts
- debug:
var: facts.appserviceplans[0].sku
- name: Scale up the App service plan
azure_rm_appserviceplan:
resource_group: "{{ resource_group }}"
name: "{{ plan_name }}"
is_linux: true
sku: S2
number_of_workers: 3
- name: Get facts
azure_rm_appserviceplan_facts:
resource_group: "{{ resource_group }}"
name: "{{ plan_name }}"
register: facts
- debug:
var: facts.appserviceplans[0].sku
Run the playbook using ansible-playbook
ansible-playbook webapp_scaleup.yml
After running the playbook, you see output similar to the following results:
PLAY [localhost]
TASK [Gathering Facts]
ok: [localhost]
TASK [Get facts of existing App service plan]
[WARNING]: Azure API profile latest does not define an entry for WebSiteManagementClient
ok: [localhost]
TASK [debug]
ok: [localhost] => {
"facts.appserviceplans[0].sku": {
"capacity": 1,
"family": "S",
"name": "S1",
"size": "S1",
"tier": "Standard"
}
}
TASK [Scale up the App service plan]
changed: [localhost]
TASK [Get facts]
ok: [localhost]
TASK [debug]
ok: [localhost] => {
"facts.appserviceplans[0].sku": {
"capacity": 3,
"family": "S",
"name": "S2",
"size": "S2",
"tier": "Standard"
}
}
PLAY RECAP
localhost : ok=6 changed=1 unreachable=0 failed=0
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for