Let me just get it off my chest and say that I hate the network where I work. The fact that I can’t get direct Internet access without having to go through proxy servers drives me crazy (it always adds another additional level of complexity to things). I get why they do it, but still…

I often use kickstart to stand up bare metal and virtual machines. I recently had an instance where I needed to set the proxy server for yum itself instead of having to rely on shell environment variables (http_proxy, https_proxy, no_proxy) like I normally would do.

Sed to the rescue once again…

The below little snippet dropped into the %post section of a kickstart file will add add proxy server config directly into /etc/yum.conf.

sed -i '/\[main\]/a proxy=http://proxy.example.com:8080' /mnt/sysimage/etc/yum.conf

I’m a huge fan of the sed utility. For those not familiar with the tool it allows you to manipulate and transform text files from the command line.

I often turn to this tool to cleanup stock config files to get rid of the extra “crud” making them easier to read and templatize for use within a config management tool. Below are two of my favorite little snippets for this.

# Remove lines starting with `#` (comments):
sed -i '/^#/d' /path/to/file

# Remove blank lines:
sed -i '/^$/d' /path/to/file

Those two commands will modify the file in place. If you remove the -i it will print the modified file to STDOUT insead which is great to preview the changes that will be written.