1
1
package com .rundeck .plugins .ansible .plugin ;
2
2
3
3
import com .dtolabs .rundeck .core .common .Framework ;
4
- import com .dtolabs .rundeck .core .common .INodeEntry ;
5
4
import com .dtolabs .rundeck .core .common .INodeSet ;
6
5
import com .dtolabs .rundeck .core .common .NodeEntryImpl ;
7
6
import com .dtolabs .rundeck .core .common .NodeSetImpl ;
29
28
import com .rundeck .plugins .ansible .util .VaultPrompt ;
30
29
import lombok .Setter ;
31
30
import lombok .extern .slf4j .Slf4j ;
31
+ import org .apache .commons .lang .StringUtils ;
32
32
import org .rundeck .app .spi .Services ;
33
33
import org .rundeck .storage .api .PathUtil ;
34
34
import org .rundeck .storage .api .StorageException ;
50
50
import java .nio .file .SimpleFileVisitor ;
51
51
import java .nio .file .attribute .BasicFileAttributes ;
52
52
import java .util .ArrayList ;
53
- import java .util .Arrays ;
54
53
import java .util .HashMap ;
55
54
import java .util .HashSet ;
56
55
import java .util .List ;
57
56
import java .util .Map ;
58
57
import java .util .Map .Entry ;
59
58
import java .util .Properties ;
60
59
import java .util .Set ;
61
- import java .util .stream .Collectors ;
62
60
61
+ import static com .rundeck .plugins .ansible .ansible .AnsibleDescribable .ANSIBLE_YAML_DATA_SIZE ;
62
+ import static com .rundeck .plugins .ansible .ansible .AnsibleDescribable .ANSIBLE_YAML_MAX_ALIASES ;
63
63
import static com .rundeck .plugins .ansible .ansible .InventoryList .ALL ;
64
64
import static com .rundeck .plugins .ansible .ansible .InventoryList .CHILDREN ;
65
65
import static com .rundeck .plugins .ansible .ansible .InventoryList .HOSTS ;
@@ -85,8 +85,6 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun
85
85
86
86
private String inventory ;
87
87
private boolean gatherFacts ;
88
- @ Setter
89
- private Integer yamlDataSize ;
90
88
private boolean ignoreErrors = false ;
91
89
private String limit ;
92
90
private String ignoreTagPrefix ;
@@ -135,6 +133,11 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun
135
133
136
134
protected String customTmpDirPath ;
137
135
136
+ @ Setter
137
+ private Integer yamlDataSize ;
138
+ @ Setter
139
+ private Integer yamlMaxAliases ;
140
+
138
141
@ Setter
139
142
private AnsibleInventoryList .AnsibleInventoryListBuilder ansibleInventoryListBuilder = null ;
140
143
@@ -144,7 +147,7 @@ public AnsibleResourceModelSource(final Framework framework) {
144
147
this .framework = framework ;
145
148
}
146
149
147
- private static String resolveProperty (
150
+ private static String resolveProperty (
148
151
final String attribute ,
149
152
final String defaultValue ,
150
153
final Properties configuration ,
@@ -197,8 +200,6 @@ public void configure(Properties configuration) throws ConfigurationException {
197
200
gatherFacts = "true" .equals (resolveProperty (AnsibleDescribable .ANSIBLE_GATHER_FACTS ,null ,configuration ,executionDataContext ));
198
201
ignoreErrors = "true" .equals (resolveProperty (AnsibleDescribable .ANSIBLE_IGNORE_ERRORS ,null ,configuration ,executionDataContext ));
199
202
200
- yamlDataSize = resolveIntProperty (AnsibleDescribable .ANSIBLE_YAML_DATA_SIZE ,10 , configuration , executionDataContext );
201
-
202
203
limit = (String ) resolveProperty (AnsibleDescribable .ANSIBLE_LIMIT ,null ,configuration ,executionDataContext );
203
204
ignoreTagPrefix = (String ) resolveProperty (AnsibleDescribable .ANSIBLE_IGNORE_TAGS ,null ,configuration ,executionDataContext );
204
205
@@ -254,6 +255,10 @@ public void configure(Properties configuration) throws ConfigurationException {
254
255
255
256
encryptExtraVars = "true" .equals (resolveProperty (AnsibleDescribable .ANSIBLE_ENCRYPT_EXTRA_VARS ,"false" ,configuration ,executionDataContext ));
256
257
258
+ // Inventory Yaml
259
+ yamlDataSize = resolveIntProperty (ANSIBLE_YAML_DATA_SIZE ,10 , configuration , executionDataContext );
260
+ yamlMaxAliases = resolveIntProperty (ANSIBLE_YAML_MAX_ALIASES ,1000 , configuration , executionDataContext );
261
+
257
262
}
258
263
259
264
public AnsibleRunner .AnsibleRunnerBuilder buildAnsibleRunner () throws ResourceModelSourceException {
@@ -708,10 +713,14 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB
708
713
LoaderOptions snakeOptions = new LoaderOptions ();
709
714
// max inventory file size allowed to 10mb
710
715
snakeOptions .setCodePointLimit (codePointLimit );
716
+ // max aliases. Default value is 1000
717
+ snakeOptions .setMaxAliasesForCollections (yamlMaxAliases );
711
718
Yaml yaml = new Yaml (new SafeConstructor (snakeOptions ));
712
719
713
720
String listResp = getNodesFromInventory (runnerBuilder );
714
721
722
+ validateAliases (listResp );
723
+
715
724
Map <String , Object > allInventory ;
716
725
try {
717
726
allInventory = yaml .load (listResp );
@@ -971,4 +980,15 @@ private boolean isTagMapValid(Map<String, Object> tagMap, String tagName) {
971
980
return true ;
972
981
}
973
982
983
+ /**
984
+ * Validates whether the YAML content contains aliases that exceed the maximum allowed.
985
+ * @param content String yaml
986
+ */
987
+ public void validateAliases (String content ) {
988
+ int totalAliases = StringUtils .countMatches (content , ": *" );
989
+ if (totalAliases > yamlMaxAliases ) {
990
+ log .warn ("The yaml inventory received has {} aliases and the maximum allowed is {}." , totalAliases , yamlMaxAliases );
991
+ }
992
+ }
993
+
974
994
}
0 commit comments