24
24
import com .rundeck .plugins .ansible .ansible .AnsibleInventoryList ;
25
25
import com .rundeck .plugins .ansible .ansible .AnsibleRunner ;
26
26
import com .rundeck .plugins .ansible .ansible .InventoryList ;
27
- import com .rundeck .plugins .ansible .ansible .PropertyResolver ;
28
27
import com .rundeck .plugins .ansible .util .VaultPrompt ;
28
+ import lombok .Setter ;
29
29
import org .rundeck .app .spi .Services ;
30
30
import org .rundeck .storage .api .PathUtil ;
31
31
import org .rundeck .storage .api .StorageException ;
32
32
import org .yaml .snakeyaml .LoaderOptions ;
33
33
import org .yaml .snakeyaml .Yaml ;
34
34
import org .yaml .snakeyaml .constructor .SafeConstructor ;
35
+ import org .yaml .snakeyaml .error .YAMLException ;
35
36
36
37
import java .io .BufferedReader ;
37
38
import java .io .ByteArrayOutputStream ;
46
47
import java .nio .file .SimpleFileVisitor ;
47
48
import java .nio .file .attribute .BasicFileAttributes ;
48
49
import java .util .ArrayList ;
50
+ import java .util .Collections ;
49
51
import java .util .HashMap ;
50
52
import java .util .HashSet ;
51
53
import java .util .List ;
@@ -61,8 +63,10 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun
61
63
public static final String HOST_TPL_J2 = "host-tpl.j2" ;
62
64
public static final String GATHER_HOSTS_YML = "gather-hosts.yml" ;
63
65
66
+ @ Setter
64
67
private Framework framework ;
65
68
69
+ @ Setter
66
70
private Services services ;
67
71
68
72
private String project ;
@@ -73,6 +77,7 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun
73
77
74
78
private String inventory ;
75
79
private boolean gatherFacts ;
80
+ @ Setter
76
81
private Integer yamlDataSize ;
77
82
private boolean ignoreErrors = false ;
78
83
private String limit ;
@@ -120,17 +125,14 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun
120
125
121
126
protected boolean encryptExtraVars = false ;
122
127
128
+ @ Setter
123
129
private AnsibleInventoryList .AnsibleInventoryListBuilder ansibleInventoryListBuilder = null ;
124
130
125
131
public AnsibleResourceModelSource (final Framework framework ) {
126
132
this .framework = framework ;
127
133
}
128
134
129
- public void setAnsibleInventoryListBuilder (AnsibleInventoryList .AnsibleInventoryListBuilder builder ) {
130
- this .ansibleInventoryListBuilder = builder ;
131
- }
132
-
133
- private static String resolveProperty (
135
+ private static String resolveProperty (
134
136
final String attribute ,
135
137
final String defaultValue ,
136
138
final Properties configuration ,
@@ -169,11 +171,7 @@ private static Boolean skipVar(final String hostVar, final List<String> varList)
169
171
return false ;
170
172
}
171
173
172
- public void setServices (Services services ) {
173
- this .services = services ;
174
- }
175
-
176
- public void configure (Properties configuration ) throws ConfigurationException {
174
+ public void configure (Properties configuration ) throws ConfigurationException {
177
175
178
176
project = configuration .getProperty ("project" );
179
177
configDataContext = new HashMap <String , Map <String , String >>();
@@ -701,7 +699,13 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB
701
699
702
700
String listResp = getNodesFromInventory (runnerBuilder );
703
701
704
- Map <String , Object > allInventory = yaml .load (listResp );
702
+ Map <String , Object > allInventory ;
703
+ try {
704
+ allInventory = yaml .load (listResp );
705
+ } catch (YAMLException e ) {
706
+ throw new ResourceModelSourceException ("Cannot load yaml data coming from Ansible: " + e .getMessage (), e );
707
+ }
708
+
705
709
Map <String , Object > all = InventoryList .getValue (allInventory , ALL );
706
710
Map <String , Object > children = InventoryList .getValue (all , CHILDREN );
707
711
@@ -836,23 +840,4 @@ public List<String> listSecretsPathResourceModel(Map<String, Object> configurati
836
840
837
841
}
838
842
839
- /**
840
- *
841
- * @param value parameter from gui
842
- * @param paramName parameter name
843
- * @return an integer value
844
- * @throws ConfigurationException
845
- */
846
- private Integer getIntegerValue (String value , String paramName ) throws ConfigurationException {
847
- if (value == null ) {
848
- throw new ConfigurationException ("Value cannot be null for parameter: " + paramName );
849
- }
850
-
851
- try {
852
- return Integer .parseInt (value );
853
- } catch (NumberFormatException e ) {
854
- throw new ConfigurationException ("Error parsing " + paramName + " as integer: " + e .getMessage (), e );
855
- }
856
- }
857
-
858
843
}
0 commit comments