0

I would like to set the following setting in /etc/zypp/zypp.conf via salt:

solver.allowVendorChange = true

How to do this?

There is a module for zypper, but I found no way to update the above setting:

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.zypper.html

2
+50

There are generic file modification modules and states in SaltStack. For example, you could use file.replace:

salt '*' file.replace /etc/zypp/zypp.conf pattern='solver.allowVendorChange = true' repl='solver.allowVendorChange = false'

In case the line doesn't exist at all, you can append it to the configuration in a state using file.blockreplace:

   file.blockreplace:
  - name: /etc/zypp/zypp.conf
  - marker_start: "#BLOCK TOP: Salt managed entry, do not edit!"
  - marker_end: "#BLOCK BOTTOM: End of Salt managed entry"
  - content: |
     solver.allowVendorChange = true
  - show_changes: True
  - append_if_not_found: True
2
  • AFAIK this would fail, if the old value is solver.allowVendorChange = False (capital "F") or the line would not exist at all, since the default is False.
    – guettli
    Jan 22 '16 at 8:53
  • Sometimes I wish linux would use a database for configuration like ms-windows uses its registry ....
    – guettli
    May 20 '16 at 8:56
1

You should be able to do it using file.sed:

salt '*' file.sed /etc/zypp/zypp.conf '^(#|)\s*solver.allowVendorChange(.+)?$' 'solver.allowVendorChange = true'
1
  • I love linux since 1996 and databases since 2005. For me config is data and belongs into a common data format. Unfortunately most linux/unix servers have their own data format for config stuff. It is sad, that there is so little progress in this area. SQLite, json, yaml ... would fit and would be much more easy to update by machine than these key-value ascii files. Sorry, this is a general "rant". Your answer looks ugly since the problem is ugly. It is not your fault. I guess there is no better way.
    – guettli
    Jan 29 '16 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.