18 Jan 2015
SaltStack currently doesn’t set the hostname correctly on Debian/Ubuntu. For example, this won’t work:
system:
network.system:
- enabled: True
- hostname: server1.example.com
Here’s a little shell script I wrote, to get around this problem:
% cat set_hostname.sh
#!/bin/bash
hn=$1
hostname $hn
echo $hn > /etc/hostname
sed -i "1s/.*/127.0.0.1 localhost $hn/" /etc/hosts
Then apply it using cmd.script, for example:
foo-hostname:
cmd.script:
- source: salt://soe/set_hostname.sh
- args: foo.bar.com
- unless: grep -q "foo.bar.com" /etc/hosts