Hi
I would like to add experimental support for z/OS, because python was ported to z/OS https://www.rocketsoftware.com/product-categories/mainframe/python-for-zos
The main obstacle of adding z/OS support into ansible is EBCDIC character set.
I can use raw module out of the box but when using other ansible modules I hit encoding issue.
Ansible modules are transferred via sftp in binary mode. This results in situation that transferred python modules on mainframe have a wrong encoding.
I found a workaround scp_if_ssh = True option in ansible.cfg to enforce scp file transfer that converts file content from Ascii to EBCDIC during transfer to target host however this has a caveat when using copy module to transfer a file from my workstation to mainframe I have to specify checksum of content in EBCDIC otherwise transfer fails with checksum mismatch.
I was looking into source-code https://github.com/ansible/ansible/blob/baf59ccaac267a7eac5dbbea5e439229e686b012/lib/ansible/plugins/action/init.py#L787 self._transfer_data(remote_module_path, module_data) is responsible to transfer data where module_style=‘new’
When I replaced it with
tmp = self._connection._play_context.ssh_transfer_method
self._play_context.ssh_transfer_method = “scp”
display.vvv(“Original transfer method %s enforced transfer method %s to transfer module file %s” % (tmp, self._play_context.ssh_transfer_method, remote_module_path))
self._transfer_data(remote_module_path, module_data)
self._play_context.ssh_transfer_method = tmp
display.vvv(“Original transfer method %s restored” % tmp)
to enforce scp mode only for python modules while normal files are copied in binary mode, however this is an ugly hack.
I’m looking for a way how to make it properly:
- do some magic autodetection of z/OS and based on that enforce scp transfer mode for ansible modules
or - “tag” hosts in inventory that require scp mode to transfer of python modules. eg
hosts:
jumper:
scp_if_ssh_for_ansible_modules = True <-- to enforce scp mode
ansible_port: 5555
ansible_host: 192.0.2.50
I would say the 2nd option is easier to do.
Would it be acceptable and in line with ansible architecture?
I plan to submit PR then.
Regards
Vitek