Template name
ACS-ECS-ApplyAnsiblePlayBooks
Template description
Runs an Ansible playbooks on Elastic Compute Service (ECS) instances. Only Ansible playbooks that support CentOS, Alibaba Cloud Linux, and Ubuntu are supported.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit | |
targets | The ECS instances on which you want to run the Ansible playbook. | Json | Yes | |||
sourceType | The storage type of the playbook. | String | Yes | |||
sourcePath | The URL of the playbook. | String | Yes | |||
playbookFile | The name of the playbook. | String | Yes | |||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | ||
tokenInfo | The token that is used to download the playbook. | String | No | "" | ||
hosts | The hosts that are used to run the playbook. | String | No | /etc/ansible/hosts | ||
installDependencies | Specifies whether to use CloudOps Orchestration Service (OOS) to install Ansible and its dependencies from the Python Package Index (PyPI) repository. | Boolean | No | True | ||
workingDir | The directory in which the playbook is run. | String | No | /root/ansible-workspace | ||
check | Specifies whether to check the execution of Ansible. | Boolean | No | True | ||
extraVariables | The extra variables to be passed to Ansible when the playbook is run. | String | No | color=red | Regular expression for string verification: ^$ | ^\w+=\S+(\s\w+=\S+)*$ |
verbose | The verbosity level that is used to record the process during which the playbook is run. | String | No | -v | ||
rateControl | The rate control settings. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | ||
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by OOS. | String | No | "" |
Output parameters
Parameter | Description | Type |
commandOutput | String |
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ECS-ApplyAnsiblePlayBooks.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: 'Use this template to run Ansible playbook on ECS Instance.Only supports CentOS, Alibaba Cloud Linux and Ubuntu.'
zh-cn: the description in Chinese
name-en: ACS-ECS-ApplyAnsiblePlayBooks
name-zh-cn: the description in Chinese
categories:
- run_command
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Label:
en: TargetInstance
zh-cn: the description in Chinese
Type: Json
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
sourceType:
Type: String
Label:
en: SourceType
zh-cn: the description in Chinese
AllowedValues:
- oss
- https
- github
sourcePath:
Type: String
Label:
en: SourcePath
zh-cn: the description in Chinese
Description:
en: 'You can specify the URL in the following formats: https://example.com/playbook.yml'
zh-cn: the description in Chinese
playbookFile:
Label:
en: PlaybookFile
zh-cn: the description in Chinese
Description:
en: ' For example: example.yml'
zh-cn: the description in Chinese
Type: String
tokenInfo:
Type: String
Label:
en: TokenInfo
zh-cn: the description in Chinese
Description:
en: 'It is only required when downloading palybook from GitHub'
zh-cn: the description in Chinese
Default: ""
hosts:
Type: String
Label:
en: Hosts
zh-cn: the description in Chinese
Default: /etc/ansible/hosts
installDependencies:
Label:
en: InstallDependencies
zh-cn: the description in Chinese
Description:
en: 'If set to True, OOS installs Ansible and its dependencies, including Python, from the PyPI repo. If set to False, then verify that Ansible and its dependencies are installed on the target instances.'
zh-cn: the description in Chinese
Type: Boolean
Default: true
workingDir:
Label:
en: WorkingDir
zh-cn: the description in Chinese
Type: String
Default: /root/ansible-workspace
check:
Label:
en: Check
zh-cn: the description in Chinese
Type: Boolean
Default: true
extraVariables:
Type: String
Label:
en: ExtraVariables
zh-cn: the description in Chinese
Description:
en: 'Enter a space separated list of key/value pairs. For example: color=red flavor=lime'
zh-cn: the description in Chinese
Default: color=red
AllowedPattern: ^$|^\w+\=\S+(\s\w+\=\S+)*$
verbose:
Type: String
Label:
en: Verbose
zh-cn: the description in Chinese
Description:
en: 'Specify -v for low verbosity, -vv or -vvv for medium verbosity, and -vvvv for debug level.'
zh-cn: the description in Chinese
AllowedValues:
- '-v'
- '-vv'
- '-vvv'
- '-vvvv'
Default: '-v'
rateControl:
Label:
en: RateControl
zh-cn: the description in Chinese
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: the description in Chinese
Action: 'ACS::SelectTargets'
Properties:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: '{{ regionId }}'
Filters:
- '{{ targets }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId'
- Name: applyPlaybook
Action: 'ACS::ECS::ApplyAnsiblePlayBook'
Description:
en: Apply the specified playbook
zh-cn: the description in Chinese
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
sourceType: '{{ sourceType }}'
sourcePath: '{{ sourcePath }}'
playbookFile: '{{ playbookFile }}'
tokenInfo: '{{ tokenInfo }}'
hosts: '{{ hosts }}'
installDependencies: '{{ installDependencies }}'
workingDir: '{{ workingDir }}'
check: '{{ check }}'
extraVariables: '{{ extraVariables }}'
verbose: '{{ verbose }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
RateControl: '{{ rateControl }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: commandOutput
Outputs:
commandOutput:
Type: String
Value: '{{ applyPlaybook.commandOutputs }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- sourceType
- sourcePath
- playbookFile
- tokenInfo
- hosts
- installDependencies
- workingDir
- check
- extraVariables
- verbose
Label:
default:
zh-cn: the description in Chinese
en: Configure Parameters
- Parameters:
- regionId
- targets
Label:
default:
zh-cn: the description in Chinese
en: Select Instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options