38
38
- The location can be a UNIX System Services (USS) file,
39
39
PS (sequential data set), member of a PDS or PDSE, PDS, PDSE.
40
40
- The USS file must be an absolute pathname.
41
+ - Generation data set (GDS) relative name of generation already
42
+ created. C(e.g. SOME.CREATION(-1).)
41
43
type: str
42
44
aliases: [ path, destfile, name ]
43
45
required: true
110
112
- When set to C(true), the module creates a backup file or data set.
111
113
- The backup file name will be returned on either success or failure of
112
114
module execution such that data can be retrieved.
115
+ - Use generation data set (GDS) relative positive name. C(e.g. SOME.CREATION(+1))
113
116
required: false
114
117
type: bool
115
118
default: false
279
282
marker_begin: "Begin Ansible Block Insertion 2"
280
283
marker_end: "End Ansible Block Insertion 2"
281
284
block: "{{ CONTENT }}"
285
+
286
+ - name: Add a block to a gds
287
+ zos_blockinfile:
288
+ src: TEST.SOME.CREATION(0)
289
+ insertafter: EOF
290
+ block: "{{ CONTENT }}"
291
+
292
+ - name: Add a block to dataset and backup in a new generation of gds
293
+ zos_blockinfile:
294
+ src: SOME.CREATION.TEST
295
+ insertbefore: BOF
296
+ backup: True
297
+ backup_name: CREATION.GDS(+1)
298
+ block: "{{ CONTENT }}"
282
299
'''
283
300
284
301
RETURN = r"""
@@ -456,13 +473,44 @@ def quotedString(string):
456
473
457
474
458
475
def quotedString_double_quotes (string ):
476
+ """Deletes the quote mark on strings.
477
+
478
+ Parameters
479
+ ----------
480
+ string : str
481
+ String to modify quote marks from.
482
+
483
+ Returns
484
+ -------
485
+ str
486
+ String scaping the quote marks.
487
+ """
459
488
# add escape if string was quoted
460
489
if not isinstance (string , str ):
461
490
return string
462
491
return string .replace ('"' , '\\ "' )
463
492
464
493
465
494
def check_double_quotes (marker , ins_bef , ins_aft , block ):
495
+ """Verify the content of strings to determine if double
496
+ quotes are in the string.
497
+
498
+ Parameters
499
+ ----------
500
+ marker : str
501
+ String to verify quote marks from.
502
+ ins_bef : str
503
+ String to verify quote marks from.
504
+ ins_aft : str
505
+ String to verify quote marks from.
506
+ block : str
507
+ String to verify quote marks from.
508
+
509
+ Returns
510
+ -------
511
+ bool
512
+ If any string contain double quotes.
513
+ """
466
514
if marker :
467
515
if '"' in marker :
468
516
return True
@@ -479,6 +527,42 @@ def check_double_quotes(marker, ins_bef, ins_aft, block):
479
527
480
528
481
529
def execute_dmod (src , block , marker , force , encoding , state , module , ins_bef = None , ins_aft = None ):
530
+ """Execute in terminal dmod command directly.
531
+
532
+ Parameters
533
+ ----------
534
+ src : str
535
+ The z/OS USS file or data set to modify.
536
+ block : str
537
+ The block to insert/replace into the src.
538
+ marker : str
539
+ The block will be inserted/updated with the markers.
540
+ force : bool
541
+ If not empty passes True option to dmod cmd.
542
+ encoding : str
543
+ Encoding of the src.
544
+ state : bool
545
+ Determine if will add or delete the block.
546
+ module : obj
547
+ Object to execute the command.
548
+ ins_bef : str
549
+ Insert the block before matching '*regex*' pattern or BOF.
550
+ choices:
551
+ - BOF
552
+ - '*regex*'
553
+ ins_aft : str
554
+ Insert the block after matching '*regex*' pattern or EOF.
555
+ choices:
556
+ - EOF
557
+ - '*regex*'
558
+
559
+ Returns
560
+ -------
561
+ int
562
+ RC of the execution of the command.
563
+ cmd
564
+ Command executed.
565
+ """
482
566
block = block .replace ('"' , '\\ "' )
483
567
force = "-f" if force else ""
484
568
encoding = "-c {0}" .format (encoding ) if encoding else ""
@@ -505,6 +589,18 @@ def execute_dmod(src, block, marker, force, encoding, state, module, ins_bef=Non
505
589
506
590
507
591
def clean_command (cmd ):
592
+ """Deletes escaped characters from the str.
593
+
594
+ Parameters
595
+ ----------
596
+ cmd : str
597
+ Command to clean any escaped characters.
598
+
599
+ Returns
600
+ -------
601
+ str
602
+ Command without escaped characters.
603
+ """
508
604
cmd = cmd .replace ('/c\\ \\ ' , '' )
509
605
cmd = cmd .replace ('/a\\ \\ ' , '' , )
510
606
cmd = cmd .replace ('/i\\ \\ ' , '' , )
@@ -667,18 +763,25 @@ def main():
667
763
marker = "{0}\\ n{1}\\ n{2}" .format (marker_begin , marker_end , marker )
668
764
block = transformBlock (block , ' ' , indentation )
669
765
# analysis the file type
766
+ if "/" not in src :
767
+ dataset = data_set .MVSDataSet (
768
+ name = src
769
+ )
770
+ src = dataset .name
771
+
772
+ if data_set .DataSet .is_gds_relative_name (src ):
773
+ module .fail_json (msg = "{0} does not exist" .format (src ))
774
+
670
775
ds_utils = data_set .DataSetUtils (src )
671
776
if not ds_utils .exists ():
672
777
message = "{0} does NOT exist" .format (str (src ))
673
778
module .fail_json (msg = message )
674
779
file_type = ds_utils .ds_type ()
675
- if file_type == 'USS' :
676
- file_type = 1
677
- else :
780
+
781
+ if file_type != "USS" :
678
782
if file_type not in DS_TYPE :
679
783
message = "{0} data set type is NOT supported" .format (str (file_type ))
680
784
module .fail_json (msg = message )
681
- file_type = 0
682
785
683
786
return_content = None
684
787
if backup :
@@ -688,7 +791,7 @@ def main():
688
791
if isinstance (backup , bool ):
689
792
backup = None
690
793
try :
691
- if file_type :
794
+ if file_type == "USS" :
692
795
result ['backup_name' ] = Backup .uss_file_backup (src , backup_name = backup , compress = False )
693
796
else :
694
797
result ['backup_name' ] = Backup .mvs_file_backup (dsn = src , bk_dsn = backup , tmphlq = tmphlq )
0 commit comments