this yaml file
standalone_execution: - utpsm_executable: &seid_01 name: tpsm_be rulesfile: [*rulesid_02,*rulesid_01] target_list: [*runid_01] - utpsm_executable: &seid_02 name: tpsm_le rulesfile: [*rulesid_01,*rulesid_02] target_list: [*runid_02,*runid_01] rules_file: - rules_file_id: &rulesid_01 name: tpsm_rulesfile_le hostname: - rules_file_id: &rulesid_02 name: tpsm_rulesfile_be hostname: run_target_platforms: - run_target_id: &runid_01 target_connection_info: run_target_hostname: run_target_username: run_target_password: - run_target_id: &runid_02 target_connection_info: run_target_hostname: run_target_username: run_target_password:
this how parse yaml :
$yaml_input = yaml::xs::loadfile("$input_file"); yaml_lib::parse_yaml($yaml_input);
here function extract parameters
sub parse_yaml_standalone($) { ($yaml_input) = @_; $standalone_exec = $yaml_input->{standalone_execution}; @utpsm_exec = (); @se_exec_name = (); @se_tgt_list = (); @se_rulesfile = (); @se_rules_name = (); @se_run_target_controls = (); @se_run_target_controls = (); $k = 0; $j = 0; $i = 0; $seindex ( @$standalone_exec ) { $utpsm_exec[$k] = $seindex->{utpsm_executable}; $se_exec_name[$k] = $utpsm_exec[$k]->{name}; $se_tgt_list[$k] = $utpsm_exec[$k]->{target_list}; $se_rulesfile[$k] = $utpsm_exec[$k]->{rulesfile}; $rindex ( @{ $se_rulesfile[$k] } ) { $se_rules_name[$j] = $rindex->{name}; $j++; } $run_index ( @{ $se_tgt_list[$k] } ) { $se_run_target_controls[$i] = $run_index->{target_controls}; $se_run_target_types[$i] = $se_run_target_controls[$i]->{run_target_type}; $se_run_target_active[$i] = $se_run_target_controls[$i]->{run_target_active}; $i++; } $k++; } #end of main print "yaml rules: @se_rules_name\n"; }
here, each of target_list element should run every rulesfile element, write following code index = 1, don't desire results, can correct me going wrong ?
my $i = 0; $j = 0; foreach $se_index ( @{$yaml_lib::standalone_exec} ) { print "parent hash : $se_index\n"; foreach $se_runid ( @{ $yaml_lib::se_tgt_list[$i] } ) { $pid = fork(); die "info :: cannot fork new process run target on host : $!" unless defined($pid); # in child processing if ( $pid == 0 ) { $k = 0; $cpid = ($$); print "info :: in run target : child $j process , pid : ($$)\n"; client_lib::client_logs($cpid); #send tpsm exec($i in case) details run targets(by $j) print "child hash $se_index\n"; foreach $rindex ( @{ $yaml_lib::se_rulesfile[$i] } ) { print "rules array : $rindex\n"; client_lib::cap_prints( $client_lib::prints_file, "$yaml_lib::se_rulesfile[$i]\n" ); $k++; } #exit child process exit 0; }
the following code parent waiting child terminate , other checks not displaying due length of question.
please let me know going wrong.
in yaml file, use aliases anchors not defined @ (rulesid_03
, rulesid_04
) or somewhere after alias in yaml stream (rulesid_01
, others). both leads invalid yaml.
moreover, have indentation issues. run_target_platforms
less indented previous keys rules_file
, standalone_execution
. invalid. finally, not want:
- run_target_id: &runid_01 target_connection_info: run_target_hostname: run_target_username: run_target_password:
it list item contains mapping. first key of mapping run_target_id
, corresponding value empty, annotated anchor runid_01
. want make rest of keys in mapping part of child mapping value of first key.
here modified yaml proper anchors, aliases , indentation:
rules_file: - rules_file_id: &rulesid_01 name: tpsm_rulesfile_le hostname: - rules_file_id: &rulesid_02 name: tpsm_rulesfile_be hostname: run_target_platforms: - run_target_id: &runid_01 target_connection_info: run_target_hostname: run_target_username: run_target_password: - run_target_id: &runid_02 target_connection_info: run_target_hostname: run_target_username: run_target_password: standalone_execution: - utpsm_executable: &seid_01 name: tpsm_be rulesfile: [*rulesid_02,*rulesid_01] target_list: [*runid_01] - utpsm_executable: &seid_02 name: tpsm_le rulesfile: [] target_list: [*runid_02]
note removed *rulesid_03,*rulesid_04
because not exist. can of course add content anchors , re-add aliases.
Comments
Post a Comment