Greetings all! Rather new to Salt, please forgive the simplistic nature of this inquiry.
Change "enabled=0" to "enabled=1" in a text file using a regular expression.
Reference:
Relevant Docs:
http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.htmlSample Regex:
http://regexr.com/3a5v3Sample File:
http://hastebin.com/edinuxesaq.smSample Template:
http://hastebin.com/xubovijevo.smQuestions:
1) What's the best way to test a salt state under development?
I initially attempted to test various replace approaches using cli invocation:
salt-call -l all file.replace path="/etc/yum.repos.d/remi.repo" pattern="/(\[remi-php55\][\s\S]*?enabled)=([0-9])/" repl="$1=1" bufsize=file
This, and every variation of it I could think of, failed with nonexplanatory errors.
I'm now using a template for testing, invoked using sudo salt-call -l all state.template '/srv/salt/php-55/init.sls'. This works, but I had to manually comment out several dependency directives so it could run with the limited scope. Is the best way to test new templates, or am I missing something?
2) Why doesn't cli invocation work?
Here's a sample pulled from the official documentation: salt '*' file.replace /etc/httpd/httpd.conf pattern='LogLevel warn' repl='LogLevel info'
Here's the simplest possible testcase I could reduce things to - each of the following commands fails with errors such as "Passed invalid arguments: first argument must be string or compiled pattern". What's the right way to do masterless cli invocation?
echo '12342' > /tmp/test.txt
salt-call -l all file.replace path="/etc/yum.repos.d/remi.repo" pattern="/(\[remi-php55\][\s\S]*?enabled)=([0-9])/" repl="$1=1" bufsize=file
salt-call file.replace /tmp/test.txt pattern='42' repl='43'
salt-call file.replace /tmp/test.txt pattern='/42/' repl='43'
salt-call file.replace /tmp/test.txt pattern=/42/ repl=43
salt-call file.replace /tmp/test.txt '42' '43'
salt-call file.replace /tmp/test.txt 42 43
3) Any idea why this regex finds no matches?
(sample file) cat /tmp/search.txt
(sample template)
/tmp/search.txt:
file.replace:
- pattern: |
42([\s\S]*)44
- repl: xxx
- bufsize: file
(sample output)
ID: /tmp/search.txt
Function: file.replace
Result: True
Comment: No changes were made
4) I feel the sample template referenced above is failing for the same reason that the simple 42 regex is failing - multiline expressions don't seem to work even when bufsize is set to file. Please let me know if there's something simple being overlooked here.