Skip to content
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

FEATURE REQUEST: ini_manage should able to synchronize ini file from sections dict #29287

Closed
tiadobatima opened this issue Nov 30, 2015 · 5 comments
Labels
Execution-Module Feature new functionality including changes to functionality and code refactors, etc. help-wanted Community help is needed to resolve this Platform Relates to OS, containers, platform-based utilities like FS, system based apps
Milestone

Comments

@tiadobatima
Copy link

Right now, If a certain option is set in the ini file, but it doesn't exist in the "sections dict" in salt.states.ini_manage.options_present, that option will remain unchanged:

From the docs:

options present in file and not specified in sections dict will be untouched
changes dict will contain the list of changes made

It would be great if there was a separate state function (or a switch in salt.states.ini_manage.options_present) that ensures that only options in the "sections dict" are kept in the ini file. If an option doesn't exist in the "sections dict", it should be deleted from the ini file. Basically, synchronize the ini file with the "sections dict".

I'm not asking for the current behaviour to be changed, but both behaviours should be supported.

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.ini_manage.html

Thanks!!!
g.

@jfindlay jfindlay added Feature new functionality including changes to functionality and code refactors, etc. Execution-Module help-wanted Community help is needed to resolve this Platform Relates to OS, containers, platform-based utilities like FS, system based apps labels Dec 1, 2015
@jfindlay jfindlay added this to the Approved milestone Dec 1, 2015
@jfindlay
Copy link
Contributor

jfindlay commented Dec 1, 2015

@tiadobatima, thanks for the feature request.

@Akilesh1597
Copy link
Contributor

Can we add a new argument 'strict' to options_present and sections_present which would make sure that the ini file strictly resembles the data provided ?

@jfindlay
Copy link
Contributor

@Akilesh1597, good suggestion.

@sevagh
Copy link
Contributor

sevagh commented Dec 22, 2016

Hello, I took a stab at implementing this.

I largely focused on making the real state work correctly (in a Docker container).

The unit test for this state seems weird to me, and doesn't actually reflect the way data is passed from the real sls file to the state. I did what needed to be done to make the unit tests pass.

# cat test.ini

[test1]
a = a
b = b

[test2]
a = a
b = b
c = c
root@28d80e067092:/etc/salt/states/test# cat test_ini.sls 
/etc/salt/states/test/test.ini:
  ini.options_present:
    - separator: '='
    - strict: True
    - sections:
        test1:
          a: 'new_a'
root@28d80e067092:/etc/salt/states/test# salt-call state.sls test.test_ini
local:
----------
          ID: /etc/salt/states/test/test.ini
    Function: ini.options_present
      Result: True
     Comment: Changes take effect
     Started: 16:51:00.182237
    Duration: 2.189 ms
     Changes:   
              ----------
              test1:
                  ----------
                  a:
                      ----------
                      after:
                          new_a
                      before:
                          a
                  b:
                      ----------
                      after:
                          None
                      before:
                          b

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   2.189 ms
root@28d80e067092:/etc/salt/states/test# 
root@28d80e067092:/etc/salt/states/test# cat test.ini

[test1]
a = new_a

[test2]
a = a
b = b
c = c
root@28d80e067092:/etc/salt/states/test# 

@lorengordon
Copy link
Contributor

This can probably be closed, as #38414 was merged and strict is available. @Ch3LL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Execution-Module Feature new functionality including changes to functionality and code refactors, etc. help-wanted Community help is needed to resolve this Platform Relates to OS, containers, platform-based utilities like FS, system based apps
Projects
None yet
Development

No branches or pull requests

6 participants