テンプレート名
ACS-ECS-ConfigureDocker:Docker を一括でインストールまたはアンインストール
テンプレートの説明
複数の Elastic Compute Service ( ECS ) インスタンスに Docker を一度にインストールまたはアンインストールします。
テンプレートタイプ
自動化
所有者
Alibaba Cloud
入力パラメーター
パラメーター | 説明 | タイプ | 必須 | デフォルト値 | 制限 |
action | 操作タイプ | String | はい | ||
targets | ターゲットインスタンス | Json | はい | ||
regionId | リージョン ID。 | String | いいえ | {{ ACS::RegionId }} | |
rateControl | タスクの同時実行率 | Json | いいえ | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | CloudOps Orchestration Service ( OOS ) によって引き受けられる Resource Access Management ( RAM ) ロール。 | String | いいえ | "" |
出力パラメーター
パラメーター | 説明 | タイプ |
commandOutput | String |
テンプレートを実行するために必要な権限ポリシー
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳細
詳細については、GitHub の ACS-ECS-ConfigureDocker.yml をご参照ください。
テンプレートコンテンツ
FormatVersion: OOS-2019-06-01
Description:
ja: 複数の ECS インスタンスに Docker をインストールまたはアンインストールします。
name-ja: ACS-ECS-ConfigureDocker
categories:
- run_command
Parameters:
regionId:
Type: String
Label:
ja: リージョン ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
action:
Type: String
Label:
ja: アクション
AllowedValues:
- install
- uninstall
targets:
Type: Json
Label:
ja: ターゲットインスタンス
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
rateControl:
Label:
ja: レート制御
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
ja: OOS が引き受けるロール
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
ja: 指定された ECS インスタンスを取得します。
Action: 'ACS::SelectTargets'
Properties:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: '{{ regionId }}'
Filters:
- '{{ targets }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId'
- Name: runCommand
Action: 'ACS::ECS::RunCommand'
Properties:
commandContent: |-
#!/bin/bash
yum --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "{{action}}" = "install" ]; then
yum install -y docker
if [ $? -ne 0 ]; then
echo "Docker installation failed. Check your command." >&2;
exit 1;
fi
exit 0;
elif [ "{{action}}" = "uninstall" ]; then
yum remove -y docker
if [ $? -ne 0 ]; then
echo "Docker uninstallation failed. Check your command." >&2;
exit 1;
fi
exit 0;
else
echo "The command for the action parameter must be install or uninstall." >& 2
exit 1;
fi
fi
apt-get --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "{{action}}" = "install" ]; then
apt-get -y update && apt-get -y install docker.io
if [ $? -ne 0 ]; then
echo "Docker installation failed. Check your command." >&2;
exit 1;
fi
exit 0;
elif [ "{{action}}" = "uninstall" ]; then
apt-get -y remove docker.io
if [ $? -ne 0 ]; then
echo "Docker uninstallation failed. Check your command." >&2;
exit 1;
fi
exit 0;
else
echo "The command for the action parameter must be install or uninstall." >& 2
exit 1;
fi
fi
echo "Unknown package installer. Only yum and apt-get are supported." >&2;
exit 1;
instanceId: '{{ ACS::TaskLoopItem }}'
commandType: RunShellScript
Loop:
Items: '{{ getInstance.instanceIds }}'
RateControl: '{{ rateControl }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Outputs:
commandOutput:
Type: String
Value: '{{ runCommand.commandOutputs }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- action
Label:
default:
ja: パラメーターの設定
- Parameters:
- regionId
- targets
Label:
default:
ja: ECS インスタンスの選択
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
ja: 詳細オプション