All Products
Search
Document Center

Resource Orchestration Service:Create a stack with the ali_ros_stack Ansible module

Last Updated:Feb 27, 2026

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 pip3 and 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.yml

Add 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: CreateVpc

The playbook defines a single task that calls the ali_ros_stack module with these parameters:

ParameterDescription
stateSet to present to create the stack.
stack_nameA unique name for the stack.
templatePath to the ROS template file that defines the resources.
timeout_in_minutesMaximum time (in minutes) to wait for stack creation to complete.
template_parametersInput 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.json

Add 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:

SectionPurpose
ROSTemplateFormatVersionSpecifies the template format version (2015-09-01).
ParametersDeclares input variables. VpcName and CidrBlock are both strings passed from the playbook's template_parameters.
ResourcesDefines 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