Template name
ACS-ECS-ApplyAnsiblePlayBooks runs an Ansible Playbook on an instance.
Template description
Runs an Ansible Playbook on an ECS instance. Only CentOS, Alibaba Cloud Linux, and Ubuntu are supported.
Template type
Automation
Owner
Alibaba Cloud
Input parameters
|
Parameter name |
Description |
Type |
Required |
Default value |
Constraints |
|
|
targets |
The target instances. |
JSON |
Yes |
|||
|
sourceType |
The storage type of the playbook. |
String |
Yes |
|||
|
sourcePath |
The URL where the playbook is stored. |
String |
Yes |
|||
|
playbookFile |
The name of the playbook to run. |
String |
Yes |
|||
|
regionId |
The region ID. |
String |
No |
{{ ACS::RegionId }} |
||
|
tokenInfo |
The token used to download the playbook. |
String |
No |
"" |
||
|
hosts |
The hosts file used to run the playbook. |
String |
No |
/etc/ansible/hosts |
||
|
installDependencies |
Whether OOS installs Ansible and its dependencies from the Python Package Index (PyPI) repository. |
Boolean |
No |
True |
||
|
workingDir |
The directory where the playbook is run. |
String |
No |
/root/ansible-workspace |
||
|
check |
Runs an Ansible execution check using the check parameter. |
Boolean |
No |
True |
||
|
extraVariables |
The extra variables that are passed to Ansible at runtime. |
String |
No |
color=red |
String validation regular expression: ^$ |
^\w+=\S+(\s\w+=\S+)*$ |
|
verbose |
The verbosity level for logging the playbook execution. |
String |
No |
-v |
||
|
rateControl |
The concurrency rate of the task execution. |
JSON |
No |
{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} |
||
|
OOSAssumeRole |
The Resource Access Management (RAM) role that OOS assumes. |
String |
No |
"" |
Output parameters
|
Parameter name |
Description |
Type |
|
commandOutput |
String |
Access policy required to run this template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
Details of ACS-ECS-ApplyAnsiblePlayBooks
Template content
FormatVersion: OOS-2019-06-01
Description:
en: 'Use this template to run an Ansible playbook on an ECS instance. This template supports only CentOS, Alibaba Cloud Linux, and Ubuntu.'
zh-cn: 'Use this template to run an Ansible Playbook on an ECS instance. This template supports only CentOS, Alibaba Cloud Linux, and Ubuntu.'
name-en: ACS-ECS-ApplyAnsiblePlayBooks
name-zh-cn: Run an Ansible Playbook in an instance
categories:
- run_command
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: Region ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Label:
en: TargetInstance
zh-cn: Target instance
Type: Json
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
sourceType:
Type: String
Label:
en: SourceType
zh-cn: The storage type of the playbook
AllowedValues:
- oss
- https
- github
sourcePath:
Type: String
Label:
en: SourcePath
zh-cn: The URL where the playbook is stored.
Description:
en: 'Specify the URL in a format such as https://example.com/playbook.yml'
zh-cn: 'Specify the URL in a format such as https://example.com/playbook.yml'
playbookFile:
Label:
en: PlaybookFile
zh-cn: The name of the playbook to run.
Description:
en: 'For example: example.yml'
zh-cn: 'For example: example.yml'
Type: String
tokenInfo:
Type: String
Label:
en: TokenInfo
zh-cn: The token used to download the playbook.
Description:
en: 'Required only when you download a playbook from GitHub.'
zh-cn: 'Required only when you download a playbook from GitHub.'
Default: ""
hosts:
Type: String
Label:
en: Hosts
zh-cn: The hosts file used to run the playbook.
Default: /etc/ansible/hosts
installDependencies:
Label:
en: InstallDependencies
zh-cn: Specifies whether OOS installs Ansible and its dependencies from the PyPI repository.
Description:
en: 'If set to True, OOS installs Ansible and its dependencies, including Python, from the PyPI repository. If set to False, verify that Ansible and its dependencies are installed on the target instances.'
zh-cn: 'If set to True, OOS installs Ansible and its dependencies, including Python, from the PyPI repository. If set to False, verify that Ansible and its dependencies are installed on the target instances.'
Type: Boolean
Default: true
workingDir:
Label:
en: WorkingDir
zh-cn: The directory where the playbook is run.
Type: String
Default: /root/ansible-workspace
check:
Label:
en: Check
zh-cn: Runs an Ansible execution check using the check parameter.
Type: Boolean
Default: true
extraVariables:
Type: String
Label:
en: ExtraVariables
zh-cn: The extra variables that are passed to Ansible at runtime.
Description:
en: 'Enter a space-separated list of key-value pairs. For example: color=red flavor=lime'
zh-cn: 'Enter a space-separated list of key-value pairs. For example: color=red flavor=lime'
Default: color=red
AllowedPattern: ^$|^\w+\=\S+(\s\w+\=\S+)*$
verbose:
Type: String
Label:
en: Verbose
zh-cn: The verbosity level for logging the playbook execution.
Description:
en: 'Specify -v for low verbosity, -vv or -vvv for medium verbosity, and -vvvv for the debug level.'
zh-cn: 'Specify -v for low verbosity, -vv or -vvv for medium verbosity, and -vvvv for the debug level.'
AllowedValues:
- '-v'
- '-vv'
- '-vvv'
- '-vvvv'
Default: '-v'
rateControl:
Label:
en: RateControl
zh-cn: The concurrency rate of the task execution.
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: The RAM role that OOS assumes.
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: Get ECS instances.
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: Apply the specified playbook.
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: Configure parameters
en: Configure parameters
- Parameters:
- regionId
- targets
Label:
default:
zh-cn: Select instances
en: Select instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: Advanced options
en: Advanced options