Bug #35792
closedsave_to_file function should not use shellescape on the filename
Description
We have improved the save_to_file function via https://projects.theforeman.org/issues/35530 but here in https://github.com/theforeman/foreman/blob/develop/app/services/foreman/renderer/scope/macros/base.rb#L116 , as we use shellescape on the filename, that breaks the functionality of kickstart_networking_snippet
- foreman-rake console
Loading production environment (Rails 6.0.4.7)
~~~~~
irb(main):002:0> filename = '/etc/sysconfig/network-scripts/ifcfg-$sanitized_real'
=> "/etc/sysconfig/network-scripts/ifcfg-$sanitized_real"
irb(main):003:0> filename.shellescape
=> "/etc/sysconfig/network-scripts/ifcfg-\\$sanitized_real"
So in foreman 3.4-stable, the rendering used to be:
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$sanitized_real
BOOTPROTO="dhcp"
DOMAIN="example.com"
DEVICE=$real
HWADDR="00:50:56:b4:14:44"
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
DEFROUTE=yes
MTU=1500
EOF
and Now, it's
cat << EOF-cd4e31fd > /etc/sysconfig/network-scripts/ifcfg-\$sanitized_real
BOOTPROTO="dhcp"
DOMAIN="example.com"
DEVICE=$real
HWADDR="00:50:56:b4:4f:c6"
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
DEFROUTE=yes
MTU=1500
EOF-cd4e31fd
And that escaping results in two ifcfg configs on the deployed system i.e.
- ls
l /etc/sysconfig/network-scripts. 1 root root 153 Nov 25 11:44 'ifcfg-$sanitized_real'
total 8
-rw-r--r-rw-r--r-. 1 root root 365 Nov 25 11:44 ifcfg-ens32