You can use the ali_ros_stack module to create a stack by writing Ansible playbook code. This topic describes how to use the ali_ros_stack module to create a stack. VPC creation is used as an example.

Prerequisites

Ansible is installed and configured on Linux.

Procedure

  1. Create a file named create_vpc.yml and open it in the visual editor.
    vi create_vpc.yml
  2. In the edit mode, copy the following playbook code to the create_vpc.yml file:
    Note For more information about the ali_ros_stack module parameters, see Parameters.
    - 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
  3. Save the file and exit the edit mode.
  4. Create a file named create_vpc.json and open it in the visual editor.
    vi create_vpc.json
  5. In the edit mode, copy the following playbook code to the create_vpc.json file:
    {
      "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"
            }
          }
        }
      }
    }
  6. Save the file and exit the edit mode.
  7. Run the Ansible playbook to create a VPC.
    ansible-playbook create_vpc.yml