1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the php-ansible package. |
4
|
|
|
* |
5
|
|
|
* (c) Marc Aschmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Asm\Ansible\Command; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class AnsibleGalaxy |
15
|
|
|
* |
16
|
|
|
* @package Asm\Ansible\Command |
17
|
|
|
* @author Marc Aschmann <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class AnsibleGalaxy extends AbstractAnsibleCommand implements AnsibleGalaxyInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Executes a command process. |
24
|
|
|
* Returns either exitcode or string output if no callback is given. |
25
|
|
|
* |
26
|
|
|
* @param null $callback |
27
|
|
|
* @return integer|string |
28
|
|
|
*/ |
29
|
|
|
public function execute($callback = null) |
30
|
|
|
{ |
31
|
|
|
return $this->runProcess($callback); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initialize a new role with base structure. |
36
|
|
|
* |
37
|
|
|
* @param string $roleName |
38
|
|
|
* @return AnsibleGalaxyInterface |
39
|
|
|
*/ |
40
|
|
|
public function init(string $roleName): AnsibleGalaxyInterface |
41
|
|
|
{ |
42
|
|
|
$this |
43
|
|
|
->addBaseoption('init') |
44
|
|
|
->addBaseoption($roleName); |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $role |
51
|
|
|
* @param string $version |
52
|
|
|
* @return AnsibleGalaxyInterface |
53
|
|
|
*/ |
54
|
|
|
public function info(string $role, string $version = ''): AnsibleGalaxyInterface |
55
|
|
|
{ |
56
|
|
|
if ('' !== $version) { |
57
|
|
|
$role = $role . ',' . $version; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this |
61
|
|
|
->addBaseoption('info') |
62
|
|
|
->addBaseoption($role); |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Install packages. |
69
|
|
|
* |
70
|
|
|
* If you are unsure whether the role(s) is already installed, |
71
|
|
|
* either check first or use the "force" option. |
72
|
|
|
* |
73
|
|
|
* @param string|array $roles role_name(s)[,version] | scm+role_repo_url[,version] |
74
|
|
|
* @return AnsibleGalaxyInterface |
75
|
|
|
*/ |
76
|
|
|
public function install($roles = ''): AnsibleGalaxyInterface |
77
|
|
|
{ |
78
|
|
|
$roles = $this->checkParam($roles, ' '); |
79
|
|
|
|
80
|
|
|
$this->addBaseoption('install'); |
81
|
|
|
|
82
|
|
|
if ('' !== $roles) { |
83
|
|
|
$this->addBaseoption($roles); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get a list of installed modules. |
91
|
|
|
* |
92
|
|
|
* @param string $roleName |
93
|
|
|
* @return AnsibleGalaxyInterface |
94
|
|
|
*/ |
95
|
|
|
public function modulelist(string $roleName = ''): AnsibleGalaxyInterface |
96
|
|
|
{ |
97
|
|
|
$this->addBaseoption('list'); |
98
|
|
|
|
99
|
|
|
if ('' !== $roleName) { |
100
|
|
|
$this->addBaseoption($roleName); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Add package(s) |
108
|
|
|
* |
109
|
|
|
* @param string|array $roles |
110
|
|
|
* @return AnsibleGalaxyInterface |
111
|
|
|
*/ |
112
|
|
|
public function remove($roles = ''): AnsibleGalaxyInterface |
113
|
|
|
{ |
114
|
|
|
$roles = $this->checkParam($roles, ' '); |
115
|
|
|
|
116
|
|
|
$this |
117
|
|
|
->addBaseoption('remove') |
118
|
|
|
->addBaseoption($roles); |
119
|
|
|
|
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Show general or specific help. |
125
|
|
|
* |
126
|
|
|
* @return AnsibleGalaxyInterface |
127
|
|
|
*/ |
128
|
|
|
public function help(): AnsibleGalaxyInterface |
129
|
|
|
{ |
130
|
|
|
$this->addParameter('--help'); |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* The path in which the skeleton role will be created. |
137
|
|
|
* The default is the current working directory. |
138
|
|
|
* |
139
|
|
|
* @param string $path |
140
|
|
|
* @return AnsibleGalaxyInterface |
141
|
|
|
*/ |
142
|
|
|
public function initPath(string $path = ''): AnsibleGalaxyInterface |
143
|
|
|
{ |
144
|
|
|
$this->addOption('--init-path', $path); |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Don't query the galaxy API when creating roles. |
151
|
|
|
* |
152
|
|
|
* @return AnsibleGalaxyInterface |
153
|
|
|
*/ |
154
|
|
|
public function offline(): AnsibleGalaxyInterface |
155
|
|
|
{ |
156
|
|
|
$this->addParameter('--offline'); |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* The API server destination. |
163
|
|
|
* |
164
|
|
|
* @param string $apiServer |
165
|
|
|
* @return AnsibleGalaxyInterface |
166
|
|
|
*/ |
167
|
|
|
public function server(string $apiServer): AnsibleGalaxyInterface |
168
|
|
|
{ |
169
|
|
|
$this->addOption('--server', $apiServer); |
170
|
|
|
|
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Force overwriting an existing role. |
176
|
|
|
* |
177
|
|
|
* @return AnsibleGalaxyInterface |
178
|
|
|
*/ |
179
|
|
|
public function force(): AnsibleGalaxyInterface |
180
|
|
|
{ |
181
|
|
|
$this->addParameter('--force'); |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* A file containing a list of roles to be imported. |
188
|
|
|
* |
189
|
|
|
* @param string $roleFile FILE |
190
|
|
|
* @return AnsibleGalaxyInterface |
191
|
|
|
*/ |
192
|
|
|
public function roleFile(string $roleFile): AnsibleGalaxyInterface |
193
|
|
|
{ |
194
|
|
|
$this->addOption('--role-file', $roleFile); |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* The path to the directory containing your roles. |
201
|
|
|
* |
202
|
|
|
* The default is the roles_path configured in your |
203
|
|
|
* ansible.cfg file (/etc/ansible/roles if not configured). |
204
|
|
|
* |
205
|
|
|
* @param string $rolesPath |
206
|
|
|
* @return AnsibleGalaxyInterface |
207
|
|
|
*/ |
208
|
|
|
public function rolesPath(string $rolesPath): AnsibleGalaxyInterface |
209
|
|
|
{ |
210
|
|
|
$this->addOption('--roles-path', $rolesPath); |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Ignore errors and continue with the next specified role. |
217
|
|
|
* |
218
|
|
|
* @return AnsibleGalaxyInterface |
219
|
|
|
*/ |
220
|
|
|
public function ignoreErrors(): AnsibleGalaxyInterface |
221
|
|
|
{ |
222
|
|
|
$this->addParameter('--ignore-errors'); |
223
|
|
|
|
224
|
|
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Don't download roles listed as dependencies. |
229
|
|
|
* |
230
|
|
|
* @return AnsibleGalaxyInterface |
231
|
|
|
*/ |
232
|
|
|
public function noDeps(): AnsibleGalaxyInterface |
233
|
|
|
{ |
234
|
|
|
$this->addParameter('--no-deps'); |
235
|
|
|
|
236
|
|
|
return $this; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Get parameter string which will be used to call ansible. |
241
|
|
|
* |
242
|
|
|
* @param bool $asArray |
243
|
|
|
* @return string|array |
244
|
|
|
*/ |
245
|
|
|
public function getCommandlineArguments(bool $asArray = true) |
246
|
|
|
{ |
247
|
|
|
return $this->prepareArguments($asArray); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|