saltstack/salt — Issue #612: function file.sed not building command properly
Author: mrballcb
Created: 2012-01-30 22:03:14+00:00
State: open

The following yaml file segment:

/etc/yum.repos.d/epel.repo:
file:
- sed
- before: 'enabled=1'
- after: 'enabled=0'
- backup: '.bak'

...results in this command execution:

[INFO ] Executing command sed -n -r -e 's/enabled=0/&/gp' /etc/yum.repos.d/epel.repo in directory /root
[DEBUG ] enabled=0
enabled=0

The sed command should be built as per the following code:

def sed(path, before, after, limit='', backup='.bak', options='-r -e',
flags='g'):
before = _sed_esc(before)
after = _sed_esc(after)
cmd = r"sed {backup}{options} '{limit}s/{before}/{after}/{flags}' {path}".format(
backup = '-i{0} '.format(backup) if backup else '',
options = options,
limit = '/{0}/ '.format(limit) if limit else '',
before = before,
after = after,
flags = flags,
path = path)
return __salt__['cmd.run'](cmd)

So it should have resulted in:
sed -i.bak -r -e 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel.repo

It looks like it's not seeing anything I define in the {backup} variable. It's putting the value I designated as {after} in the {before} slot, and putting a literal "&" in the {after} slot. I can't figure out where the -n is coming from in the command.

Is this a bug in the construction of the command or is this me using the command improperly?

CentOS57[root@ivwm21 ~]# salt-call --version
salt-call 0.9.6