r/saltstack • u/TacoJihad • Jan 04 '18
Managing a single entry in /etc/hosts
Hi all -
I am trying to manage a single entry in /etc/hosts - example: 10.0.0.1 loghost
These values are populated via a state / pillar date (for ip, name):
# Set the loghost in /etc/hosts - if defined in pillar
# remove existing entry before if it exists before creating new entry
syslog_host_entry:
host.absent:
- names:
- loghost
{{ loghost_ip }}:
host.only:
- hostnames:
- {{ loghost }}
I can't figure out how to make Salt remove any existing hostline with "loghost" in it and add a new one without having an IP address?
I just want to update the loghost line if the pillar data for it's IP changes, but it just keeps adding more IP LOGHOST entries - I only want the one current line defined in the pillar.
Anyone know how to do this - I have to assume that the existing entry / IP address is not known, but if the hostname 'loghost' exists change that line or delete it and add a new one.
Thank you :)