Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zos_copy mode is applied to the destination directory, a deviation from the communtiy module behavior. #723

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- zos_copy - Fixed a bug where the module would change the mode for a directory when copying into it the contents of another.
(https://github.com/ansible-collections/ibm_zos_core/pull/723)
19 changes: 19 additions & 0 deletions plugins/module_utils/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,25 @@ def uss_file_tag(self, file_path):
except Exception:
return None

def uss_tag_encoding(self, file_path, tag):
"""Tag the file/directory specified with the given code set.
If `file_path` is a directory, all of the files and subdirectories will
be tagged recursively.

Arguments:
file_path {str} -- Absolute file path to tag.
tag {str} -- Code set to tag the file/directory.

Raises:
TaggingError: When the chtag command fails.
"""
is_dir = os.path.isdir(file_path)

tag_cmd = "chtag -{0}c {1} {2}".format("R" if is_dir else "t", tag, file_path)
rc, out, err = self.module.run_command(tag_cmd)
if rc != 0:
raise TaggingError(file_path, tag, rc, out, err)


class EncodeError(Exception):
def __init__(self, message):
Expand Down
12 changes: 0 additions & 12 deletions plugins/modules/zos_blockinfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@
block: |
MOUNT FILESYSTEM('SOME.DATA.SET') TYPE(ZFS) MODE(READ)
MOUNTPOINT('/tmp/src/somedirectory')

- name: Remove a library as well as surrounding markers
zos_blockinfile:
state: absent
src: SYS1.PARMLIB(PROG00)
marker: "/* {mark} ANSIBLE MANAGED BLOCK FOR SOME.DATA.SET */"

- name: Add ZOAU path to PATH in /etc/profile
zos_blockinfile:
src: /etc/profile
Expand All @@ -210,7 +208,6 @@
ZOAU=/path/to/zoau_dir/bin
export ZOAU
PATH=$ZOAU:$PATH

- name: Insert/Update HTML surrounded by custom markers after <body> line
zos_blockinfile:
path: /var/www/html/index.html
Expand All @@ -219,13 +216,11 @@
block: |
<h1>Welcome to {{ ansible_hostname }}</h1>
<p>Last updated on {{ ansible_date_time.iso8601 }}</p>

- name: Remove HTML as well as surrounding markers
zos_blockinfile:
path: /var/www/html/index.html
state: absent
marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"

- name: Add mappings to /etc/hosts
zos_blockinfile:
path: /etc/hosts
Expand All @@ -236,7 +231,6 @@
- { name: host1, ip: 10.10.1.10 }
- { name: host2, ip: 10.10.1.11 }
- { name: host3, ip: 10.10.1.12 }

- name: Add a code block to a member using a predefined indentation.
zos_blockinfile:
path: SYS1.PARMLIB(BPXPRM00)
Expand Down Expand Up @@ -308,12 +302,10 @@

def transformBlock(block, indentation_char, indentation_spaces):
"""Prepends the specified number of spaces to the block in all lines

Arguments:
block: {str} -- The block text to be transformed.
indentation_char: {str} -- The indentation char to be used.
indentation_spaces: {int} -- Number of times the indentation char to prepend.

Returns:
block: {str} -- The text block after applying the necessary transformations.
"""
Expand All @@ -332,7 +324,6 @@ def present(src, block, marker, ins_aft, ins_bef, encoding, force):
"""Replace a block with the matching regex pattern
Insert a block before/after the matching pattern
Insert a block at BOF/EOF

Arguments:
src: {str} -- The z/OS USS file or data set to modify.
block: {str} -- The block to insert/replace into the src.
Expand All @@ -347,7 +338,6 @@ def present(src, block, marker, ins_aft, ins_bef, encoding, force):
- '*regex*'
encoding: {str} -- Encoding of the src.
force: {str} -- If not empty passes the -f option to dmod cmd.

Returns:
str -- Information in JSON format. keys:
cmd: {str} -- dmod shell command
Expand All @@ -359,13 +349,11 @@ def present(src, block, marker, ins_aft, ins_bef, encoding, force):

def absent(src, marker, encoding, force):
"""Delete blocks with matching regex pattern

Arguments:
src: {str} -- The z/OS USS file or data set to modify.
marker: {str} -- Identifies the block to be removed.
encoding: {str} -- Encoding of the src.
force: {str} -- If not empty passes the -f option to dmod cmd.

Returns:
str -- Information in JSON format. keys:
cmd: {str} -- dmod shell command
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/zos_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,8 @@ def copy_to_uss(
group = self.common_file_args.get("group")
owner = self.common_file_args.get("owner")
if mode is not None:
self.module.set_mode_if_different(dest, mode, False)

if not os.path.isdir(dest):
self.module.set_mode_if_different(dest, mode, False)
if changed_files:
for filepath in changed_files:
self.module.set_mode_if_different(os.path.join(dest, filepath), mode, False)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/modules/test_zos_blockinfile_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,4 +1510,4 @@ def test_ds_not_supported(ansible_zos_module, dstype):
DsNotSupportedHelper(
TEST_INFO["test_ds_block_insertafter_regex"]["test_name"], ansible_zos_module,
TEST_ENV, TEST_INFO["test_uss_block_insertafter_regex"]
)
)