@@ -113,6 +113,12 @@ func Run(flags *aoflags.AnsibleOperatorFlags) error {
113
113
options .Namespace = metav1 .NamespaceAll
114
114
}
115
115
116
+ err = setAnsibleEnvVars (flags )
117
+ if err != nil {
118
+ log .Error (err , "Failed to set environment variable." )
119
+ return err
120
+ }
121
+
116
122
// Create a new manager to provide shared dependencies and start components
117
123
mgr , err := manager .New (cfg , options )
118
124
if err != nil {
@@ -291,3 +297,23 @@ func getAnsibleDebugLog() bool {
291
297
}
292
298
return val
293
299
}
300
+
301
+ // setAnsibleEnvVars will set environment variables based on CLI flags
302
+ func setAnsibleEnvVars (f * aoflags.AnsibleOperatorFlags ) error {
303
+ if len (f .AnsibleRolesPath ) > 0 {
304
+ if err := os .Setenv (aoflags .AnsibleRolesPathEnvVar , f .AnsibleRolesPath ); err != nil {
305
+ return fmt .Errorf ("failed to set environment variable %s: %v" , aoflags .AnsibleRolesPathEnvVar , err )
306
+ }
307
+ log .Info ("Set the environment variable" , "envVar" , aoflags .AnsibleRolesPathEnvVar ,
308
+ "value" , f .AnsibleRolesPath )
309
+ }
310
+
311
+ if len (f .AnsibleCollectionsPath ) > 0 {
312
+ if err := os .Setenv (aoflags .AnsibleCollectionsPathEnvVar , f .AnsibleCollectionsPath ); err != nil {
313
+ return fmt .Errorf ("failed to set environment variable %s: %v" , aoflags .AnsibleCollectionsPathEnvVar , err )
314
+ }
315
+ log .Info ("Set the environment variable" , "envVar" , aoflags .AnsibleCollectionsPathEnvVar ,
316
+ "value" , f .AnsibleCollectionsPath )
317
+ }
318
+ return nil
319
+ }
0 commit comments