-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
bugThis issue/PR relates to a bugThis issue/PR relates to a bughas_prmodulemodulemodulepluginsplugin (any type)plugin (any type)traceback
Description
Summary
Documentation at https://docs.ansible.com/ansible/latest/collections/community/general/ini_file_module.html for option
parameter says
If set (required for changing a value, this is the name of the option.
May be omitted if adding/removing a whole section
However, leaving option unset does not work for setting a whole section instead resulting in an error. Somebody else ran into a similar problem at https://serverfault.com/questions/969137/ansible-ini-file-module-replace-whole-section
Issue Type
Bug Report
Component Name
ini_file
Ansible Version
$ ansible --version
ansible [core 2.18.6]
config file = /workspaces/ansible/ansible.cfg
configured module search path = ['/workspaces/ansible/plugins/modules']
ansible python module location = /home/vscode/.local/lib/python3.12/site-packages/ansible
ansible collection location = /home/vscode/.ansible/collections:/usr/share/ansible/collections
executable location = /home/vscode/.local/bin/ansible
python version = 3.12.10 (main, May 22 2025, 01:29:12) [GCC 12.2.0] (/usr/local/bin/python3.12)
jinja version = 3.1.6
libyaml = True
Community.general Version
$ ansible-galaxy collection list community.general
# /home/vscode/.local/lib/python3.12/site-packages/ansible_collections
Collection Version
----------------- -------
community.general 10.7.0
Configuration
$ ansible-config dump --only-changed
OS / Environment
No response
Steps to Reproduce
- community.general.ini_file:
path: /etc/samba/smb.conf
section: backup
value: |
path = /mnt/backup
browseable = yes
writeable = yes
valid users = @user
Expected Results
Add backup section to /etc/samba/smb.conf that looks like
[backup]
path = /mnt/backup
browseable = yes
writeable = yes
valid users = @user
Actual Results
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: decoding to str: need a bytes-like object, NoneType found
failed: [samba2] (item={'section': 'backup', 'value': 'path = /mnt/backup\nbrowseable = yes\nwriteable = yes\nvalid users = @user\n'}) => {"ansible_loop_var": "item", "changed": false, "item": {"section": "backup", "value": "path = /mnt/backup\nbrowseable = yes\nwriteable = yes\nvalid users = @user\n"}, "module_stderr": "Shared connection to 10.60.1.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/root/.ansible/tmp/ansible-tmp-1750482471.8477345-253457-87713894490347/AnsiballZ_ini_file.py\", line 107, in <module>\r\n _ansiballz_main()\r\n File \"/root/.ansible/tmp/ansible-tmp-1750482471.8477345-253457-87713894490347/AnsiballZ_ini_file.py\", line 99, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/root/.ansible/tmp/ansible-tmp-1750482471.8477345-253457-87713894490347/AnsiballZ_ini_file.py\", line 47, in invoke_module\r\n runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.ini_file', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.ini_file', _modlib_path=modlib_path),\r\n File \"<frozen runpy>\", line 226, in run_module\r\n File \"<frozen runpy>\", line 98, in _run_module_code\r\n File \"<frozen runpy>\", line 88, in _run_code\r\n File \"/tmp/ansible_community.general.ini_file_payload_iistki4o/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 662, in <module>\r\n File \"/tmp/ansible_community.general.ini_file_payload_iistki4o/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 640, in main\r\n File \"/tmp/ansible_community.general.ini_file_payload_iistki4o/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 457, in do_ini\r\n File \"/tmp/ansible_community.general.ini_file_payload_iistki4o/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 270, in match_opt\r\n File \"/usr/lib/python3.11/re/__init__.py\", line 260, in escape\r\n pattern = str(pattern, 'latin1')\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\nTypeError: decoding to str: need a bytes-like object, NoneType found\r\n", "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: decoding to str: need a bytes-like object, NoneType found
failed: [samba2] (item={'section': 'iso', 'value': 'path = /mnt/iso\nbrowseable = yes\nwriteable = yes\nvalid users = @user\n'}) => {"ansible_loop_var": "item", "changed": false, "item": {"section": "iso", "value": "path = /mnt/iso\nbrowseable = yes\nwriteable = yes\nvalid users = @user\n"}, "module_stderr": "Shared connection to 10.60.1.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/root/.ansible/tmp/ansible-tmp-1750482472.126275-253457-14224654766412/AnsiballZ_ini_file.py\", line 107, in <module>\r\n _ansiballz_main()\r\n File \"/root/.ansible/tmp/ansible-tmp-1750482472.126275-253457-14224654766412/AnsiballZ_ini_file.py\", line 99, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/root/.ansible/tmp/ansible-tmp-1750482472.126275-253457-14224654766412/AnsiballZ_ini_file.py\", line 47, in invoke_module\r\n runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.ini_file', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.ini_file', _modlib_path=modlib_path),\r\n File \"<frozen runpy>\", line 226, in run_module\r\n File \"<frozen runpy>\", line 98, in _run_module_code\r\n File \"<frozen runpy>\", line 88, in _run_code\r\n File \"/tmp/ansible_community.general.ini_file_payload_9kpvn8pz/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 662, in <module>\r\n File \"/tmp/ansible_community.general.ini_file_payload_9kpvn8pz/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 640, in main\r\n File \"/tmp/ansible_community.general.ini_file_payload_9kpvn8pz/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 457, in do_ini\r\n File \"/tmp/ansible_community.general.ini_file_payload_9kpvn8pz/ansible_community.general.ini_file_payload.zip/ansible_collections/community/general/plugins/modules/ini_file.py\", line 270, in match_opt\r\n File \"/usr/lib/python3.11/re/__init__.py\", line 260, in escape\r\n pattern = str(pattern, 'latin1')\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\nTypeError: decoding to str: need a bytes-like object, NoneType found\r\n", "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error", "rc": 1}
Code of Conduct
- I agree to follow the Ansible Code of Conduct
Metadata
Metadata
Assignees
Labels
bugThis issue/PR relates to a bugThis issue/PR relates to a bughas_prmodulemodulemodulepluginsplugin (any type)plugin (any type)traceback