Reputation: 1
I am using puppet for provisioning to AWS cloud. I am a newbie to this. My requirement is to add entry into /etc/hosts file of amazon ec2 instance. However at the time of writing puppet, I do not know the actual hostname.
How can I use $HOSTNAME variable in .pp file?
Something like this -
host { '$HOSTNAME':
ip => 'echo $HOSTNAME | tr "-" "." | sed 's/ip.//'',
host_aliases => 'mywebsite',
}
Upvotes: 0
Views: 1418
Reputation: 1
Since I wanted the hosts file to be updated before startup script's start gets executed, I did this and it worked for me.
Added this in /etc/init.d/
setup_hostname() {
IPADDR=`echo $HOSTNAME | tr "-" "." | sed 's/ip.//'`
echo "${IPADDR} ${HOSTNAME}" >> /etc/hosts
}
Called setup_hostname from start
case "$1" in
start)
clean
setup_hostname
start
;;
Upvotes: 0
Reputation: 11469
Something like this :
host { $fqdn :
ip => $ipaddress,
host_aliases => 'mywebsite',
}
$fqdn
provides fully qualified domain name and $ipaddress
provides IP address for the machine. These variables are available if you have facter
installed in your system. facter
is available at the puppetlab repo. You can install it the same way you installed puppet
in your system.
As in the comment, you can also use $hostname
to get the short-hostname in place of $fqdn
.
Upvotes: 2