-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::ECS::ApplyAnsiblePlayBook.yml
144 lines (144 loc) · 5.9 KB
/
ACS::ECS::ApplyAnsiblePlayBook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS::ECS::ApplyAnsiblePlayBook
name-zh-cn: 在ECS实例中执行Ansible-playbook
en: 'Run Ansible playbooks on ECS Instance.Only supports CentOS, AliyunLinux and Ubuntu'
zh-cn: 在ECS实例中执行Ansible-playbook,仅支持CentOS,AliyunLinux,Ubuntu类型实例
Parameters:
regionId:
Description:
en: The ID of region
zh-cn: 地域ID
Type: String
Default: '{{ ACS::RegionId }}'
instanceId:
Description:
en: The ID of ECS instance
zh-cn: ECS实例ID
Type: String
sourceType:
Description:
en: The type of playbook storage
zh-cn: playbook存储类型
Type: String
AllowedValues:
- oss
- https
- github
sourcePath:
Description:
en: 'You must specify a URL where the playbook is stored.You can specify the URL in the following formats: https://example.com/playbook.yml'
zh-cn: '您必须指定一个用于存储playbook的URL。您可以采用以下格式指定URL:https://example.com/playbook.yml'
Type: String
playbookFile:
Description:
en: 'The name of playbook to apply. For example: example.yml'
zh-cn: '要执行的playbook的名称,举例:example.yml'
Type: String
tokenInfo:
Type: String
Description:
en: Specify a token to download ansible playbook.It is only required when downloading palybook from GitHub
zh-cn: 指定一个token来下载playbook,只有从GitHub下载时用到
Default: ''
hosts:
Description:
en: The hosts used to execute palybook
zh-cn: 运行执行palybook的hosts
Type: String
Default: /etc/ansible/hosts
installDependencies:
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: '如果设置为True,OOS将从PyPI存储库中安装Ansible及其依赖项,包括Python。如果设置为False,则验证Ansible及其依赖项是否已安装在目标实例上'
Type: Boolean
Default: true
workingDir:
Description:
en: The directory to apply playbook
zh-cn: 执行playbook的目录
Type: String
Default: /root/ansible-workspace
check:
Description:
en: Use the check parameter to perform a dry run of the Ansible execution
zh-cn: 使用check参数检查Ansible的执行
Type: Boolean
Default: true
extraVariables:
Type: String
Description:
en: 'Additional variables to pass to Ansible at runtime. Enter a space separated list of key/value pairs. For example: color=red flavor=lime'
zh-cn: '附带变量在运行时传递给Ansible。输入以空格分隔的键/值对列表。例如:color = red flavour = lime'
Default: color=red
AllowedPattern: ^$|^\w+\=\S+(\s\w+\=\S+)*$
verbose:
Type: String
Description:
en: 'Set the verbosity level for logging Playbook executions. Specify -v for low verbosity, -vv or –vvv for medium verbosity, and -vvvv for debug level'
zh-cn: '设置用于记录Playbook执行情况的详细程度。指定-v表示低级别,-vv或–vvv表示中等级别,-vvvv表示调试级别'
AllowedValues:
- '-v'
- '-vv'
- '-vvv'
- '-vvvv'
Default: '-v'
Tasks:
- Name: applyPlaybook
Action: 'ACS::ECS::RunCommand'
Description:
en: Executes the specified playbook on ECS instance
zh-cn: 在ECS实例中执行指定的playbook
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ instanceId }}'
commandType: RunShellScript
commandContent: |-
if [ '{{ installDependencies }}' = 'true' ] ; then
echo "Installing and or updating required tools: Ansible, wget unzip ...." >&2;
if [ -f "/etc/system-release" ] ; then
if cat /etc/system-release|grep -i 'CentOS Linux release' ; then
sudo yum install -y ansible
sudo yum -y install unzip
elif cat /etc/system-release|grep -i '^Ali.*Linux' ; then
sudo yum install -y ansible
sudo yum install -y unzip
else
echo "There was a problem installing or updating the required tools for the document. You can review the log files to help you correct the problem." >&2;
exit 1;
fi
elif cat /etc/issue|grep -i Ubuntu ; then
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install python-pip -y
sudo pip install ansible --upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get install unzip -y
else
echo "There was a problem installing or updating the required tools for the document. You can review the log files to help you correct the problem." >&2
exit 1
fi
fi
echo "Downloading playbook"
acs-plugin-manager --exec -P oosutil --params download_content,{{sourceType}},'{{sourcePath}}',\''{{ tokenInfo }}'\','{{workingDir}}'
echo "Running Ansible in {{workingDir}}"
cd {{workingDir}}
for zip in $(find -iname '*.zip'); do
unzip -o $zip
done
PlaybookFile="{{ playbookFile }}"
if [ ! -f ${PlaybookFile} ] ; then
echo "The specified Playbook file doesn't exist in the downloaded bundle. Please review the relative path and file name." >&2
exit 2
fi
if [ {{ check }} = true ] ; then
ansible-playbook -i "{{ hosts }}" --check -c local -e "{{ extraVariables }}" "{{ verbose }}" ${PlaybookFile}
else
ansible-playbook -i "{{ hosts }}" -c local -e "{{ extraVariables }}" "{{ verbose }}" ${PlaybookFile}
fi
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Outputs:
commandOutput:
Type: String
Value: '{{ applyPlaybook.commandOutput }}'