@@ -56,7 +56,8 @@ def generate_site_file_yaml(user_roles):
5656 return site_yaml
5757
5858
59- def write_worker_host_vars (* , cluster_id , worker , worker_count , log ):
59+ def get_worker_host_vars (* , cluster_id , worker , worker_count ):
60+ write_host_vars_remote = []
6061 for worker_number in range (worker .get ('count' , 1 )):
6162 name = WORKER_IDENTIFIER (cluster_id = cluster_id , additional = worker_count + worker_number )
6263 write_volumes = []
@@ -73,12 +74,14 @@ def write_worker_host_vars(*, cluster_id, worker, worker_count, log):
7374 else :
7475 volume_name = volume ["name" ]
7576 write_volumes .append ({** volume , "name" : volume_name })
76- write_yaml ( os . path . join ( aRP . HOST_VARS_FOLDER , f" { name } .yaml" ),
77- {"volumes" : write_volumes },
78- log )
77+ write_host_vars_remote . append (
78+ ( {"volumes" : write_volumes }, os . path . join ( aRP . HOST_VARS_FOLDER_REMOTE , f" { name } .yaml" )))
79+ return write_host_vars_remote
7980
8081
81- def write_worker_vars (* , provider , configuration , cluster_id , worker , worker_count , log ):
82+ def get_worker_vars (* , provider , configuration , cluster_id , worker ,
83+ worker_count ): # pylint: disable-msg=too-many-locals
84+ write_worker_vars_remote = []
8285 flavor_dict = provider .create_flavor_dict (flavor = worker ["type" ])
8386 name = WORKER_IDENTIFIER (cluster_id = cluster_id ,
8487 additional = f"[{ worker_count } -{ worker_count + worker .get ('count' , 1 ) - 1 } ]" )
@@ -91,7 +94,8 @@ def write_worker_vars(*, provider, configuration, cluster_id, worker, worker_cou
9194 "network" : configuration ["network" ], "flavor" : flavor_dict ,
9295 "gateway_ip" : configuration ["private_v4" ],
9396 "cloud_identifier" : configuration ["cloud_identifier" ],
94- "on_demand" : worker .get ("onDemand" , True ), "state" : "CLOUD" ,
97+ "on_demand" : worker .get ("onDemand" , True ),
98+ "state" : "CLOUD" ,
9599 "partitions" : partitions ,
96100 "boot_volume" : worker .get ("bootVolume" , configuration .get ("bootVolume" , {})),
97101 "meta" : mergedeep .merge ({}, worker .get ("meta" , {}), configuration .get ("meta" , {})),
@@ -107,15 +111,15 @@ def write_worker_vars(*, provider, configuration, cluster_id, worker, worker_cou
107111 worker_dict ["features" ] = features
108112
109113 pass_through (configuration , worker_dict , "waitForServices" , "wait_for_services" )
110- write_yaml ( os .path .join (aRP .GROUP_VARS_FOLDER , f"{ group_name } .yaml" ), worker_dict , log )
114+ write_worker_vars_remote . append (( worker_dict , os .path .join (aRP .GROUP_VARS_FOLDER_REMOTE , f"{ group_name } .yaml" )) )
111115 if worker_dict ["on_demand" ]: # not on demand instances host_vars are created in create
112- write_worker_host_vars (cluster_id = cluster_id , worker = worker , worker_count = worker_count ,
113- log = log )
116+ write_worker_vars_remote = write_worker_vars_remote + get_worker_host_vars (cluster_id = cluster_id , worker = worker ,
117+ worker_count = worker_count )
114118 worker_count += worker .get ('count' , 1 )
115- return worker_count
119+ return worker_count , write_worker_vars_remote
116120
117121
118- def write_vpn_var (* , provider , configuration , cluster_id , vpngtw , vpn_count , log ):
122+ def get_vpn_var (* , provider , configuration , cluster_id , vpngtw , vpn_count ):
119123 name = VPNGTW_IDENTIFIER (cluster_id = cluster_id , additional = f"{ vpn_count } " )
120124 wireguard_ip = f"10.0.0.{ vpn_count + 2 } " # skipping 0 and 1 (master)
121125 vpn_count += 1
@@ -131,10 +135,10 @@ def write_vpn_var(*, provider, configuration, cluster_id, vpngtw, vpn_count, log
131135 if configuration .get ("wireguard_peer" ):
132136 vpngtw_dict ["wireguard" ] = {"ip" : wireguard_ip , "peer" : configuration .get ("wireguard_peer" )}
133137 pass_through (configuration , vpngtw_dict , "waitForServices" , "wait_for_services" )
134- write_yaml ( os .path .join (aRP .HOST_VARS_FOLDER , f"{ name } .yaml" ), vpngtw_dict , log )
138+ return vpngtw_dict , os .path .join (aRP .HOST_VARS_FOLDER_REMOTE , f"{ name } .yaml" )
135139
136140
137- def write_master_var (provider , configuration , cluster_id , log ):
141+ def get_master_var (provider , configuration , cluster_id ):
138142 master = configuration ["masterInstance" ]
139143 name = MASTER_IDENTIFIER (cluster_id = cluster_id )
140144 flavor_dict = provider .create_flavor_dict (flavor = master ["type" ])
@@ -152,10 +156,10 @@ def write_master_var(provider, configuration, cluster_id, log):
152156 if configuration .get ("wireguard_peer" ):
153157 master_dict ["wireguard" ] = {"ip" : "10.0.0.1" , "peer" : configuration .get ("wireguard_peer" )}
154158 pass_through (configuration , master_dict , "waitForServices" , "wait_for_services" )
155- write_yaml ( os .path .join (aRP .GROUP_VARS_FOLDER , "master.yaml" ), master_dict , log )
159+ return master_dict , os .path .join (aRP .GROUP_VARS_FOLDER_REMOTE , "master.yaml" )
156160
157161
158- def write_host_and_group_vars (configurations , providers , cluster_id , log ):
162+ def get_host_and_group_vars (configurations , providers , cluster_id , log ):
159163 """
160164 Filters unnecessary information
161165 @param log:
@@ -167,17 +171,21 @@ def write_host_and_group_vars(configurations, providers, cluster_id, log):
167171 log .info ("Generating instances file..." )
168172 worker_count = 0
169173 vpn_count = 0
174+ write_remote = []
170175 for configuration , provider in zip (configurations , providers ): # pylint: disable=too-many-nested-blocks
171176 for worker in configuration .get ("workerInstances" , []):
172- worker_count = write_worker_vars (provider = provider , configuration = configuration , cluster_id = cluster_id ,
173- worker = worker , worker_count = worker_count , log = log )
174-
177+ worker_count , write_worker_vars_remote = get_worker_vars (provider = provider , configuration = configuration ,
178+ cluster_id = cluster_id ,
179+ worker = worker , worker_count = worker_count )
180+ write_remote = write_remote + write_worker_vars_remote
175181 vpngtw = configuration .get ("vpnInstance" )
176182 if vpngtw :
177- write_vpn_var (provider = provider , configuration = configuration , cluster_id = cluster_id , vpngtw = vpngtw ,
178- vpn_count = vpn_count , log = log )
183+ write_remote .append (
184+ get_vpn_var (provider = provider , configuration = configuration , cluster_id = cluster_id , vpngtw = vpngtw ,
185+ vpn_count = vpn_count ))
179186 else :
180- write_master_var (provider , configuration , cluster_id , log )
187+ write_remote .append (get_master_var (provider , configuration , cluster_id ))
188+ return write_remote
181189
182190
183191def pass_through (dict_from , dict_to , key_from , key_to = None ):
@@ -361,6 +369,8 @@ def write_yaml(path, generated_yaml, log, alias=False):
361369 @param log:
362370 @param alias:
363371 @return:
372+ TODO: This method should be moved to a different file as it is no longer used here but at other places
373+ which are not related to ansible_configurator
364374 """
365375 log .debug ("Writing yaml %s" , path )
366376
@@ -398,21 +408,19 @@ def configure_ansible_yaml(providers, configurations, cluster_id, log):
398408 @return:
399409 """
400410 log .info ("Writing ansible files..." )
401- alias = configurations [0 ].get ("aliasDumper" , False )
402411 user_roles = configurations [0 ].get ("userRoles" , [])
403412 default_user = providers [0 ].cloud_specification ["auth" ].get ("username" , configurations [0 ].get ("sshUser" , "Ubuntu" ))
404413 add_wireguard_peers (configurations )
405- for path , generated_yaml in [
406- (aRP .WORKER_SPECIFICATION_FILE , generate_worker_specification_file_yaml (configurations , log )), (
407- aRP .COMMONS_CONFIG_FILE ,
408- generate_common_configuration_yaml (cidrs = get_cidrs (configurations ), configurations = configurations ,
409- cluster_id = cluster_id , ssh_user = configurations [0 ]["sshUser" ],
410- default_user = default_user , log = log )), (aRP .HOSTS_CONFIG_FILE ,
411- generate_ansible_hosts_yaml (
412- configurations [0 ][
413- "sshUser" ],
414- configurations ,
415- cluster_id , log )),
416- (aRP .SITE_CONFIG_FILE , generate_site_file_yaml (user_roles ))]:
417- write_yaml (path , generated_yaml , log , alias )
418- write_host_and_group_vars (configurations , providers , cluster_id , log ) # writing included in method
414+ write_remote = []
415+ for write_remote_tuple in [
416+ (generate_worker_specification_file_yaml (configurations , log ), aRP .WORKER_SPECIFICATION_FILE_REMOTE ),
417+ (generate_common_configuration_yaml (cidrs = get_cidrs (configurations ), configurations = configurations ,
418+ cluster_id = cluster_id , ssh_user = configurations [0 ]["sshUser" ],
419+ default_user = default_user , log = log ), aRP .COMMONS_CONFIG_FILE_REMOTE ),
420+ (generate_ansible_hosts_yaml (configurations [0 ]["sshUser" ], configurations , cluster_id , log ),
421+ aRP .HOSTS_CONFIG_FILE_REMOTE ),
422+ (generate_site_file_yaml (user_roles ), aRP .SITE_CONFIG_FILE_REMOTE )]:
423+ write_remote .append (write_remote_tuple )
424+ write_remote = write_remote + get_host_and_group_vars (configurations , providers , cluster_id ,
425+ log )
426+ return write_remote
0 commit comments