Repository: ansible-collections/community.general

Issue:
svr4pkg on Solaris 11.4: TypeError: a bytes-like object is required, not 'str'
### Summary

When you try to install a package on Solaris 11.4 with the svr4pkg module, you get an error:
TypeError: a bytes-like object is required, not 'str'

Fix: 
```
--- svr4pkg.py.orig     2021-04-29 08:28:55.110835528 -0400
+++ svr4pkg.py  2021-04-29 08:27:49.567089417 -0400
@@ -121,7 +121,7 @@

 def create_admin_file():
     (desc, filename) = tempfile.mkstemp(prefix='ansible_svr4pkg', text=True)
-    fullauto = '''
+    fullauto = b'''
 mail=
 instance=unique
 partial=nocheck
```

After the fix it still works on Solaris 11.4 SRU15, Solaris 11.4 SRU31, Solaris 10 1/13

### Issue Type

Bug Report

### Component Name

communtiry.general.svr4pkg

### Ansible Version

```console (paste below)
$ ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug 18 2020, 08:33:21)
 [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible [core 2.12.0.dev0]  (devel 60adf8e1ee) last updated 2021/04/29 08:21:55 (GMT -400)
  config file = None
  configured module search path = ['/home/srml/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/srml/ansible/lib/ansible
  ansible collection location = /home/srml/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/srml/ansible/bin/ansible
  python version = 3.6.8 (default, Aug 18 2020, 08:33:21) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
  jinja version = 2.11.3
  libyaml = True
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug 18 2020, 08:33:21)
 [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.
```


### OS / Environment

RHEL 8.3

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- hosts: all
  become: yes
  tasks:
  - name: install svr4 package
    community.general.svr4pkg:
      name: CSWntop
      state: present
      src: /var/tmp/XYZsome.pkg
```


### Expected Results

Package should be installed

### Actual Results

```console (paste below)
$ ansible-playbook -i inventory -l sol11 svr4pkg.yml
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug 18 2020, 08:33:21)
 [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.

PLAY [all] ***********************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************[WARNING]: Platform sunos on host sol11 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could
change the meaning of that path. See https://docs.ansible.com/ansible/devel/reference_appendices/interpreter_discovery.html for more information.
ok: [sol11]

TASK [install svr4 package] ******************************************************************************************************************************************An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: a bytes-like object is required, not 'str'
fatal: [sol11]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.0.75.109 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699186.3019922-33970-236219862995078/AnsiballZ_svr4pkg.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699186.3019922-33970-236219862995078/AnsiballZ_svr4pkg.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699186.3019922-33970-236219862995078/AnsiballZ_svr4pkg.py\", line 41, in invoke_module\r\n    run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 262, in <module>\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 216, in main\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 154, in package_install\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 142, in create_admin_file\r\nTypeError: a bytes-like object is required, not 'str'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP ***********************************************************************************************************************************************************sol11                      : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


The full traceback is:
Traceback (most recent call last):
  File "/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py", line 100, in <module>
    _ansiballz_main()
  File "/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py", line 41, in invoke_module
    run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.5/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 262, in <module>
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 216, in main
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 154, in package_install
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 142, in create_admin_file
TypeError: a bytes-like object is required, not 'str'
fatal: [sol11]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.0.75.109 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py\", line 41, in invoke_module\r\n    run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 262, in <module>\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 216, in main\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 154, in package_install\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 142, in create_admin_file\r\nTypeError: a bytes-like object is required, not 'str'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
svr4pkg on Solaris 11.4: TypeError: a bytes-like object is required, not 'str'
### Summary

When you try to install a package on Solaris 11.4 with the svr4pkg module, you get an error:
TypeError: a bytes-like object is required, not 'str'

Fix: 
```
--- svr4pkg.py.orig     2021-04-29 08:28:55.110835528 -0400
+++ svr4pkg.py  2021-04-29 08:27:49.567089417 -0400
@@ -121,7 +121,7 @@

 def create_admin_file():
     (desc, filename) = tempfile.mkstemp(prefix='ansible_svr4pkg', text=True)
-    fullauto = '''
+    fullauto = b'''
 mail=
 instance=unique
 partial=nocheck
```

After the fix it still works on Solaris 11.4 SRU15, Solaris 11.4 SRU31, Solaris 10 1/13

### Issue Type

Bug Report

### Component Name

communtiry.general.svr4pkg

### Ansible Version

```console (paste below)
$ ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug 18 2020, 08:33:21)
 [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible [core 2.12.0.dev0]  (devel 60adf8e1ee) last updated 2021/04/29 08:21:55 (GMT -400)
  config file = None
  configured module search path = ['/home/srml/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/srml/ansible/lib/ansible
  ansible collection location = /home/srml/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/srml/ansible/bin/ansible
  python version = 3.6.8 (default, Aug 18 2020, 08:33:21) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
  jinja version = 2.11.3
  libyaml = True
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug 18 2020, 08:33:21)
 [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.
```


### OS / Environment

RHEL 8.3

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- hosts: all
  become: yes
  tasks:
  - name: install svr4 package
    community.general.svr4pkg:
      name: CSWntop
      state: present
      src: /var/tmp/XYZsome.pkg
```


### Expected Results

Package should be installed

### Actual Results

```console (paste below)
$ ansible-playbook -i inventory -l sol11 svr4pkg.yml
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug 18 2020, 08:33:21)
 [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out
features under development. This is a rapidly changing source of code and can become unstable at any point.

PLAY [all] ***********************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************[WARNING]: Platform sunos on host sol11 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could
change the meaning of that path. See https://docs.ansible.com/ansible/devel/reference_appendices/interpreter_discovery.html for more information.
ok: [sol11]

TASK [install svr4 package] ******************************************************************************************************************************************An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: a bytes-like object is required, not 'str'
fatal: [sol11]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.0.75.109 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699186.3019922-33970-236219862995078/AnsiballZ_svr4pkg.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699186.3019922-33970-236219862995078/AnsiballZ_svr4pkg.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699186.3019922-33970-236219862995078/AnsiballZ_svr4pkg.py\", line 41, in invoke_module\r\n    run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 262, in <module>\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 216, in main\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 154, in package_install\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_ndukwobh/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 142, in create_admin_file\r\nTypeError: a bytes-like object is required, not 'str'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP ***********************************************************************************************************************************************************sol11                      : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


The full traceback is:
Traceback (most recent call last):
  File "/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py", line 100, in <module>
    _ansiballz_main()
  File "/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py", line 41, in invoke_module
    run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.5/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 262, in <module>
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 216, in main
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 154, in package_install
  File "/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py", line 142, in create_admin_file
TypeError: a bytes-like object is required, not 'str'
fatal: [sol11]: FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.0.75.109 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/export/home/srml/.ansible/tmp/ansible-tmp-1619699820.2843351-34415-58061845298388/AnsiballZ_svr4pkg.py\", line 41, in invoke_module\r\n    run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 262, in <module>\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 216, in main\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 154, in package_install\r\n  File \"/tmp/ansible_community.general.svr4pkg_payload_n2ffzlfd/ansible_community.general.svr4pkg_payload.zip/ansible_collections/community/general/plugins/modules/svr4pkg.py\", line 142, in create_admin_file\r\nTypeError: a bytes-like object is required, not 'str'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Resolving patch:
diff --git a/plugins/modules/packaging/os/svr4pkg.py b/plugins/modules/packaging/os/svr4pkg.py
--- a/plugins/modules/packaging/os/svr4pkg.py
+++ b/plugins/modules/packaging/os/svr4pkg.py
@@ -121,7 +121,7 @@ def package_installed(module, name, category):
 
 def create_admin_file():
     (desc, filename) = tempfile.mkstemp(prefix='ansible_svr4pkg', text=True)
-    fullauto = '''
+    fullauto = b'''
 mail=
 instance=unique
 partial=nocheck


Test patch: