How can I make several replacements in one file using the same state of salt gum?

Here is my target file:

Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.

# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=/opt/nexuswork
runtime=${bundleBasedir}/nexus/WEB-INF

I know this is an easy way to do this with regex or a simple sed script:

sed -i 's/${bundleBasedir}\/..\/my\/second\/path\/002\/\/nexus/\/myfirstdir001\/g'

However, I would ideally prefer the salt road.

I would like it to look something like this:

Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.

# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=/my/second/path/002/nexus # changed
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=/opt/nexuswork
runtime=/myfirstdir001/nexus/WEB-INF # changed 

I still do not understand the meaning of this article.

The Saltstack documentation for salt.states.file.replace looks pretty simple:

http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.replace

Here is what I tried:

/opt/nexus-2.8.0/conf/nexus.properties
  file:                                  # state
    - replace
    - pattern: '\$\{bundleBasedir\}'  # without escapes: '${bundleBasedir}/nexus'
    - repl: '/my/second/path/002/nexus'
#    - name: /opt/nexus-2.8.0/conf/nexus.properties
#    - count=0
#    - append_if_not_found=False
#    - prepend_if_not_found=False
#    - not_found_content=None
#    - backup='.bak'
#    - show_changes=True
    - pattern: '\$\{bundleBasedir\}\/WEB-INF' # without escapes: ${bundleBasedir}/WEB-INF
    - repl: '/myfirstdir001/'

I could try several status identifiers, but that seems inelegant.

If there is anything else, I get annoyed, please advise!

I would love to find a solution to this.

, , , , , .

, - , :

http://comments.gmane.org/gmane.comp.sysutils.salt.user/15138

+6
2

, , , ahus1.

/ , , , , ( OP) - . - :

/opt/nexus-2.8.0/conf/nexus.properties-jetty:
  file:
    - replace
    - name: /opt/nexus-2.8.0/conf/nexus.properties
    - pattern: '\$\{bundleBasedir\}'  # without escapes: '${bundleBasedir}/nexus'
    - repl: '/my/second/path/002/nexus'

/opt/nexus-2.8.0/conf/nexus.properties-nexus:
  file:
    - replace:
    - name: /opt/nexus-2.8.0/conf/nexus.properties
    - pattern: '\$\{bundleBasedir\}\/WEB-INF' # without escapes: ${bundleBasedir}/WEB-INF
    - repl: '/myfirstdir001/'

, salt.states.file.line . , salt.states.file.managed replace: False , , , line.

+5

, . nexus.properties file.managed, http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html

- :

/opt/nexus-2.8.0/conf/nexus.properties:
  file.managed:
    - source: salt://nexus/nexus.properties.jinja
    - template: jinja
    - defaults:
        bundleBasedir: "..."

Jinja :

# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp={{ bundleBasedir }}/nexus
nexus-webapp-context-path=/nexus

. Jinja: http://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.jinja.html

, .

+4

All Articles