Use the ali_ros_stack module to update a stack

Updated at:

You can write an Ansible playbook to automatically update a stack using the ali_ros_stack module. This topic provides an example of how to update a stack for a virtual private cloud (VPC).

Prerequisites

Ensure that you have installed and configured the Ansible module on a Linux system using pip3. For more information, see Install and configure Ansible.

Procedure

  1. Create a file named update_vpc.yml and open it in the VI editor.
    vi update_vpc.yml
  2. In edit mode, paste the following sample playbook into the update_vpc.yml file.
    Note For a description of the ali_ros_stack module parameters, see Parameter description.
    - hosts: localhost
      remote_user: root
      tasks:
        - name: Changed. Update Ros Stack
          ali_ros_stack:
            state: present
            stack_name: vpc_2020-04-08_test
            template: update_vpc.json
            timeout_in_minutes: 60
            template_parameters:
              CidrBlock: 192.168.XX.XX/16
              VpcName: UpdateVpc
  3. After saving the file, exit edit mode.
  4. Create a file named update_vpc.json and open it in the VI editor.
    vi update_vpc.json
  5. In edit mode, paste the following sample template into the update_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. After saving the file, exit edit mode.
  7. Run the Ansible playbook to update the VPC-connected instance.
    ansible-playbook update_vpc.yml -v