This topic walks through creating a Resource Orchestration Service (ROS) stack by writing an Ansible playbook. The example creates a Virtual Private Cloud (VPC).
Prerequisites
Before you begin, ensure that you have:
Ansible installed on Linux with
pip3and configured
For more information about ali_ros_stack module parameters, see Parameters.
Procedure
Step 1: Create the playbook
Create a file named create_vpc.yml:
vi create_vpc.ymlAdd the following content:
- hosts: localhost
remote_user: root
tasks:
- name: Changed. Create Ros Stack
ali_ros_stack:
state: present
stack_name: vpc_2020-04-08_test
template: create_vpc.json
timeout_in_minutes: 60
template_parameters:
CidrBlock: 192.168.XX.XX/16
VpcName: CreateVpcThe playbook defines a single task that calls the ali_ros_stack module with these parameters:
| Parameter | Description |
|---|---|
state | Set to present to create the stack. |
stack_name | A unique name for the stack. |
template | Path to the ROS template file that defines the resources. |
timeout_in_minutes | Maximum time (in minutes) to wait for stack creation to complete. |
template_parameters | Input values passed to the template. CidrBlock sets the VPC address range and VpcName sets the VPC name. |
Replace 192.168.XX.XX/16 with your actual CIDR block.Save the file and exit the editor.
Step 2: Create the ROS template
Create a file named create_vpc.json:
vi create_vpc.jsonAdd the following content:
{
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"VpcName": {
"Type": "String",
"Description": "Vpc Name",
"Label": "Vpc Name"
},
"CidrBlock": {
"Type": "String",
"Description": "Vpc CidrBlock",
"Label": "Vpc CidrBlock"
}
},
"Resources": {
"Vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": {
"Ref": "CidrBlock"
},
"VpcName": {
"Ref": "VpcName"
}
}
}
}
}The template has three sections:
| Section | Purpose |
|---|---|
ROSTemplateFormatVersion | Specifies the template format version (2015-09-01). |
Parameters | Declares input variables. VpcName and CidrBlock are both strings passed from the playbook's template_parameters. |
Resources | Defines the infrastructure to create. The Vpc resource (type ALIYUN::ECS::VPC) references both parameters to configure the VPC. |
Save the file and exit the editor.
Step 3: Run the playbook
Run the Ansible playbook to create the VPC:
ansible-playbook create_vpc.yml