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 --->
@srml Thanks for your fix, are you interested in creating a PR fixing this?
!component =plugins/modules/packaging/os/svr4pkg.py
Files identified in the description:
* [`plugins/modules/packaging/os/svr4pkg.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/packaging/os/svr4pkg.py)

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 --->
cc @bcoca @brontitall @fishman @jasperla @jpdasma @mator @scathatheworm @troy2914 @xen0l
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
i can't reproduce with solaris 11.4 (x86_64) virtual machine and my playbook 
```
$ cat playbooks/solaris-srv4.yml
---
- hosts: solaris114
  become: yes
  gather_facts: no
  tasks:
  - name: Install a package directly from an http site
    community.general.svr4pkg:
      name: CSWpkgutil
      src: 'http://get.opencsw.org/now'
      state: present
      zone: current

$ ansible-playbook  playbooks/solaris-srv4.yml

PLAY [solaris114] *************************************************************************************************

TASK [Install a package directly from an http site] ***************************************************************
changed: [solaris114]

PLAY RECAP ********************************************************************************************************
solaris114                 : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
```
checking with installed package on solaris 11:
```
solaris114# pkginfo | grep -i csw
application CSWpkgutil     pkgutil - Installs Solaris packages easily
```
ansible versions tested (archlinux system installed first and current git second):
```
$ ansible --version
ansible 2.10.8
  config file = /home/mator/ansible.dev/ansible.cfg
  configured module search path = ['/home/mator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]

$ source ansible/hacking/env-setup
$ ansible --version
ansible [core 2.12.0.dev0]  (devel aa12af1d34) last updated 2021/04/29 19:37:34 (GMT +300)
  config file = /home/mator/ansible.dev/ansible.cfg
  configured module search path = ['/home/mator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mator/ansible.dev/ansible/lib/ansible
  ansible collection location = /home/mator/ansible.dev/collections
  executable location = /home/mator/ansible.dev/ansible/bin/ansible
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]
  jinja version = 2.11.3
  libyaml = True
```
> i can't reproduce with solaris 11.4 (x86_64) virtual machine and my playbook

It only happens on newer SRU (I think 30 or 31) which have python3 as the default python. 

Check SRU:
```
# pkg info entire | grep Version
       Version: 11.4 (Oracle Solaris 11.4.0.0.1.15.0)
                                                ^^- SRU
```
On older SRU you can manually switch to python3:
```
# python --version
Python 2.7.14

# pkg mediator -a python
MEDIATOR     VER. SRC. VERSION IMPL. SRC. IMPLEMENTATION
python       vendor    2.7     vendor
python       system    3.5     system
python       system    3.4     system

# pkg set-mediator -vV 3.5 python
            Packages to change:       14
           Mediators to change:        1
     Estimated space available: 17.00 GB
Estimated space to be consumed: 63.85 MB
       Create boot environment:       No
Create backup boot environment:      Yes
          Rebuild boot archive:       No

Changed mediators:
  mediator python:
           version: 2.7 (vendor default) -> 3.5 (local default)
...

# python --version
Python 3.5.3
```

After that you should be able to reproduce.
solaris 11.4 GA have only python versions of 2.7 and 3.4, so my test was based on vendor default version 2.7

```
solaris114:~$ pkg mediator -a python
MEDIATOR     VER. SRC. VERSION IMPL. SRC. IMPLEMENTATION
python       vendor    2.7     vendor
python       system    3.4     system

solaris114:~$ pkg info entire
          Name: entire
       Summary: Incorporation to lock all system packages to the same build
   Description: This package constrains system package versions to the same
                build.  WARNING: Proper system update and correct package
                selection depend on the presence of this incorporation.
                Removing this package will result in an unsupported system.
      Category: Meta Packages/Incorporations
         State: Installed
     Publisher: solaris
       Version: 11.4 (Oracle Solaris 11.4.0.0.1.15.0)
        Branch: 11.4.0.0.1.15.0
Packaging Date: Fri Aug 17 00:42:03 2018
          Size: 2.53 kB
          FMRI: pkg://solaris/entire@11.4-11.4.0.0.1.15.0:20180817T004203Z
```

switched python version to 3.4 with `pkg set-mediator` , but ansible complained it only support 3.5+ versions of python. I'm going try to upgrade my solaris 11.4 GA version to something more recent (don't have support contract here, but have some FRU ips repo files around) and try again. 
Thanks.
I used the VM template from https://www.oracle.com/solaris/solaris11/downloads/solaris11-vm-templates-downloads.html, that one has python 3.5 installed.
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 --->
@srml Thanks for your fix, are you interested in creating a PR fixing this?
!component =plugins/modules/packaging/os/svr4pkg.py
Files identified in the description:
* [`plugins/modules/packaging/os/svr4pkg.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/packaging/os/svr4pkg.py)

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 --->
cc @bcoca @brontitall @fishman @jasperla @jpdasma @mator @scathatheworm @troy2914 @xen0l
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
i can't reproduce with solaris 11.4 (x86_64) virtual machine and my playbook 
```
$ cat playbooks/solaris-srv4.yml
---
- hosts: solaris114
  become: yes
  gather_facts: no
  tasks:
  - name: Install a package directly from an http site
    community.general.svr4pkg:
      name: CSWpkgutil
      src: 'http://get.opencsw.org/now'
      state: present
      zone: current

$ ansible-playbook  playbooks/solaris-srv4.yml

PLAY [solaris114] *************************************************************************************************

TASK [Install a package directly from an http site] ***************************************************************
changed: [solaris114]

PLAY RECAP ********************************************************************************************************
solaris114                 : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
```
checking with installed package on solaris 11:
```
solaris114# pkginfo | grep -i csw
application CSWpkgutil     pkgutil - Installs Solaris packages easily
```
ansible versions tested (archlinux system installed first and current git second):
```
$ ansible --version
ansible 2.10.8
  config file = /home/mator/ansible.dev/ansible.cfg
  configured module search path = ['/home/mator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]

$ source ansible/hacking/env-setup
$ ansible --version
ansible [core 2.12.0.dev0]  (devel aa12af1d34) last updated 2021/04/29 19:37:34 (GMT +300)
  config file = /home/mator/ansible.dev/ansible.cfg
  configured module search path = ['/home/mator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mator/ansible.dev/ansible/lib/ansible
  ansible collection location = /home/mator/ansible.dev/collections
  executable location = /home/mator/ansible.dev/ansible/bin/ansible
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]
  jinja version = 2.11.3
  libyaml = True
```
> i can't reproduce with solaris 11.4 (x86_64) virtual machine and my playbook

It only happens on newer SRU (I think 30 or 31) which have python3 as the default python. 

Check SRU:
```
# pkg info entire | grep Version
       Version: 11.4 (Oracle Solaris 11.4.0.0.1.15.0)
                                                ^^- SRU
```
On older SRU you can manually switch to python3:
```
# python --version
Python 2.7.14

# pkg mediator -a python
MEDIATOR     VER. SRC. VERSION IMPL. SRC. IMPLEMENTATION
python       vendor    2.7     vendor
python       system    3.5     system
python       system    3.4     system

# pkg set-mediator -vV 3.5 python
            Packages to change:       14
           Mediators to change:        1
     Estimated space available: 17.00 GB
Estimated space to be consumed: 63.85 MB
       Create boot environment:       No
Create backup boot environment:      Yes
          Rebuild boot archive:       No

Changed mediators:
  mediator python:
           version: 2.7 (vendor default) -> 3.5 (local default)
...

# python --version
Python 3.5.3
```

After that you should be able to reproduce.
solaris 11.4 GA have only python versions of 2.7 and 3.4, so my test was based on vendor default version 2.7

```
solaris114:~$ pkg mediator -a python
MEDIATOR     VER. SRC. VERSION IMPL. SRC. IMPLEMENTATION
python       vendor    2.7     vendor
python       system    3.4     system

solaris114:~$ pkg info entire
          Name: entire
       Summary: Incorporation to lock all system packages to the same build
   Description: This package constrains system package versions to the same
                build.  WARNING: Proper system update and correct package
                selection depend on the presence of this incorporation.
                Removing this package will result in an unsupported system.
      Category: Meta Packages/Incorporations
         State: Installed
     Publisher: solaris
       Version: 11.4 (Oracle Solaris 11.4.0.0.1.15.0)
        Branch: 11.4.0.0.1.15.0
Packaging Date: Fri Aug 17 00:42:03 2018
          Size: 2.53 kB
          FMRI: pkg://solaris/entire@11.4-11.4.0.0.1.15.0:20180817T004203Z
```

switched python version to 3.4 with `pkg set-mediator` , but ansible complained it only support 3.5+ versions of python. I'm going try to upgrade my solaris 11.4 GA version to something more recent (don't have support contract here, but have some FRU ips repo files around) and try again. 
Thanks.
I used the VM template from https://www.oracle.com/solaris/solaris11/downloads/solaris11-vm-templates-downloads.html, that one has python 3.5 installed.

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: