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