-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adding parameter to prefix option with spaces for ini_file #8639
base: main
Are you sure you want to change the base?
Adding parameter to prefix option with spaces for ini_file #8639
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
It seems you want this option to use the ini_file
module to operate on TOML files. I don't think it's a good idea to use the ini_file
module for TOML files, and I'm not sure whether adding this option to the ini_file
module is a good idea since its main application seems to be to edit TOML files.
changelogs/fragments/8639-ini_file-add-option_prefix-spaces.yml
Outdated
Show resolved
Hide resolved
plugins/modules/ini_file.py
Outdated
@@ -257,6 +263,14 @@ | |||
value: xxxxxxxxxxxxxxxxxxxx | |||
mode: '0600' | |||
state: present | |||
- name: Update the option and indent with spaces | |||
community.general.ini_file: | |||
path: /etc/influxdb/config.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the file extension indicates this is NOT an INI file, but a TOML file.
Using ini_file
for a TOML file is generally not a good idea, and definitely should not appear in the examples to avoid suggesting this to users.
- name: Update the option and indent with spaces | ||
community.general.ini_file: | ||
path: /etc/influxdb/config.toml | ||
path: /etc/influxdb/config.ini |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://docs.influxdata.com/influxdb/v2/reference/config-options/#influxdb-configuration-file .ini
is not supported.
This is the main problem with this PR, could you please comment on this? Are you aware of any actual INI files (which are not TOML files!) that need this indentation? |
I didn't find any other "module" in Ansible that provided the framework for handling this file. I do understand that this might not be the correct path forward. I can move the example back to the file extension of "toml" for the documentation. I have looked around for modules to handle TOML and the current existing python ones don't do writing to a file very well. I will probably have to dig into the code to get it working. If you would rather close this out and wait for a proper fix in a new module for handling toml code, I can make some attempts at that. |
When searching a bit I found https://github.com/python-poetry/tomlkit which seems to preserve style and comments. With that implementing an Ansible module for modifying TOML files should be possible. |
SUMMARY
Add parameter to prefix option with spaces when formatting the options in a section.
This is useful for formatting some INI files. The use case here was specifically around the updating some options/values in an InfluxDB config file. This is usually in an users directory. (/home/user/.influxdbv2/configs)
ISSUE TYPE
COMPONENT NAME
ini_file module - new parameter
option_prefix_spaces
ADDITIONAL INFORMATION
With an existing InfluxDB configs file of the following:
Using the below task:
produces the following in the configs file:
While this seems okay, the next time that the
influx
orinfluxd
commands are used, it reformats the file the to the format that it expects. Running ansible again tries to change the file as it notices that the current content is different than what the expected content will be after running the taskAdding the new ini_file parameter allows the change to be applied once and not affect now the influx/influxd commands formats the file.